• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • 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
          • Extract-vl-types
          • Hierarchy
          • Range-tools
            • Vl-range-resolved-p
            • Vl-maybe-range-size
            • Vl-maybe-range-resolved-p
            • Vl-selwidth
            • Vl-range-size
            • Vl-maybe-range-msbidx
            • Vl-maybe-range-lsbidx
            • Vl-maybe-range-lowidx
            • Vl-range-low-idx
            • Vl-maybe-range-revp
            • Vl-range-msbidx
            • Vl-range-lsbidx
            • Vl-range-revp
          • 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
  • Mlib

Range-tools

Basic functions for working with ranges.

In Verilog, ranges are used in net and register declarations, and also in module- and gate-instance declarations to describe arrays of modules or gates.

For gate and module instances, the Verilog-2005 standard is pretty clear. 7.1.5 covers gate instances and 12.1.2 says that module instances have the same rules. In short, neither side has to be larger than the other, neither side has to be zero, and it always specifies abs(left-right)+1 occurrences (so that if they're the same it means one gate).

BOZO consider "negative" numbers and what they might mean.

The specification doesn't give similarly crisp semantics to net and reg ranges. Verilog-XL is horribly permissive, allowing even negative indexes and such. But Verilog-XL indeed seems to treat w[1:1] as a single bit, and in the Centaur design there are occurrences of [0:0] and [1:1] and such. So it may be that the semantics are supposed to be the same? It turns out that there are at least some differences, e.g., you're not allowed to select bit 0 from a plain wire, but you can select bit 0 from w[0:0], etc.

Historically, VL required the msb index is not smaller than the lsb index. But we now try to permit designs that use ranges that go from both high to low and low to high.

The difference is that for a wire like wire [5:0] w, the most significant bit is w[5] and the least significant is w[0], whereas for wire [0:5] v, the most significant bit is v[0] and the least significant is v[5].

Regardless of how the range is written, the wire behaves the same as far as operations like addition, concatenation, and so forth are concerned. This might seem pretty surprising. For instance,

wire [3:0] a = 4'b0001;
wire [0:3] b = 4'b1000;
wire [7:0] c = {a, b};

Results in c having the value 8'b 0001_1000. Basically the way that the bits of b are represented doesn't affect its value as an integer, and when we just write b we're referring to that value.

Where it does matter is when bits or parts are selected from the wire. That is, b[0] is 1 since its indices go from low to high.

Subtopics

Vl-range-resolved-p
Determine if a range's indices have been resolved to constants.
Vl-maybe-range-size
Usual way to compute the width of a net/reg, given its range.
Vl-maybe-range-resolved-p
Vl-selwidth
Returns the width of a range [a:b], i.e., |a-b|+1.
Vl-range-size
The size of a range is one more than the difference between its msb and lsb. For example [3:0] has size 4.
Vl-maybe-range-msbidx
Extract the MSB (left) index from a resolved vl-maybe-range; treats the empty range as [0:0], i.e., its MSB is 0.
Vl-maybe-range-lsbidx
Extract the LSB (right) index from a resolved vl-maybe-range; treats the empty range as [0:0], i.e., its LSB index is 0.
Vl-maybe-range-lowidx
Extract the lesser of the msb and lsb of a resolved vl-maybe-range; treats the empty range as [0:0], i.e., its low index is 0.
Vl-range-low-idx
Extract the lesser of the msb and lsb of a resolved vl-range.
Vl-maybe-range-revp
Determine if a resolved vl-maybe-range is in ``reverse'' order, i.e., if its msb < lsb; treats the empty range as [0:0], i.e., not in reverse order.
Vl-range-msbidx
Extract the MSB (left) index from a resolved vl-range.
Vl-range-lsbidx
Extract the LSB (right) index from a resolved vl-range.
Vl-range-revp
Determine if a resolved vl-range is in ``reverse'' order, i.e., if its msb < lsb.