OverviewA tuple provides an unnamed data structure typically used to hold a small number of related fields. Like other SystemVerilog constructs, tuples are polymorphic, that is, they are parameterized on the types of data they hold. Tuples are typically found as return values from functions when more than one value must be returned.
In the Bluespec environment, tuples are defined for 2 to 7 element, i.e., Tuple2 through Tuple7. In most specific cases, named data structures should be used instead of tuples, since structures provide for better (self) documentation of the source code, since each field has a name in addition to its position.
Syntax- Tuple2 groups two items together, Tuple3 groups three items together, up through Tuple7 which groups seven items together.
- Tuples cannot be manipulated like normal structures; you cannot
create values of and select fields from tuples as you would a normal
structure.
- Values of these types can be created only by applying a predefined family of constructor functions.
- Fields of Tuples can only be extracted by applying a predefined set of selector functions.
typedef struct{ a tpl_1; b tpl_2; } Tuple2 #(type a, type b) deriving (Bits, Eq, Bounded);
typedef struct{ a tpl_1; b tpl_2; c tpl_3; } Tuple3 #(type a, type b, type c) deriving (Bits, Eq, Bounded);
typedef struct{ a tpl_1; b tpl_2; c tpl_3; d tpl_4; } Tuple4 #(type a, type b, type c, type d) deriving (Bits, Eq, Bounded);
typedef struct{ a tpl_1; b tpl_2; c tpl_3; d tpl_4; e tpl_5; } Tuple5 #(type a, type b, type c, type d, type e) deriving (Bits, Eq, Bounded);
typedef struct{ a tpl_1; b tpl_2; c tpl_3; d tpl_4; e tpl_5; f tpl_6; } Tuple6 #(type a, type b, type c, type d, type e, type f) deriving (Bits, Eq, Bounded);
typedef struct{ a tpl_1; b tpl_2; c tpl_3; d tpl_4; e tpl_5; f tpl_6; g tpl_7; } Tuple7 #(type a, type b, type c, type d, type e, type f, type g) deriving (Bits, Eq, Bounded);
FunctionsTuple Constructor Functionstuple2(e1, e2)
| Creates a variable of type Tuple2 with component values e1 and e2.
| tuple3(e1, e2, e3) | Creates a variable of type Tuple3 with component values e1, e2, and e3.
| tuple4(e1, e2, e3, e4) | Creates a variable of type Tuple4 with component values e1, e2, e3, and e4.
| tuple5(e1, e2, e3, e4, e5)
| Creates a variable of type Tuple5 with component values e1, e2, e3, e4, and e5.
| tuple6(e1, e2, e3, e4, e5, e6) | Creates a variable of type Tuple6 with component values e1, e2, e3, e4, e5, and e6.
| tuple7(e1, e2, e3, e4, e5, e6, e7) | Creates a variable of type Tuple7 with component values e1, e2, e3, e4, e5, e6, and e7.
|
Tuple Extract Functions
tpl_1 (x)
| Extracts the first field of x from a Tuple2 to Tuple7.
| tpl_2 (x) | Extracts the first field of x from a Tuple2 to Tuple7.
| tpl_3 (x) | Extracts the first field of x from a Tuple3 to Tuple7.
| tpl_4 (x)
| Extracts the first field of x from a Tuple4 to Tuple7.
| tpl_5 (x) | Extracts the first field of x from a Tuple5 to Tuple7. | tpl_6 (x) | Extracts the first field of x from a Tuple62 or Tuple7. | tpl_7 (x) | Extracts the first field of x from a Tuple7. |
Examples Tuple2#(int,Bool) // pair of items, an int and a Bool
Tuple3#(int,Bool,String) // triple of items, an int, a Bool and a String
|