一個packed structure有很多的bits組成,這些bit在物理上連續存儲。packed structure只允許包含packed數據類型。
struct packed signed {
byte BE; //2-state
int addr; //2-state
int data; //2-state
} pStruct; //signed, 2-state
在上面的例子中,我們顯式地將packed struct聲明為“signed”。
如果一個packed structure中的所有數據類型都是2-state,structure作為一個整體被視為一個2-state向量。
如果一個packed structure中的存在一個數據的數據類型是4-state,structure作為一個整體被視為一個4-state向量。
一個unsigned structure示例:
struct packed unsigned {
integer addr; //4-state
logic [31:0] data; //4-state
int burst; //2-state
} upStruct; //unsigned, 4-state
在上面的例子中,成員中存在4-state變量,所以整個結構體被視為一個4-state變量。
module SU;
struct packed {
bit [7:0] intr; //packed struct
logic [23:0] addr;
} SUR;
initial begin
SUR.intr = 'hFF;
$display($stime,,, "SUR = %h",SUR);
$display($stime,,, "SUR Intr = %h",SUR.intr);
//Assign by position
SUR = '{'h00,'hFF_FF_FF};
$display($stime,,, "SUR = %h",SUR);
//Assign by name
SUR = '{intr:'h01, addr:'hf0f0f0};
$display($stime,,, "SUR = %h",SUR);
//Assign default
SUR = '{default:'h123456};
$display($stime,,, "SUR = %h",SUR);//Assign default
SUR = '{default:'h78};
$display($stime,,, "SUR = %h",SUR);
SUR = 0;
SUR = SUR+'h12; //Arithmetic operation.
// packed structure can be used as a vector
$display($stime,,, "SUR = %h",SUR);
end
endmodule
仿真log:
0 SUR = ffxxxxxx 0 SUR Intr = ff 0 SUR = 00ffffff 0 SUR = 01f0f0f0 0 SUR = 56123456 0 SUR = 78000078 0 SUR = 00000012 V C S S i m u l a t i o n R e p o r t
在這個例子中,我們給結構體中的單個成員賦值(通過名稱或者位置索引),也可以將結構體作為一個整體賦值和算術運算。
給整個結構體賦值需要使用‘{…},這個{}在這里不是連接的含義,而是結構體中各個成員的集合。
下面是一個packed結構體,以及其在內存中的存放示意圖。
struct packed {
logic frame_;
logic [15:0] address;
logic [31:0] data;
} control;

審核編輯:湯梓紅
-
Verilog
+關注
關注
30文章
1374瀏覽量
114522 -
System
+關注
關注
0文章
166瀏覽量
38669 -
結構體
+關注
關注
1文章
131瀏覽量
11371
原文標題:SystemVerilog中的Packed Structure
文章出處:【微信號:芯片驗證工程師,微信公眾號:芯片驗證工程師】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
SystemVerilog中的“const”類屬性
基于事件結構的SystemVerilog指稱語義
SpinalHDL中Bundle數據類型的轉換
SystemVerilog中$cast的應用
unpacked數組和packed數組的主要區別
SystemVerilog中的Packed Union
SystemVerilog中的Semaphores
SystemVerilog中至關重要的結構體和自定義類型
Systemverilog中的Driving Strength講解
SystemVerilog中的Packed Structure
評論