(vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb) → (mv err rel-lsb width)
Function:
(defun vl-arrayrange->rel-lsb-and-width (x dim-lsb dim-msb) (declare (xargs :guard (and (vl-arrayrange-p x) (natp dim-lsb) (natp dim-msb)))) (declare (xargs :guard (not (vl-arrayrange-case x :none)))) (let ((__function__ 'vl-arrayrange->rel-lsb-and-width)) (declare (ignorable __function__)) (b* ((dim-lsb (lnfix dim-lsb)) (dim-msb (lnfix dim-msb))) (vl-arrayrange-case x :range (b* (((unless (and (vl-expr-resolved-p x.lsb) (vl-expr-resolved-p x.msb))) (mv "Array range not resolved" nil nil)) (sel-lsb (vl-resolved->val x.lsb)) (sel-msb (vl-resolved->val x.msb)) ((when (or (and (< sel-lsb sel-msb) (< dim-msb dim-lsb)) (and (> sel-lsb sel-msb) (> dim-msb dim-lsb)))) (mv "Reversed array range" nil nil)) ((unless (or (and (<= dim-lsb sel-lsb) (<= sel-msb dim-msb)) (and (>= dim-lsb sel-lsb) (>= sel-msb dim-msb)))) (mv "Range indices out of bounds" nil nil)) (rel-lsb (abs (- sel-lsb dim-lsb))) (width (+ 1 (abs (- sel-msb sel-lsb))))) (mv nil rel-lsb width)) :index (b* (((unless (vl-expr-resolved-p x.expr)) (mv "Array index not resolved" nil nil)) (sel (vl-resolved->val x.expr)) ((unless (or (and (<= dim-lsb sel) (<= sel dim-msb)) (and (>= dim-lsb sel) (>= sel dim-msb)))) (mv "Range index out of bounds" nil nil)) (rel-lsb (abs (- sel dim-lsb))) (width 1)) (mv nil rel-lsb width)) :plusminus (b* (((unless (and (vl-expr-resolved-p x.width) (vl-expr-resolved-p x.base))) (mv "Array range not resolved" nil nil)) (sel-base (vl-resolved->val x.base)) (sel-width (vl-resolved->val x.width)) ((unless (> sel-width 0)) (mv "Range width zero" nil nil)) (sel-end (if x.minusp (- sel-base (- sel-width 1)) (+ sel-base (- sel-width 1)))) ((unless (if (< dim-lsb dim-msb) (and (<= dim-lsb sel-base) (<= dim-lsb sel-end) (<= sel-base dim-msb) (<= sel-end dim-msb)) (and (<= dim-msb sel-base) (<= dim-msb sel-end) (<= sel-base dim-lsb) (<= sel-end dim-lsb)))) (mv "Range indices out of bounds" nil nil)) (rel-lsb (min (abs (- sel-base dim-lsb)) (abs (- sel-end dim-lsb))))) (mv nil rel-lsb sel-width)) :otherwise (prog2$ (impossible) (mv "impossible" nil nil))))))
Theorem:
(defthm return-type-of-vl-arrayrange->rel-lsb-and-width.err (b* (((mv ?err ?rel-lsb ?width) (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb))) (iff (vl-msg-p err) err)) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-vl-arrayrange->rel-lsb-and-width.rel-lsb (b* (((mv ?err ?rel-lsb ?width) (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb))) (implies (not err) (natp rel-lsb))) :rule-classes :type-prescription)
Theorem:
(defthm return-type-of-vl-arrayrange->rel-lsb-and-width.width (b* (((mv ?err ?rel-lsb ?width) (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb))) (implies (not err) (posp width))) :rule-classes :type-prescription)
Theorem:
(defthm vl-arrayrange->rel-lsb-and-width-of-vl-arrayrange-fix-x (equal (vl-arrayrange->rel-lsb-and-width (vl-arrayrange-fix x) dim-lsb dim-msb) (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb)))
Theorem:
(defthm vl-arrayrange->rel-lsb-and-width-vl-arrayrange-equiv-congruence-on-x (implies (vl-arrayrange-equiv x x-equiv) (equal (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb) (vl-arrayrange->rel-lsb-and-width x-equiv dim-lsb dim-msb))) :rule-classes :congruence)
Theorem:
(defthm vl-arrayrange->rel-lsb-and-width-of-nfix-dim-lsb (equal (vl-arrayrange->rel-lsb-and-width x (nfix dim-lsb) dim-msb) (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb)))
Theorem:
(defthm vl-arrayrange->rel-lsb-and-width-nat-equiv-congruence-on-dim-lsb (implies (acl2::nat-equiv dim-lsb dim-lsb-equiv) (equal (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb) (vl-arrayrange->rel-lsb-and-width x dim-lsb-equiv dim-msb))) :rule-classes :congruence)
Theorem:
(defthm vl-arrayrange->rel-lsb-and-width-of-nfix-dim-msb (equal (vl-arrayrange->rel-lsb-and-width x dim-lsb (nfix dim-msb)) (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb)))
Theorem:
(defthm vl-arrayrange->rel-lsb-and-width-nat-equiv-congruence-on-dim-msb (implies (acl2::nat-equiv dim-msb dim-msb-equiv) (equal (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb) (vl-arrayrange->rel-lsb-and-width x dim-lsb dim-msb-equiv))) :rule-classes :congruence)