Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Đăng ký
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
wafer.jpg

Packing And Unpacking

Email In PDF.

Packing And Unpacking

Packing performs concatenation of scalars, strings, list elements, or struct fields in the order that you specify. Unpacking performs the reverse operation, splitting a single expression into multiple expressions.

As part of the concatenation or splitting process, packing and unpacking also perform type conversion between any of the following:

  • scalars
  • strings
  • lists and list subtypes

pack()

Packing a scalar expression creates an ordered bit stream by concatenating the bits of the expression together.

Packing are of two types:

  • packing.low
  • packing.high
    Example - pack()
  1 <'
  2 struct instruction { 
  3     %opcode     : uint (bits : 3); 
  4     %operand    : uint (bits : 5); 
  5     %address    : uint (bits : 8); 
  6      ! data_packed_high : list of bit; 
  7      ! data_packed_low  : list of bit; 
  8     keep opcode ==  0b100; 
  9     keep operand == 0b11001; 
 10     keep address == 0b00001111; 
 11     post_generate() is also {
 12        data_packed_low = pack(packing.low, opcode, operand); 
 13        data_packed_high = pack(packing.high, opcode, operand);  
 14     };
 15 };
 16 
 17 extend sys {
 18   ins : instruction;
 19   run() is also {
 20     print ins using bin;
 21     print ins.data_packed_low using bin;
 22     print ins.data_packed_high using bin;
 23   };
 24 };
25 '>
Output - pack()
  ins = instruction-@0: instruction

               ----------------------------------------------         @packing1

0              %opcode:                        0b100

1              %operand:                       0b11001

2              %address:                       0b00001111

3              !data_packed_high:              (8 items)

4              !data_packed_low:               (8 items)

  ins.data_packed_low =  (8 items, bin):

                                                     1 1 0 0  1 1 0 0  .0            

  ins.data_packed_high =  (8 items, bin):

                                                  1 0 0 1  1 0 0 1  .0

unpack()

Unpacking a bit stream into a scalar expression fills the scalar expression, starting by default by putting the lowest bit of the bit stream into the lowest bit of the scalar expression.

Unpacking are of two types:

  • packing.low
  • packing.high
Example - unpack()
  1 <'
  2 struct instruction { 
  3   %opcode     : uint (bits : 3); 
  4   %operand    : uint (bits : 5); 
  5   %address    : uint (bits : 8); 
  6 };
  7 
  8 extend sys { 
  9   post_generate() is also { 
 10     var inst : instruction; 
 11     var packed_data: list of bit; 
 12     packed_data = {1;1;1;1;0;0;0;0;1;0;0;1;1;0;0;1}; 
 13     unpack(packing.high, packed_data, inst); 
 14     print packed_data using bin;
 15     out("Unpacking high");
 16     print inst using bin;
 17     unpack(packing.low, packed_data, inst); 
 18     out("Unpacking low");
 19     print inst using bin;
 20   }; 
 21 };
 22 '>
Output - unpack()
  packed_data =  (16 items, bin):

                                   1 0 0 1  1 0 0 1  0 0 0 0  1 1 1 1           .0           

Unpacking high

  inst = instruction-@0: instruction

               ----------------------------------------------         @packing2

0              %opcode:                        0b100

1              %operand:                       0b11001

2              %address:                       0b00001111

Unpacking low

  inst = instruction-@0: instruction

               ----------------------------------------------         @packing2

0              %opcode:                        0b111

1              %operand:                       0b00001

2              %address:                       0b10011001

Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

 

Lần cập nhật cuối ( Thứ ba, 03 Tháng 5 2022 19:43 )  

Related Articles

Chat Zalo