The size of a range is one more than the difference between its msb and lsb. For example [3:0] has size 4.
(vl-range-size x) → size
Notice that this definition still works in the case of [1:1] and so on.
Function:
(defun vl-range-size (x) (declare (xargs :guard (vl-range-p x))) (declare (xargs :guard (vl-range-resolved-p x))) (let ((__function__ 'vl-range-size)) (declare (ignorable __function__)) (b* (((vl-range x) x) (left (vl-resolved->val x.msb)) (right (vl-resolved->val x.lsb))) (+ 1 (abs (- left right))))))
Theorem:
(defthm posp-of-vl-range-size (b* ((size (vl-range-size x))) (posp size)) :rule-classes :type-prescription)
Theorem:
(defthm vl-range-size-of-vl-range-fix-x (equal (vl-range-size (vl-range-fix x)) (vl-range-size x)))
Theorem:
(defthm vl-range-size-vl-range-equiv-congruence-on-x (implies (vl-range-equiv x x-equiv) (equal (vl-range-size x) (vl-range-size x-equiv))) :rule-classes :congruence)