Special routine for truncating ordinary, unsigned constant integers, without introducing temporary wires.
We can truncate resolved constants by just creating a new constant that has its width and value chopped down to size.
Function:
(defun vl-truncate-constint (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-constint-p (vl-atom->guts x)) (equal (vl-expr->finaltype x) :vl-unsigned) (< n (vl-expr->finalwidth x))))) (let ((__function__ 'vl-truncate-constint)) (declare (ignorable __function__)) (b* ((n (lposfix n)) (guts (vl-atom->guts x)) (value (vl-constint->value guts)) (val-chop (mod value (expt 2 n))) (new-guts (make-vl-constint :value val-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-constint (b* ((chopped-expr (vl-truncate-constint n x))) (vl-expr-p chopped-expr)) :rule-classes :rewrite)
Theorem:
(defthm vl-truncate-constint-basics (implies (and (force (posp n)) (force (vl-atom-p x)) (force (vl-expr-welltyped-p x)) (force (vl-constint-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-constint n x)) n) (equal (vl-expr->finaltype (vl-truncate-constint n x)) :vl-unsigned) (vl-expr-welltyped-p (vl-truncate-constint n x)))))
Theorem:
(defthm vl-truncate-constint-of-pos-fix-n (equal (vl-truncate-constint (pos-fix n) x) (vl-truncate-constint n x)))
Theorem:
(defthm vl-truncate-constint-pos-equiv-congruence-on-n (implies (acl2::pos-equiv n n-equiv) (equal (vl-truncate-constint n x) (vl-truncate-constint n-equiv x))) :rule-classes :congruence)
Theorem:
(defthm vl-truncate-constint-of-vl-expr-fix-x (equal (vl-truncate-constint n (vl-expr-fix x)) (vl-truncate-constint n x)))
Theorem:
(defthm vl-truncate-constint-vl-expr-equiv-congruence-on-x (implies (vl-expr-equiv x x-equiv) (equal (vl-truncate-constint n x) (vl-truncate-constint n x-equiv))) :rule-classes :congruence)