Reverses blocks, like the streaming concatenation operator in SystemVerilog.
Example:
(equal (rev-blocks 28 8 #xaabbccdd) #xddccbba)
This essentially truncates x to nbits bits, then divides this into blocks of
size blocksz, starting from least significant bits, where the last
block (corresponding to the most significant bits of x) may be smaller. Then
it reverses the order of these blocks. So in the example above, the most
significant
Function:
(defun rev-blocks (nbits blocksz x) (declare (xargs :guard (and (natp nbits) (posp blocksz) (integerp x)))) (let ((__function__ 'rev-blocks)) (declare (ignorable __function__)) (b* ((nbits (lnfix nbits)) (blocksz (mbe :logic (pos-fix blocksz) :exec blocksz)) ((when (< nbits blocksz)) (loghead nbits x)) (next-nbits (- nbits blocksz)) (rest (rev-blocks next-nbits blocksz (ash x (- blocksz))))) (logapp next-nbits rest (loghead blocksz x)))))
Theorem:
(defthm natp-of-rev-blocks (b* ((res (rev-blocks nbits blocksz x))) (natp res)) :rule-classes :type-prescription)
Theorem:
(defthm rev-blocks-of-nfix-nbits (equal (rev-blocks (nfix nbits) blocksz x) (rev-blocks nbits blocksz x)))
Theorem:
(defthm rev-blocks-nat-equiv-congruence-on-nbits (implies (nat-equiv nbits nbits-equiv) (equal (rev-blocks nbits blocksz x) (rev-blocks nbits-equiv blocksz x))) :rule-classes :congruence)
Theorem:
(defthm rev-blocks-of-pos-fix-blocksz (equal (rev-blocks nbits (pos-fix blocksz) x) (rev-blocks nbits blocksz x)))
Theorem:
(defthm rev-blocks-pos-equiv-congruence-on-blocksz (implies (pos-equiv blocksz blocksz-equiv) (equal (rev-blocks nbits blocksz x) (rev-blocks nbits blocksz-equiv x))) :rule-classes :congruence)
Theorem:
(defthm rev-blocks-of-ifix-x (equal (rev-blocks nbits blocksz (ifix x)) (rev-blocks nbits blocksz x)))
Theorem:
(defthm rev-blocks-int-equiv-congruence-on-x (implies (int-equiv x x-equiv) (equal (rev-blocks nbits blocksz x) (rev-blocks nbits blocksz x-equiv))) :rule-classes :congruence)