|
|
The streaming operators perform packing of bit-stream types into a sequence of bits in a user-specified order. When used in the left-hand-side, the streaming operators perform the reverse operation, unpack a stream of bits into one or more variables. If the data being packed contains any 4-state types, the result of a pack operation is a 4-state stream; otherwise, the result of a pack is a 2-state stream. Unpacking a 4-state stream into a 2-state type is done by a cast to a 2-state variable, and vice-versa. |
|
|
1 module streaming();
2
3 //-------------------------------
4 // PACK Example
5 //-------------------------------
6 int j = { "A", "B", "C", "D" };
7
8 bit [31:0] stream;
9
10 initial begin
11 $display(" PACK");
12 $display("Value of j %0x",j);
13 $monitor("@%0dns stream value is %x",$time, stream);
14 #1 stream = { << byte {j}};
15 #1 stream = { >> {j}} ;
16 #1 stream = { << { 8'b0011_0101 }};
17 #1 stream = { << 16 {j}};
18 #1 stream = { << 4 { 6'b11_0101 }};
19 #1 stream = { >> 4 { 6'b11_0101 }} ;
20 #1 stream = { << 2 { { << { 4'b1101 }} }};
21 end
22
23 //-------------------------------
24 // UNPACK Example
25 //-------------------------------
26 int a, b, c;
27 logic [10:0] up [3:0];
28 logic [11:1] p1, p2, p3, p4;
29 bit [96:1] y;
30 int j ;
31 bit [99:0] d;
32
33 initial begin
34 #20 ;
35 $display(" UNPACK");
36 // Below line should give compile error
37 //{>>{ a, b, c }} = 23'b1;
38 {>>{ a, b, c }} = 96'b1;
39 $display("@%0dns a %x b %x c %x",$time,a,b,c);
40 {>>{ a, b, c }} = 100'b1;
41 $display("@%0dns a %x b %x c %x",$time,a,b,c);
42 { >> {p1, p2, p3, p4}} = up;
43 $display("@%0dns p1 %x p2 %x p3 %x p4 %x",$time,p1,p2,p3,p4);
44 y = {>>{ a, b, c }};
45 $display("@%0dns y %x",$time,y);
46 // Below line should give compile error
47 //j = {>>{ a, b, c }};
48 d = {>>{ a, b, c }};
49 $display("@%0dns d %x",$time,d);
50 end
51
52 endmodule
You could download file streaming.sv here
|