Learning BSV‎ > ‎Data Types‎ > ‎

Bit#(n)

Bit#(n) is a polymorphic data type which defines a type containing n bits.  This may be the most familiar data type to Verilog users.

 Bit#(n)

Usage

  • Use for variables which are simple bit patterns.  This is the type on which you can perform bit-wise operations. 
  • In general, you should use Bit#(n) only for data types which require bit modification, such as control fields, patterns, etc. If the data is a counter, or numerical value, then you should use Int or UInt.
  • Bit#(1) cannot be used as a Bool; that is, the operators &&, ||, and ! are not allowed. 
  • The type bit is a special case for simplicity and for backwards compatibility.  It is the same as Bit#(1)>. 
  • bit[15:0] is a synonym for Bit#(16).

Examples


 Bit#(32) a;  // like 'reg [31:] a'
 Bit#(1)  b;  // like 'reg a'
 bit      c;  // same as Bit#(1) c


Data Type Conversion Functions

Bluespec provides a set of functions to convert a type between Bit#(n) and other types.  During type checking, the compiler resolves these functions to a particular type instance. If you have excessive type conversion in your design, it usually indicates a poor choice of the basic object types in the design, and you may want to review your type choices.  These conversion utilities do not incur logic overhead.
Comments