• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
        • Transforms
          • Expression-sizing
            • Expression-sizing-minutia
            • Expression-sizing-intro
            • Vl-keyvalue-pattern-collect-array-replacements
            • Vl-assignpattern-positional-replacement
            • Vl-plainarg-exprsize
            • Vl-assignpattern-keyvalue-replacement
            • Vl-keyvalue-pattern-collect-struct-replacements
            • Vl-modulelist-exprsize
            • Vl-expr-assignpattern-extend/truncate
            • Vl-structmemberlist->types
            • Vl-expr-size
              • Vl-expr-selfsize
              • Vl-expr-typedecide
              • Vl-expr-expandsizes
                • Vl-weirdint-atom-expandsizes
                • Vl-constint-atom-expandsizes
                • Vl-hidexpr-expandsizes
                • Vl-expandsizes-zeroextend
                  • Vl-atom-expandsizes
                  • Vl-string-atom-expandsizes
                  • Vl-sign-extend-constint
                • Vl-exprlist-expandsizes
                • Vl-exprlist-size
              • Vl-expr-selfdetermine-type
              • Vl-assignpattern-multi-replacement
              • Vl-parse-keyval-pattern-struct
              • Vl-plainarglist-exprsize
              • Vl-parse-keyval-pattern-array
              • Vl-warn-about-implicit-extension
              • Vl-assigncontext-size
              • Vl-arguments-exprsize
              • Vl-assignpattern-replacement
              • Vl-packeddimensionlist-exprsize
              • Vl-namedparamvaluelist-exprsize
              • Vl-maybe-delayoreventcontrol-exprsize
              • Vl-repeateventcontrol-exprsize
              • Vl-paramvaluelist-exprsize
              • Vl-maybe-packeddimension-exprsize
              • Vl-delayoreventcontrol-exprsize
              • Vl-namedparamvalue-exprsize
              • Vl-namedarglist-exprsize
              • Vl-enumitemlist-exprsize
              • Vl-packeddimension-exprsize
              • Vl-maybe-paramvalue-exprsize
              • Vl-evatomlist-exprsize
              • Vl-atom-selfdetermine-type
              • Vl-rangelist-exprsize
              • Vl-maybe-gatedelay-exprsize
              • Vl-maybe-datatype-exprsize
              • Vl-gatedelay-exprsize
              • Vl-paramargs-exprsize
              • Vl-namedarg-exprsize
              • Vl-eventcontrol-exprsize
              • Vl-enumbasetype-exprsize
              • Vl-delaycontrol-exprsize
              • Vl-paramvalue-exprsize
              • Vl-maybe-range-exprsize
              • Vl-enumitem-exprsize
              • Vl-range-exprsize
              • Vl-paramdecl-exprsize
              • Vl-paramdecllist-exprsize
              • Vl-maybe-expr-size
              • Vl-evatom-exprsize
              • Vl-vardecllist-exprsize
              • Vl-portdecllist-exprsize
              • Vl-modinstlist-exprsize
              • Vl-initiallist-exprsize
              • Vl-gateinstlist-exprsize
              • Vl-fundecllist-exprsize
              • Vl-assign-exprsize
              • Vl-interfaceport-exprsize
              • Vl-assignlist-exprsize
              • Vl-alwayslist-exprsize
              • Vl-portlist-exprsize
              • Vl-modinst-exprsize
              • Vl-gateinst-exprsize
              • Vl-fundecl-exprsize
              • Vl-vardecl-exprsize
              • Vl-regularport-exprsize
              • Vl-portdecl-exprsize
              • Vl-initial-exprsize
              • Vl-always-exprsize
              • Vl-port-exprsize
              • Vl-lvalue-type
              • Vl-classify-extension-warning-hook
              • Welltyped
              • Vl-castexpr->datatype
              • Vl-expr-size-assigncontext
              • Vl-type-expr-pairs-sum-datatype-sizes
              • Vl-basictype->datatype
              • Vl-expr-replace-assignpatterns
              • Vl-design-exprsize
              • Vl-op-simple-vector-p
              • Vl-expr-val-alist-max-count
              • Vl-expr-has-patterns
              • Vl-exprlist-max-count
              • Vl-unsigned-when-size-zero-lst
              • Vl-type-expr-pairs
              • Append-n
              • Vl-expr-val-alist
              • Vl-datatypelist
            • Occform
            • Oprewrite
            • Expand-functions
            • Delayredux
            • Unparameterization
            • Caseelim
            • Split
            • Selresolve
            • Weirdint-elim
            • Vl-delta
            • Replicate-insts
            • Rangeresolve
            • Propagate
            • Clean-selects
            • Clean-params
            • Blankargs
            • Inline-mods
            • Expr-simp
            • Trunc
            • Always-top
            • Gatesplit
            • Gate-elim
            • Expression-optimization
            • Elim-supplies
            • Wildelim
            • Drop-blankports
            • Clean-warnings
            • Addinstnames
            • Custom-transform-hooks
            • Annotate
            • Latchcode
            • Elim-unused-vars
            • Problem-modules
          • Lint
          • Mlib
          • Server
          • Kit
          • Printer
          • Esim-vl
          • Well-formedness
        • Sv
        • Fgl
        • Vwsim
        • Vl
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Vl-expr-expandsizes

    Vl-expandsizes-zeroextend

    Safely zero-extend an already-sized, unsigned expression to finalwidth.

    Signature
    (vl-expandsizes-zeroextend x finalwidth ctx warnings) 
      → 
    (mv successp warnings new-x)
    Arguments
    x — An expression that we may need to zero-extend.
        Guard (vl-expr-p x).
    finalwidth — Width we want to expand x to. Must be at least as large as the final width of x.
        Guard (natp finalwidth).
    ctx — Context for warnings.
        Guard (vl-context-p ctx).
    warnings — Ordinary warnings accumulator.
        Guard (vl-warninglist-p warnings).
    Returns
    successp — Type (booleanp successp).
    warnings — Type (vl-warninglist-p warnings).
    new-x — Type (vl-expr-p new-x).

    Warning: this function should typically only be called by the expression-sizing transform.

    If an extension is needed, we introduce an explicit concatenation, e.g., if we are expanding foo from 3 to 7 bits, we produce a new expression like { 4'b0, foo }. When no extension is needed, we just return x unchanged.

    Definitions and Theorems

    Function: vl-expandsizes-zeroextend

    (defun vl-expandsizes-zeroextend (x finalwidth ctx warnings)
     (declare (xargs :guard (and (vl-expr-p x)
                                 (natp finalwidth)
                                 (vl-context-p ctx)
                                 (vl-warninglist-p warnings))))
     (declare (xargs :guard (and (vl-expr->finalwidth x)
                                 (eq (vl-expr->finaltype x)
                                     :vl-unsigned))))
     (let ((__function__ 'vl-expandsizes-zeroextend))
      (declare (ignorable __function__))
      (b*
       ((x (vl-expr-fix x))
        (ctx (vl-context-fix ctx))
        (finalwidth (lnfix finalwidth))
        (x.finalwidth (lnfix (vl-expr->finalwidth x)))
        ((when (> x.finalwidth finalwidth))
         (mv
          nil
          (fatal
           :type :vl-programming-error
           :msg
           "~a0: trying to zero-extend ~a1, which has width ~x2, ~
                             to ~x3 bits??? Serious bug in our sizing code."
           :args (list ctx x x.finalwidth finalwidth))
          x))
        ((when (eql x.finalwidth finalwidth))
         (mv t (ok) x))
        (pad-width (- finalwidth x.finalwidth))
        (zero-guts (make-vl-constint :value 0
                                     :origwidth pad-width
                                     :origtype :vl-unsigned
                                     :wasunsized nil))
        (zero-atom (make-vl-atom :guts zero-guts
                                 :finalwidth pad-width
                                 :finaltype :vl-unsigned))
        (atts (acons (hons-copy "VL_ZERO_EXTENSION")
                     nil nil))
        (concat (make-vl-nonatom :op :vl-concat
                                 :args (list zero-atom x)
                                 :finalwidth finalwidth
                                 :finaltype :vl-unsigned
                                 :atts atts)))
       (mv t (ok) concat))))

    Theorem: booleanp-of-vl-expandsizes-zeroextend.successp

    (defthm booleanp-of-vl-expandsizes-zeroextend.successp
      (b* (((mv ?successp ?warnings ?new-x)
            (vl-expandsizes-zeroextend x finalwidth ctx warnings)))
        (booleanp successp))
      :rule-classes :type-prescription)

    Theorem: vl-warninglist-p-of-vl-expandsizes-zeroextend.warnings

    (defthm vl-warninglist-p-of-vl-expandsizes-zeroextend.warnings
      (b* (((mv ?successp ?warnings ?new-x)
            (vl-expandsizes-zeroextend x finalwidth ctx warnings)))
        (vl-warninglist-p warnings))
      :rule-classes :rewrite)

    Theorem: vl-expr-p-of-vl-expandsizes-zeroextend.new-x

    (defthm vl-expr-p-of-vl-expandsizes-zeroextend.new-x
      (b* (((mv ?successp ?warnings ?new-x)
            (vl-expandsizes-zeroextend x finalwidth ctx warnings)))
        (vl-expr-p new-x))
      :rule-classes :rewrite)

    Theorem: warning-irrelevance-of-vl-expandsizes-zeroextend

    (defthm warning-irrelevance-of-vl-expandsizes-zeroextend
      (let ((ret1 (vl-expandsizes-zeroextend x finalwidth ctx warnings))
            (ret2 (vl-expandsizes-zeroextend x finalwidth nil nil)))
        (implies (syntaxp (not (and (equal ctx ''nil)
                                    (equal warnings ''nil))))
                 (and (equal (mv-nth 0 ret1) (mv-nth 0 ret2))
                      (equal (mv-nth 2 ret1)
                             (mv-nth 2 ret2))))))

    Theorem: vl-expr->finalwidth-of-vl-expandsizes-zeroextend

    (defthm vl-expr->finalwidth-of-vl-expandsizes-zeroextend
     (implies
      (and
          (mv-nth 0
                  (vl-expandsizes-zeroextend x finalwidth ctx warnings))
          (force (vl-expr->finalwidth x))
          (force (equal (vl-expr->finaltype x)
                        :vl-unsigned)))
      (equal
       (vl-expr->finalwidth
         (mv-nth 2
                 (vl-expandsizes-zeroextend x finalwidth ctx warnings)))
       (nfix finalwidth))))

    Theorem: no-change-loser-of-vl-expandsizes-zeroextend

    (defthm no-change-loser-of-vl-expandsizes-zeroextend
      (let ((ret (vl-expandsizes-zeroextend x finalwidth ctx warnings)))
        (implies (not (mv-nth 0 ret))
                 (equal (mv-nth 2 ret)
                        (vl-expr-fix x)))))

    Theorem: vl-expr->finaltype-of-vl-expandsizes-zeroextend

    (defthm vl-expr->finaltype-of-vl-expandsizes-zeroextend
      (let ((ret (vl-expandsizes-zeroextend x finalwidth ctx warnings)))
        (implies (and (mv-nth 0 ret)
                      (force (vl-expr->finalwidth x))
                      (force (equal (vl-expr->finaltype x)
                                    :vl-unsigned)))
                 (equal (vl-expr->finaltype (mv-nth 2 ret))
                        :vl-unsigned))))

    Theorem: vl-expr-welltyped-p-of-vl-expandsizes-zeroextend

    (defthm vl-expr-welltyped-p-of-vl-expandsizes-zeroextend
      (let ((ret (vl-expandsizes-zeroextend x finalwidth ctx warnings)))
        (implies (and (mv-nth 0 ret)
                      (force (vl-expr-welltyped-p x))
                      (force (vl-expr->finalwidth x))
                      (force (equal (vl-expr->finaltype x)
                                    :vl-unsigned)))
                 (vl-expr-welltyped-p (mv-nth 2 ret)))))

    Theorem: vl-expandsizes-zeroextend-of-vl-expr-fix-x

    (defthm vl-expandsizes-zeroextend-of-vl-expr-fix-x
      (equal (vl-expandsizes-zeroextend (vl-expr-fix x)
                                        finalwidth ctx warnings)
             (vl-expandsizes-zeroextend x finalwidth ctx warnings)))

    Theorem: vl-expandsizes-zeroextend-vl-expr-equiv-congruence-on-x

    (defthm vl-expandsizes-zeroextend-vl-expr-equiv-congruence-on-x
     (implies
      (vl-expr-equiv x x-equiv)
      (equal
           (vl-expandsizes-zeroextend x finalwidth ctx warnings)
           (vl-expandsizes-zeroextend x-equiv finalwidth ctx warnings)))
     :rule-classes :congruence)

    Theorem: vl-expandsizes-zeroextend-of-nfix-finalwidth

    (defthm vl-expandsizes-zeroextend-of-nfix-finalwidth
      (equal (vl-expandsizes-zeroextend x (nfix finalwidth)
                                        ctx warnings)
             (vl-expandsizes-zeroextend x finalwidth ctx warnings)))

    Theorem: vl-expandsizes-zeroextend-nat-equiv-congruence-on-finalwidth

    (defthm vl-expandsizes-zeroextend-nat-equiv-congruence-on-finalwidth
     (implies
      (acl2::nat-equiv finalwidth finalwidth-equiv)
      (equal
           (vl-expandsizes-zeroextend x finalwidth ctx warnings)
           (vl-expandsizes-zeroextend x finalwidth-equiv ctx warnings)))
     :rule-classes :congruence)

    Theorem: vl-expandsizes-zeroextend-of-vl-context-fix-ctx

    (defthm vl-expandsizes-zeroextend-of-vl-context-fix-ctx
     (equal (vl-expandsizes-zeroextend x finalwidth (vl-context-fix ctx)
                                       warnings)
            (vl-expandsizes-zeroextend x finalwidth ctx warnings)))

    Theorem: vl-expandsizes-zeroextend-vl-context-equiv-congruence-on-ctx

    (defthm vl-expandsizes-zeroextend-vl-context-equiv-congruence-on-ctx
     (implies
      (vl-context-equiv ctx ctx-equiv)
      (equal
           (vl-expandsizes-zeroextend x finalwidth ctx warnings)
           (vl-expandsizes-zeroextend x finalwidth ctx-equiv warnings)))
     :rule-classes :congruence)

    Theorem: vl-expandsizes-zeroextend-of-vl-warninglist-fix-warnings

    (defthm vl-expandsizes-zeroextend-of-vl-warninglist-fix-warnings
      (equal
           (vl-expandsizes-zeroextend x finalwidth
                                      ctx (vl-warninglist-fix warnings))
           (vl-expandsizes-zeroextend x finalwidth ctx warnings)))

    Theorem: vl-expandsizes-zeroextend-vl-warninglist-equiv-congruence-on-warnings

    (defthm
     vl-expandsizes-zeroextend-vl-warninglist-equiv-congruence-on-warnings
     (implies
      (vl-warninglist-equiv warnings warnings-equiv)
      (equal
           (vl-expandsizes-zeroextend x finalwidth ctx warnings)
           (vl-expandsizes-zeroextend x finalwidth ctx warnings-equiv)))
     :rule-classes :congruence)