20200630把零零碎碎收拾一下
在上次關於 SystemVerilog 數組網絡研討會之後,我收到了幾個有關數組和結構體之間的差異以及如何跨模塊共享聲明的問題。關於這個以及相關的更多內容將涵蓋在我的下一個網絡研討會-SystemVerilog的結構體和包。會議前半部分關於結構體,包含的主題有,何時該選擇組合結構體(packed structure)或非組合結構體(unpacked structure)。包是組織相關定義(如 USB 測試平臺的所有類或 PCI 硬體定義)的一種好方法。但是導入包意味著什麼呢?在網絡研討會的後半部分,你將了解導入包的最佳位置,以及如何編寫代碼,來避免在多個包中有重名定義的問題。例如,為什麼以下代碼不編譯,RED 和 GREEN 名稱的 Bug 是什麼?調試並找出答案。20200609SystemVerilog中的多維數組
謝謝所有註冊並參加了有關SystemVerilog數組的網絡研討會的人。有很多很棒的問題,在這裡(https://verificationacademy.com/sessions/taking-systemverilog-arrays-to-the-next-dimension/questions-and-answers)我已經回答了很多。「SystemVerilog數組」是一個大話題,我不得不省略許多想法。有關多維數組(Multidimensional Arrays,MDA)的問題很多,因此這裡僅作簡短介紹。複製並粘貼這些代碼,然後在你喜歡的模擬器上運行。搞亂,犯錯,再進行調試–——你是驗證工程師,請牢記這一點!讓我們從一個固定大小的一維數組開始,其中包含4個元素和一些代碼對其進行初始化。int one[4];
foreach (one[i]) one[i] = i;
int two[3][4]; //簡明寫法,等價於
two = '{ 3 { one } };
$display("two = %p", two); // '{'{0, 1, 2, 3}, '{0, 1, 2, 3}, '{0, 1, 2, 3}}
foreach (two[i,j]) // Not two[i][j]
$display("two[%0d][%0d]=%0d", i, j, two[i][j]);
two[0][0]=0
two[0][1]=1
two[0][2]=2
two[0][3]=3
two[1][0]=0
two[1][1]=1
two[1][2]=2
two[1][3]=3
two[2][0]=0
two[2][1]=1
two[2][2]=2
two[2][3]=3
int triangle[3][];
initial begin
$display("Start: triangle = %p\n", triangle);
foreach (triangle[i]) begin
$display("Construct: triangle[%0d]", i);
triangle[i] = new[i+1];
end
$display("Constructed: triangle = %p\n", triangle);
foreach (triangle[i,j]) begin
$display("Initialize: triangle[%0d][%0d]", i, j);
triangle[i][j] = i*10 + j;
end
$display("Final: triangle = %p", triangle); // '{'{0}, '{0, 0}, '{0, 0, 0}}
end
int sb[int][$];
initial begin
$display("Start: sb = %p\n", sb);
for (int i=0; i<22; i=i+2) begin
sb[i%10].push_front((i/10)*10);
end
$display("Init: sb = %p\n", sb);
end
typedef bit[23:0] addr_t;
class Xact;
addr_t addr;
int data;
function new(input int i);
addr = i%10; // Use one's digit
data = (i/10) * 10; // Use 10's digit
endfunction
endclass
Xact scoreboard[addr_t][$], t;
function void sb_add(input Xact t);
scoreboard[t.addr].push_front(t);
endfunction
initial begin
// Fill scoreboard with 0, 1, 2, ... 21
for (int i=0; i<22; i++) begin
t = new(i);
sb_add(t);
end
// Display the scoreboard contents
foreach (scoreboard[i,j]) begin
if (j==0) $write("\n scoreboard[%0d] = ", i);
$write("%0d ", scoreboard[i][j].data);
end
end