• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
      • Sv
      • Fgl
      • Vwsim
      • Vl
        • Syntax
        • Loader
        • Warnings
        • Getting-started
        • Utilities
        • Printer
        • Kit
        • Mlib
          • Scopestack
          • Hid-tools
          • Filtering-by-name
          • Vl-interface-mocktype
          • Stripping-functions
          • Genblob
          • Expr-tools
            • Vl-expr-typedecide
              • Vl-arithclass-p
                • Vl-arithclass-max
                  • Vl-arithclass-rank
                • Vl-datatype-arithclass
                • Vl-integer-arithclass-p
                • Vl-integer-arithclass->exprsign
                • Vl-exprsign->arithclass
              • Vl-binaryop-typedecide
              • Vl-funcall-typedecide
              • Vl-index-typedecide
              • Vl-unaryop-typedecide
              • Vl-signedness-ambiguity-warning
              • Vl-syscall-typedecide
              • Vl-value-typedecide
              • Vl-operandinfo-signedness-caveat
            • Vl-exprlist-resolved->vals
            • Vl-make-idexpr-list
            • Vl-idexprlist->names
            • Vl-expr-selfsize
            • Vl-expr-update-subexprs
            • Vl-exprlist-to-plainarglist
            • Vl-call-namedargs-update-subexprs
            • Vl-valuerangelist-update-subexprs
            • Vl-streamexprlist-update-subexprs
            • Vl-op-p
            • Vl-maybe-exprlist-update-subexprs
            • Vl-evatomlist-update-subexprs
            • Vl-expr-values
            • Vl-keyvallist-update-subexprs
            • Vl-assignpat-update-subexprs
            • Vl-valuerange-update-subexprs
            • Vl-scopeexpr-update-subexprs
            • Vl-partselect-update-subexprs
            • Vl-hidexpr-update-subexprs
            • Vl-expr-add-atts
            • Vl-arrayrange-update-subexprs
            • Vl-streamexpr-update-subexprs
            • Vl-slicesize-update-subexprs
            • Vl-plusminus-update-subexprs
            • Vl-patternkey-update-subexprs
            • Vl-expr-ops
            • Vl-make-integer
            • Vl-range-update-subexprs
            • Vl-idexpr
            • Vl-make-index
            • Vl-expr->subexprs
            • Vl-bitlist-from-nat
            • Vl-pps-expr
            • Vl-maybe-exprlist->subexprs
            • Vl-hidexpr->subexprs
            • Vl-evatomlist->subexprs
            • Vl-call-namedargs->subexprs
            • Vl-valuerangelist->subexprs
            • Vl-streamexprlist->subexprs
            • Vl-keyvallist->subexprs
            • Vl-exprlist-has-ops
            • Vl-expr-resolved-p
            • Vl-valuerange->subexprs
            • Vl-streamexpr->subexprs
            • Vl-slicesize->subexprs
            • Vl-scopeexpr->subexprs
            • Vl-patternkey->subexprs
            • Vl-partselect->subexprs
            • Vl-assignpat->subexprs
            • Vl-arrayrange->subexprs
            • Vl-pps-origexpr
            • Vl-plusminus->subexprs
            • Vl-idscope
            • Vl-idexpr->name
            • Vl-expr-has-ops
            • Vl-resolved->val
            • Vl-range->subexprs
            • Vl-idexpr-p
            • Vl-idexprlist-p
            • Vl-exprlist-resolved-p
            • Vl-idscope->name
            • Vl-idscope-p
            • Vl-zbitlist-p
            • Vl-zatom-p
            • Vl-op-fix
            • Vl-oplist
            • Vl-expr-varnames
            • Vl-one-bit-constants
          • Extract-vl-types
          • Hierarchy
          • Range-tools
          • Finding-by-name
          • Stmt-tools
          • Modnamespace
          • Flat-warnings
          • Reordering-by-name
          • Datatype-tools
          • Syscalls
          • Allexprs
          • Lvalues
          • Port-tools
        • Transforms
      • X86isa
      • Svl
      • Rtl
    • Software-verification
    • Math
    • Testing-utilities
  • Vl-arithclass-p

Vl-arithclass-max

(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:

  • If any operand is real, the result is real.
  • If any operand is unsigned, the result is unsigned, regardless of the operator.
  • If all operands are signed, the result will be signed, regardless of operator, except when specified otherwise.''

These rules seem pretty incomplete because not all expressions fit nicely into these types: for instance what is the result from a mintypmax expression or a tagged union type or an unpacked type or that sort of thing. But at any rate we imagine a hierarchy, where:

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 a + b and a is a unsigned but b is a shortreal, then the sum should be a shortreal.

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.)

Definitions and Theorems

Function: vl-arithclass-max-fn

(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: vl-arithclass-p-of-vl-arithclass-max

(defthm vl-arithclass-p-of-vl-arithclass-max
  (vl-arithclass-p (vl-arithclass-max x y)))

Theorem: vl-arithclass-max-of-vl-arithclass-max

(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: vl-arithclass-max-fn-of-vl-arithclass-fix-x

(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: vl-arithclass-max-fn-vl-arithclass-equiv-congruence-on-x

(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: vl-arithclass-max-fn-of-vl-arithclass-fix-y

(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: vl-arithclass-max-fn-vl-arithclass-equiv-congruence-on-y

(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)

Subtopics

Vl-arithclass-rank
Rankings of vl-arithclass-ps used in vl-arithclass-max.