【轉】https://blog.csdn.net/kevindas/article/details/80380144
說明:系統函數的介紹參考的是VCS User Guide和IEEE Verilog-2005標准,不同IDE可能不太一樣。1、$test$plusargs(string) 在對verilog代碼進行編譯時,我們會在代碼中引入`ifdef, `elsif, `endif等條件編譯指令,然后在編譯時指定宏來對編譯代碼范圍進行控制。系統函數$test$plusargs的目的就是用來替換這些條件編譯指令的。 在使用時,該函數會判斷參數string是否定義,從而返回0或非0。VCS User Guide上例子如下:
initial
if ($test$plusargs("postprocess"))
begin
$vcdpluson(0,design_1);
$vcdplusdeltacycleon;
$vcdplusglitchon;
end
當然,這里所謂的定義就不再是define定義的宏了,而是在VCS運行simv時指定的參數。比如上面的例子,你就需要如下的參數:
% simv +postprocess
Q1:那么問題來了,既然已經有了條件編譯指令,這樣做會不會顯得很多余?
A1:關鍵就在於條件編譯會在編譯階段生效,而系統函數$test$plusargs則會在仿真階段生效。換句話說,當參數發生變化時,你不需要重新編譯代碼,只需要改變參數重新運行仿真即可。
Q2:既然系統函數$test$plusargs這么好,那么是不是條件編譯指令就沒有用武之地了?
A2:好處是有代價的,引入系統函數會讓你的編譯變得更龐大(預編譯只對相應代碼編譯,其它部分即使語法錯誤也不管),而且simv的運行效率更低。事實上,synopsys官方都不建議我們直接使用該函數:
For this reason, Synopsys recommends that if you use this technique,
you should plan to abandon it fairly early in the development cycle
and switch to either the conditional compilation technique for writing
simulation history files, or a combination of the two techniques.
Q3:到底要不要使用這個函數?
A3:我認為還是按照官方的建議來,采用$test$plusargs與預編譯結合的方式(個中妙處,自行體會):
`ifdef comppostprocess
initial
if ($test$plusargs("postprocess"))
begin
$vcdpluson(0,design_1);
$vcsplusdeltacycleon;
$vcdplusglitchon;
end
`endif
pitfall:
這個函數在掃描參數list時只顧自己,只要自己匹配上了,就不管參數后半截了,也是就說,當參數是+postprocessabc也是能夠匹配上的。
2、$value$plusargs(user_string, variable)
這個系統函數用於在仿真時將一個參數傳遞至內部信號。
example:
module valueplusargs;
reg [31:0] r1;
integer status;
initial
begin
$monitor("r1=%0d at %0t",r1,$time);
#1 r1=0;
#1 status=$value$plusargs("r1=%d",r1);
end
endmodule
user_string格式可以變化,只要vcs能正確提取數據即可。運行時指定參數值:
% simv +r1=10
運行結果:
r1=x at 0
r1=0 at 1
r1=10 at 2
user_string的格式和$display函數一致,支持的數據類型如下:
%d decimal conversion
%o octal conversion
%h hexadecimal conversion
%b binary conversion
%e real exponential conversion
%f real decimal conversion
%g real decimal or exponential conversion
%s string (no conversion)是支持小數類型的,網上其它地方說只支持整型是不對的。
————————————————
版權聲明:本文為CSDN博主「kevindas」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/kevindas/article/details/80380144
