• 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
          • Expression-sizing
          • Occform
          • Oprewrite
            • Vl-op-oprewrite
              • Vl-modulelist-oprewrite
              • Vl-expr-oprewrite
              • Vl-maybe-delayoreventcontrol-oprewrite
              • Vl-repeateventcontrol-oprewrite
              • Vl-plainarglist-oprewrite
              • Vl-namedarglist-oprewrite
              • Vl-gateinstlist-oprewrite
              • Vl-delayoreventcontrol-oprewrite
              • Vl-modinstlist-oprewrite
              • Vl-initiallist-oprewrite
              • Vl-replicate-constint-value
              • Vl-evatomlist-oprewrite
              • Vl-assignlist-oprewrite
              • Vl-arguments-oprewrite
              • Vl-alwayslist-oprewrite
              • Vl-eventcontrol-oprewrite
              • Vl-delaycontrol-oprewrite
              • Vl-plainarg-oprewrite
              • Vl-namedarg-oprewrite
              • Vl-modinst-oprewrite
              • Vl-maybe-expr-oprewrite
              • Vl-initial-oprewrite
              • Vl-gateinst-oprewrite
              • Vl-assign-oprewrite
              • Vl-goofymux-p
              • Vl-evatom-oprewrite
              • Vl-always-oprewrite
              • Vl-replicate-weirdint-bits
              • Vl-maybe-consolidate-multiconcat
              • Vl-qmark-p
              • Vl-goofymux-rewrite
              • Vl-module-oprewrite
              • Vl-design-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
    • Oprewrite

    Vl-op-oprewrite

    Main operator rewriting function.

    Signature
    (vl-op-oprewrite op args atts warnings) → (mv warnings expr)
    Arguments
    op — Some operator.
        Guard (vl-op-p op).
    args — The arguments to the operator (already rewritten).
        Guard (vl-exprlist-p args).
    atts — The attributes for the operator.
        Guard (vl-atts-p atts).
    warnings — Ordinary warnings accumulator.
        Guard (vl-warninglist-p warnings).
    Returns
    warnings — Type (vl-warninglist-p warnings).
    expr — Possibly simplified, rewritten version of op(args).
        Type (vl-expr-p expr).

    Keeping this function separate from vl-expr-oprewrite helps to keep the mutual recursion as simple as possible.

    Definitions and Theorems

    Function: vl-op-oprewrite

    (defun vl-op-oprewrite (op args atts warnings)
     (declare (xargs :guard (and (vl-op-p op)
                                 (vl-exprlist-p args)
                                 (vl-atts-p atts)
                                 (vl-warninglist-p warnings))))
     (declare (xargs :guard (or (not (vl-op-arity op))
                                (equal (len args) (vl-op-arity op)))))
     (let ((__function__ 'vl-op-oprewrite))
      (declare (ignorable __function__))
      (case
       (vl-op-fix op)
       (:vl-qmark
        (b* (((list a b c) args)
             (or-a (make-vl-nonatom
                        :op :vl-unary-bitor
                        :args (list a)
                        :atts (acons "VL_CONDITIONAL_FIX" nil atts))))
          (if
           (vl-zatom-p b)
           (let
             ((nor-a (make-vl-nonatom
                          :op :vl-unary-bitnot
                          :args (list or-a)
                          :atts (acons "VL_CONDITIONAL_FIX" nil atts))))
             (mv (ok)
                 (make-vl-nonatom :op :vl-qmark
                                  :atts atts
                                  :args (list nor-a c b))))
           (mv (ok)
               (make-vl-nonatom :op :vl-qmark
                                :atts atts
                                :args (list or-a b c))))))
       (:vl-binary-logand
            (b* (((list a b) args)
                 (or-a (make-vl-nonatom :op :vl-unary-bitor
                                        :args (list a)))
                 (or-b (make-vl-nonatom :op :vl-unary-bitor
                                        :args (list b)))
                 (result (make-vl-nonatom :op :vl-binary-bitand
                                          :atts atts
                                          :args (list or-a or-b))))
              (mv (ok) result)))
       (:vl-binary-logor
            (b* (((list a b) args)
                 (or-a (make-vl-nonatom :op :vl-unary-bitor
                                        :args (list a)))
                 (or-b (make-vl-nonatom :op :vl-unary-bitor
                                        :args (list b)))
                 (result (make-vl-nonatom :op :vl-binary-bitor
                                          :atts atts
                                          :args (list or-a or-b))))
              (mv (ok) result)))
       (:vl-unary-plus
        (b*
         (((list a) args)
          (|1'sb0|
           (make-vl-atom :guts (make-vl-constint :value 0
                                                 :origwidth 1
                                                 :origtype :vl-signed)))
          (result (make-vl-nonatom :op :vl-binary-plus
                                   :atts atts
                                   :args (list a |1'sb0|))))
         (mv (ok) result)))
       (:vl-unary-minus
        (b*
         (((list a) args)
          (|1'sb0|
           (make-vl-atom :guts (make-vl-constint :value 0
                                                 :origwidth 1
                                                 :origtype :vl-signed)))
          (result (make-vl-nonatom :op :vl-binary-minus
                                   :atts atts
                                   :args (list |1'sb0| a))))
         (mv (ok) result)))
       (:vl-unary-lognot
            (b* (((list a) args)
                 (or-a (make-vl-nonatom :op :vl-unary-bitor
                                        :args (list a)))
                 (~or-a (make-vl-nonatom :op :vl-unary-bitnot
                                         :args (list or-a)))
                 (result (make-vl-nonatom :op :vl-concat
                                          :atts atts
                                          :args (list ~or-a))))
              (mv (ok) result)))
       (:vl-unary-nand
            (b* (((list a) args)
                 (and-a (make-vl-nonatom :op :vl-unary-bitand
                                         :args (list a)))
                 (~and-a (make-vl-nonatom :op :vl-unary-bitnot
                                          :args (list and-a)))
                 (result (make-vl-nonatom :op :vl-concat
                                          :atts atts
                                          :args (list ~and-a))))
              (mv (ok) result)))
       (:vl-unary-nor
            (b* (((list a) args)
                 (or-a (make-vl-nonatom :op :vl-unary-bitor
                                        :args (list a)))
                 (~or-a (make-vl-nonatom :op :vl-unary-bitnot
                                         :args (list or-a)))
                 (result (make-vl-nonatom :op :vl-concat
                                          :atts atts
                                          :args (list ~or-a))))
              (mv (ok) result)))
       (:vl-unary-xnor (b* (((list a) args)
                            (^a (make-vl-nonatom :op :vl-unary-xor
                                                 :args (list a)))
                            (~^a (make-vl-nonatom :op :vl-unary-bitnot
                                                  :args (list ^a)))
                            (result (make-vl-nonatom :op :vl-concat
                                                     :atts atts
                                                     :args (list ~^a))))
                         (mv (ok) result)))
       ((:vl-binary-eq)
        (b* (((list a b) args)
             (a~^b (make-vl-nonatom :op :vl-binary-xnor
                                    :args (list a b)))
             (result (make-vl-nonatom :op :vl-unary-bitand
                                      :atts atts
                                      :args (list a~^b))))
          (mv (ok) result)))
       ((:vl-binary-neq)
        (b* (((list a b) args)
             (a^b (make-vl-nonatom :op :vl-binary-xor
                                   :args (list a b)))
             (result (make-vl-nonatom :op :vl-unary-bitor
                                      :atts atts
                                      :args (list a^b))))
          (mv (ok) result)))
       (:vl-binary-cne
            (b* (((list a b) args)
                 (a===b (make-vl-nonatom :op :vl-binary-ceq
                                         :args (list a b)))
                 (~a===b (make-vl-nonatom :op :vl-unary-bitnot
                                          :args (list a===b)))
                 (result (make-vl-nonatom :op :vl-concat
                                          :atts atts
                                          :args (list ~a===b))))
              (mv (ok) result)))
       (:vl-binary-lt
            (b* (((list a b) args)
                 (a>=b (make-vl-nonatom :op :vl-binary-gte
                                        :args (list a b)))
                 (~a>=b (make-vl-nonatom :op :vl-unary-bitnot
                                         :args (list a>=b)))
                 (result (make-vl-nonatom :op :vl-concat
                                          :atts atts
                                          :args (list ~a>=b))))
              (mv (ok) result)))
       (:vl-binary-gt
            (b* (((list a b) args)
                 (b>=a (make-vl-nonatom :op :vl-binary-gte
                                        :args (list b a)))
                 (~b>=a (make-vl-nonatom :op :vl-unary-bitnot
                                         :args (list b>=a)))
                 (result (make-vl-nonatom :op :vl-concat
                                          :atts atts
                                          :args (list ~b>=a))))
              (mv (ok) result)))
       (:vl-binary-lte (b* (((list a b) args)
                            (result (make-vl-nonatom :op :vl-binary-gte
                                                     :atts atts
                                                     :args (list b a))))
                         (mv (ok) result)))
       (:vl-multiconcat
            (let ((result (vl-maybe-consolidate-multiconcat
                               (make-vl-nonatom :op :vl-multiconcat
                                                :args args
                                                :atts atts))))
              (mv (ok) result)))
       (otherwise (mv (ok)
                      (make-vl-nonatom :op op
                                       :args args
                                       :atts atts))))))

    Theorem: vl-warninglist-p-of-vl-op-oprewrite.warnings

    (defthm vl-warninglist-p-of-vl-op-oprewrite.warnings
      (b* (((mv ?warnings ?expr)
            (vl-op-oprewrite op args atts warnings)))
        (vl-warninglist-p warnings))
      :rule-classes :rewrite)

    Theorem: vl-expr-p-of-vl-op-oprewrite.expr

    (defthm vl-expr-p-of-vl-op-oprewrite.expr
      (b* (((mv ?warnings ?expr)
            (vl-op-oprewrite op args atts warnings)))
        (vl-expr-p expr))
      :rule-classes :rewrite)

    Theorem: vl-op-oprewrite-of-vl-op-fix-op

    (defthm vl-op-oprewrite-of-vl-op-fix-op
      (equal (vl-op-oprewrite (vl-op-fix op)
                              args atts warnings)
             (vl-op-oprewrite op args atts warnings)))

    Theorem: vl-op-oprewrite-vl-op-equiv-congruence-on-op

    (defthm vl-op-oprewrite-vl-op-equiv-congruence-on-op
      (implies (vl-op-equiv op op-equiv)
               (equal (vl-op-oprewrite op args atts warnings)
                      (vl-op-oprewrite op-equiv args atts warnings)))
      :rule-classes :congruence)

    Theorem: vl-op-oprewrite-of-vl-exprlist-fix-args

    (defthm vl-op-oprewrite-of-vl-exprlist-fix-args
      (equal (vl-op-oprewrite op (vl-exprlist-fix args)
                              atts warnings)
             (vl-op-oprewrite op args atts warnings)))

    Theorem: vl-op-oprewrite-vl-exprlist-equiv-congruence-on-args

    (defthm vl-op-oprewrite-vl-exprlist-equiv-congruence-on-args
      (implies (vl-exprlist-equiv args args-equiv)
               (equal (vl-op-oprewrite op args atts warnings)
                      (vl-op-oprewrite op args-equiv atts warnings)))
      :rule-classes :congruence)

    Theorem: vl-op-oprewrite-of-vl-atts-fix-atts

    (defthm vl-op-oprewrite-of-vl-atts-fix-atts
      (equal (vl-op-oprewrite op args (vl-atts-fix atts)
                              warnings)
             (vl-op-oprewrite op args atts warnings)))

    Theorem: vl-op-oprewrite-vl-atts-equiv-congruence-on-atts

    (defthm vl-op-oprewrite-vl-atts-equiv-congruence-on-atts
      (implies (vl-atts-equiv atts atts-equiv)
               (equal (vl-op-oprewrite op args atts warnings)
                      (vl-op-oprewrite op args atts-equiv warnings)))
      :rule-classes :congruence)

    Theorem: vl-op-oprewrite-of-vl-warninglist-fix-warnings

    (defthm vl-op-oprewrite-of-vl-warninglist-fix-warnings
      (equal (vl-op-oprewrite op
                              args atts (vl-warninglist-fix warnings))
             (vl-op-oprewrite op args atts warnings)))

    Theorem: vl-op-oprewrite-vl-warninglist-equiv-congruence-on-warnings

    (defthm vl-op-oprewrite-vl-warninglist-equiv-congruence-on-warnings
      (implies (vl-warninglist-equiv warnings warnings-equiv)
               (equal (vl-op-oprewrite op args atts warnings)
                      (vl-op-oprewrite op args atts warnings-equiv)))
      :rule-classes :congruence)