(vl-arithclass-max x y &rest rst) computes the arithmetic class for a non self-determined operand, given the classes of the arguments.
See SystemVerilog-2012 Section 11.8.1, Expression Evaluation Rules. This function loosely corresponds to the case for non self-determined operands, where ``the following rules apply:
These rules seem pretty incomplete because not all expressions fit nicely
into these types: for instance what is the result from a
signed < unsigned < shortreal < real < other
And the maximum class of an argument becomes the class for the operator.
For example, if we're computing the type of
We assign the ``other'' class to anything that is valid but doesn't seem like a sensible arithmetic type. For instance, an unpacked structure or weird operator like a mintypmax.
We use the ``error'' class only for cases where we truly cannot determine the type of something because of an error (e.g., undeclared identifier, etc.)
Function:
(defun vl-arithclass-max-fn (x y) (declare (xargs :guard (and (vl-arithclass-p x) (vl-arithclass-p y)))) (b* ((x (vl-arithclass-fix x)) (y (vl-arithclass-fix y))) (if (< (vl-arithclass-rank x) (vl-arithclass-rank y)) y x)))
Theorem:
(defthm vl-arithclass-p-of-vl-arithclass-max (vl-arithclass-p (vl-arithclass-max x y)))
Theorem:
(defthm vl-arithclass-max-of-vl-arithclass-max (equal (vl-arithclass-max (vl-arithclass-max x y) z) (vl-arithclass-max x (vl-arithclass-max y z))))
Theorem:
(defthm vl-arithclass-max-fn-of-vl-arithclass-fix-x (equal (vl-arithclass-max-fn (vl-arithclass-fix x) y) (vl-arithclass-max-fn x y)))
Theorem:
(defthm vl-arithclass-max-fn-vl-arithclass-equiv-congruence-on-x (implies (vl-arithclass-equiv x x-equiv) (equal (vl-arithclass-max-fn x y) (vl-arithclass-max-fn x-equiv y))) :rule-classes :congruence)
Theorem:
(defthm vl-arithclass-max-fn-of-vl-arithclass-fix-y (equal (vl-arithclass-max-fn x (vl-arithclass-fix y)) (vl-arithclass-max-fn x y)))
Theorem:
(defthm vl-arithclass-max-fn-vl-arithclass-equiv-congruence-on-y (implies (vl-arithclass-equiv y y-equiv) (equal (vl-arithclass-max-fn x y) (vl-arithclass-max-fn x y-equiv))) :rule-classes :congruence)