Special routine for truncating unsigned weirdint literals without introducing temporary wires.
(vl-truncate-weirdint n x) → chopped-expr
We can truncate a weirdint by just creating a new weirdint that has its width reduced and that drops the chopped off bits.
Function:
(defun vl-truncate-weirdint (n x) (declare (xargs :guard (and (posp n) (vl-expr-p x)))) (declare (xargs :guard (and (vl-atom-p x) (vl-expr-welltyped-p x) (vl-weirdint-p (vl-atom->guts x)) (equal (vl-expr->finaltype x) :vl-unsigned) (< n (vl-expr->finalwidth x))))) (let ((__function__ 'vl-truncate-weirdint)) (declare (ignorable __function__)) (b* ((n (lposfix n)) (guts (vl-atom->guts x)) ((vl-weirdint guts) guts) (bits-chop (nthcdr (- guts.origwidth n) (list-fix guts.bits))) (new-guts (make-vl-weirdint :bits bits-chop :origwidth n :origtype :vl-unsigned)) (new-atom (make-vl-atom :guts new-guts :finalwidth n :finaltype :vl-unsigned))) new-atom)))
Theorem:
(defthm vl-expr-p-of-vl-truncate-weirdint (b* ((chopped-expr (vl-truncate-weirdint n x))) (vl-expr-p chopped-expr)) :rule-classes :rewrite)
Theorem:
(defthm vl-truncate-weirdint-basics (implies (and (force (posp n)) (force (vl-atom-p x)) (force (vl-expr-welltyped-p x)) (force (vl-weirdint-p (vl-atom->guts x))) (force (< n (vl-expr->finalwidth x))) (force (equal (vl-expr->finaltype x) :vl-unsigned))) (and (equal (vl-expr->finalwidth (vl-truncate-weirdint n x)) n) (equal (vl-expr->finaltype (vl-truncate-weirdint n x)) :vl-unsigned) (vl-expr-welltyped-p (vl-truncate-weirdint n x)))))
Theorem:
(defthm vl-truncate-weirdint-of-pos-fix-n (equal (vl-truncate-weirdint (pos-fix n) x) (vl-truncate-weirdint n x)))
Theorem:
(defthm vl-truncate-weirdint-pos-equiv-congruence-on-n (implies (acl2::pos-equiv n n-equiv) (equal (vl-truncate-weirdint n x) (vl-truncate-weirdint n-equiv x))) :rule-classes :congruence)
Theorem:
(defthm vl-truncate-weirdint-of-vl-expr-fix-x (equal (vl-truncate-weirdint n (vl-expr-fix x)) (vl-truncate-weirdint n x)))
Theorem:
(defthm vl-truncate-weirdint-vl-expr-equiv-congruence-on-x (implies (vl-expr-equiv x x-equiv) (equal (vl-truncate-weirdint n x) (vl-truncate-weirdint n x-equiv))) :rule-classes :congruence)