• 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
          • 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
            • Vl-modulelist-trunc
            • Vl-make-chopped-id
            • Vl-assign-trunc
            • Vl-truncate-weirdint
            • Vl-truncate-constint
            • Vl-assignlist-trunc
            • Vl-module-trunc
            • Vl-design-trunc
            • Vl-assignlist-can-skip-trunc-p
            • Vl-assign-can-skip-trunc-p
          • 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
  • Transforms

Trunc

Eliminate implicit truncations in assignments

This transformation must occur after expression splitting has already been applied. Recall that the split transformation brings all assignments into one of the following forms:

  1. lvalue = atom
  2. lvalue = (op atom1 atom2 ... atomN)

Unfortunately, Verilog allows for implicit truncations during assignments, so that the lvalue's width might be less than the operation's width. (The other case is that the widths agree, since the lvalue plays a role in the ctxsize computation, and so if the lvalue's width is larger than the expression's, the expression will be expanded to match.

And so we now introduce a rewrite which corrects for this, and results in assignments where the expressions always agree on the desired sizes. The basic transformation is as follows. We are looking at the assignment lvalue = expr. If lvalue is shorter than expr, we replace this assignment with something like:

wire [expr.width-1:0] trunc_12345;
assign trunc_12345 = expr;
assign lvalue = trunc_12345[lvalue.width-1:0];

where trunc_12345 is a fresh variable name. All of the resulting assignments are between lvalues and expressions that agree.

Subtopics

Vl-modulelist-trunc
(vl-modulelist-trunc x) maps vl-module-trunc across a list.
Vl-make-chopped-id
Generate the expression to truncate a wire.
Vl-assign-trunc
Make any implicit truncation in an assignment explicit.
Vl-truncate-weirdint
Special routine for truncating unsigned weirdint literals without introducing temporary wires.
Vl-truncate-constint
Special routine for truncating ordinary, unsigned constant integers, without introducing temporary wires.
Vl-assignlist-trunc
Vl-module-trunc
Eliminate implicit truncations in assignments throughout a module.
Vl-design-trunc
Top-level trunc transform.
Vl-assignlist-can-skip-trunc-p
Vl-assign-can-skip-trunc-p