quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Streaming operators (pack / unpack)

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.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - Streaming
   

space.gif


  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
   

space.gif

  ../images/main/bullet_star_pink.gif Simulator Output : Streaming
   

space.gif

        PACK
 Value of j 41424344
 @0ns stream value is 00000000
 @1ns stream value is 44434241
 @2ns stream value is 41424344
 @3ns stream value is 000000ac
 @4ns stream value is 43444142
 @5ns stream value is 0000004d
 @6ns stream value is d4000000
 @7ns stream value is 0000000e
        UNPACK
 @20ns a 00000000 b 00000000 c 00000001
 @20ns a 00000000 b 00000000 c 00000000
 @20ns p1 xxx p2 xxx p3 xxx p4 xxx
 @20ns y 000000000000000000000000
 @20ns d 0000000000000000000000000
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com