Rotate a bit-vector some arbitrary number of places to the left.
Note that
Function:
(defun rotate-left (x width places) (declare (xargs :guard (and (integerp x) (posp width) (natp places)))) (let ((__function__ 'rotate-left)) (declare (ignorable __function__)) (let* ((width (lnfix width)) (places (lnfix places)) (wmask (1- (ash 1 width))) (x (logand x wmask)) (places (mbe :logic (mod places width) :exec (if (< places width) places (rem places width)))) (places (acl2::gl-mbe places (logand places (lognot (ash -1 (integer-length width)))))) (low-num (- width places)) (mask (1- (ash 1 low-num))) (xl (logand x mask)) (xh (logand x (lognot mask))) (xh-shift (ash xh (- low-num))) (xl-shift (ash xl places)) (ans (logior xl-shift xh-shift))) ans)))
Theorem:
(defthm acl2::natp-of-rotate-left (b* ((rotated (rotate-left x width places))) (natp rotated)) :rule-classes :type-prescription)
Theorem:
(defthm int-equiv-implies-equal-rotate-left-1 (implies (int-equiv x x-equiv) (equal (rotate-left x width places) (rotate-left x-equiv width places))) :rule-classes (:congruence))
Theorem:
(defthm nat-equiv-implies-equal-rotate-left-2 (implies (nat-equiv width width-equiv) (equal (rotate-left x width places) (rotate-left x width-equiv places))) :rule-classes (:congruence))
Theorem:
(defthm nat-equiv-implies-equal-rotate-left-3 (implies (nat-equiv places places-equiv) (equal (rotate-left x width places) (rotate-left x width places-equiv))) :rule-classes (:congruence))
Theorem:
(defthm logbitp-of-rotate-left-split (equal (logbitp n (rotate-left x width places)) (b* ((n (nfix n)) (width (nfix width)) (places (mod (nfix places) width))) (cond ((>= n width) nil) ((>= n places) (logbitp (- n places) x)) (t (logbitp (+ n width (- places)) x))))))
Theorem:
(defthm rotate-left-zero-width (equal (rotate-left x 0 places) 0))
Theorem:
(defthm rotate-left-by-zero (equal (rotate-left x width 0) (loghead width x)))
Theorem:
(defthm rotate-left-by-width (equal (rotate-left x width width) (loghead width x)))
Theorem:
(defthm unsigned-byte-p-of-rotate-left (implies (natp width) (unsigned-byte-p width (rotate-left x width places))))
Theorem:
(defthm rotate-left-of-rotate-left (equal (rotate-left (rotate-left x width places1) width places2) (rotate-left x width (+ (nfix places1) (nfix places2)))))