Decide whether the datatype is signed/unsigned/real/other.
(vl-datatype-arithclass x) → (mv caveat-flag class)
Returns an vl-arithclass-p that describes the kind of this datatype. This function never fails, as such, but in some cases where implementations disagree on the correct signedness, we return a flag to signal that there is a caveat about that signedness.
This caveat occurs when we have packed dimensions on a usertype that is declared as signed. In this case, NCV treats the array as unsigned, but VCS treats it as signed. The SV spec only touches on this to say (from Sec. 7.4.1, Packed Arrays):
If a packed array is declared as signed, then the array viewed as a single vector shall be signed. The individual elements of the array are unsigned unless they are of a named type declared as signed. A partselect of a packed array shall be unsigned.
An example:
typedef logic signed [3:0] squad; squad [3:0] b; assign b = 16'hffff; logic [20:0] btest; assign btest = b;
In NCVerilog, btest has the value
Function:
(defun vl-datatype-arithclass (x) (declare (xargs :guard (vl-datatype-p x))) (declare (xargs :guard (vl-datatype-resolved-p x))) (let ((__function__ 'vl-datatype-arithclass)) (declare (ignorable __function__)) (b* (((when (consp (vl-datatype->udims x))) (mv nil :vl-other-class))) (vl-datatype-case x :vl-coretype (mv nil (vl-coretype-arithclass (vl-coretypename->info x.name) x.signedp)) :vl-struct (mv nil (cond ((not x.packedp) :vl-other-class) (x.signedp :vl-signed-int-class) (t :vl-unsigned-int-class))) :vl-union (mv nil (cond ((not x.packedp) :vl-other-class) (x.signedp :vl-signed-int-class) (t :vl-unsigned-int-class))) :vl-enum (vl-datatype-arithclass x.basetype) :vl-usertype (b* (((unless (mbt (and x.res t))) (mv (impossible) :vl-other-class)) ((mv caveat ans1) (vl-datatype-arithclass x.res)) ((when (and (consp (vl-datatype->pdims x)) (eq ans1 :vl-signed-int-class))) (mv t :vl-unsigned-int-class))) (mv caveat ans1))))))
Theorem:
(defthm vl-arithclass-p-of-vl-datatype-arithclass.class (b* (((mv ?caveat-flag common-lisp::?class) (vl-datatype-arithclass x))) (vl-arithclass-p class)) :rule-classes :rewrite)
Theorem:
(defthm vl-datatype-arithclass-of-vl-datatype-fix-x (equal (vl-datatype-arithclass (vl-datatype-fix x)) (vl-datatype-arithclass x)))
Theorem:
(defthm vl-datatype-arithclass-vl-datatype-equiv-congruence-on-x (implies (vl-datatype-equiv x x-equiv) (equal (vl-datatype-arithclass x) (vl-datatype-arithclass x-equiv))) :rule-classes :congruence)