• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
        • Transforms
        • Lint
        • Mlib
          • Scopestack
          • Filtering-by-name
          • Vl-namefactory
          • Substitution
          • Allexprs
          • Hid-tools
          • Vl-consteval
          • Range-tools
          • Lvalexprs
          • Hierarchy
          • Finding-by-name
          • Expr-tools
          • Expr-slicing
          • Stripping-functions
          • Stmt-tools
          • Modnamespace
          • Vl-parse-expr-from-str
          • Welltyped
          • Reordering-by-name
          • Flat-warnings
          • Genblob
          • Expr-building
            • Vl-make-binary-gateinstlist
            • Vl-make-binary-gateinst
            • Vl-make-unary-gateinstlist
            • Vl-make-bitselect
            • Vl-make-unary-gateinst
            • Vl-make-partselect
              • Vl-make-msb-to-lsb-bitselects
              • Vl-make-list-of-bitselects
              • Vl-default-n-bit-expr
            • Datatype-tools
            • Syscalls
            • Relocate
            • Expr-cleaning
            • Namemangle
            • Caremask
            • Port-tools
            • Lvalues
          • Server
          • Kit
          • Printer
          • Esim-vl
          • Well-formedness
        • Sv
        • Fgl
        • Vwsim
        • Vl
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Expr-building

    Vl-make-partselect

    Safely creates expr[msb:lsb].

    Signature
    (vl-make-partselect expr msb lsb) → |expr[msb:lsb]|
    Arguments
    expr — Guard (vl-expr-p expr).
    msb — Guard (natp msb).
    lsb — Guard (natp lsb).
    Returns
    |expr[msb:lsb]| — Type (vl-expr-p |expr[msb:lsb]|).

    We ensure that expr is an identifier and that msb >= lsb. Moreover, if msb = lsb, we create the bitselect expr[msb] instead.

    Historic note. This used to have the same problem as vl-make-bitselect, and checked whether the msb was less than the final-width of expression. See the discussion there.

    We no longer try to prevent you from creating part-selects with invalid ranges, since it's just not possible to do that correctly here. Garbage in, garbage out.

    Definitions and Theorems

    Function: vl-make-partselect

    (defun vl-make-partselect (expr msb lsb)
      (declare (xargs :guard (and (vl-expr-p expr)
                                  (natp msb)
                                  (natp lsb))))
      (let ((__function__ 'vl-make-partselect))
        (declare (ignorable __function__))
        (b* ((msb (lnfix msb))
             (lsb (lnfix lsb))
             ((when (> lsb msb))
              (raise "LSB, ~x0, is larger than MSB, ~x1."
                     lsb msb)
              (vl-default-n-bit-expr 1))
             (width (+ 1 (- msb lsb)))
             (msb-index (vl-make-index msb))
             (lsb-index (vl-make-index lsb))
             ((unless (and (vl-fast-atom-p expr)
                           (vl-fast-id-p (vl-atom->guts expr))))
              (raise "Trying to select from a non-identifier: ~x0"
                     expr)
              (vl-default-n-bit-expr width))
             ((when (= lsb msb))
              (make-vl-nonatom :op :vl-bitselect
                               :args (list expr msb-index)
                               :finalwidth 1
                               :finaltype :vl-unsigned)))
          (make-vl-nonatom :op :vl-partselect-colon
                           :args (list expr msb-index lsb-index)
                           :finalwidth width
                           :finaltype :vl-unsigned))))

    Theorem: vl-expr-p-of-vl-make-partselect

    (defthm vl-expr-p-of-vl-make-partselect
      (b* ((|expr[msb:lsb]| (vl-make-partselect expr msb lsb)))
        (vl-expr-p |expr[msb:lsb]|))
      :rule-classes :rewrite)

    Theorem: vl-expr->finalwidth-of-vl-make-partselect

    (defthm vl-expr->finalwidth-of-vl-make-partselect
      (equal (vl-expr->finalwidth (vl-make-partselect expr msb lsb))
             (+ 1 (nfix (- (nfix msb) (nfix lsb))))))

    Theorem: vl-expr-widthsfixed-p-of-vl-make-partselect

    (defthm vl-expr-widthsfixed-p-of-vl-make-partselect
      (implies
           (force (vl-expr-widthsfixed-p expr))
           (vl-expr-widthsfixed-p (vl-make-partselect expr msb lsb))))

    Theorem: vl-make-partselect-of-vl-expr-fix-expr

    (defthm vl-make-partselect-of-vl-expr-fix-expr
      (equal (vl-make-partselect (vl-expr-fix expr)
                                 msb lsb)
             (vl-make-partselect expr msb lsb)))

    Theorem: vl-make-partselect-vl-expr-equiv-congruence-on-expr

    (defthm vl-make-partselect-vl-expr-equiv-congruence-on-expr
      (implies (vl-expr-equiv expr expr-equiv)
               (equal (vl-make-partselect expr msb lsb)
                      (vl-make-partselect expr-equiv msb lsb)))
      :rule-classes :congruence)

    Theorem: vl-make-partselect-of-nfix-msb

    (defthm vl-make-partselect-of-nfix-msb
      (equal (vl-make-partselect expr (nfix msb) lsb)
             (vl-make-partselect expr msb lsb)))

    Theorem: vl-make-partselect-nat-equiv-congruence-on-msb

    (defthm vl-make-partselect-nat-equiv-congruence-on-msb
      (implies (acl2::nat-equiv msb msb-equiv)
               (equal (vl-make-partselect expr msb lsb)
                      (vl-make-partselect expr msb-equiv lsb)))
      :rule-classes :congruence)

    Theorem: vl-make-partselect-of-nfix-lsb

    (defthm vl-make-partselect-of-nfix-lsb
      (equal (vl-make-partselect expr msb (nfix lsb))
             (vl-make-partselect expr msb lsb)))

    Theorem: vl-make-partselect-nat-equiv-congruence-on-lsb

    (defthm vl-make-partselect-nat-equiv-congruence-on-lsb
      (implies (acl2::nat-equiv lsb lsb-equiv)
               (equal (vl-make-partselect expr msb lsb)
                      (vl-make-partselect expr msb lsb-equiv)))
      :rule-classes :congruence)