system Verilog display 时间

发布时间 2023-03-30 14:10:33作者: 天山明月

目前的NPU模块的module level sim是c和sv混合的,npu core的行为由c code生成。方针的pattern有时候需要加入一些delay,c code自带的mdelay不能满足要求,自带的环境里面有一个delay函数,但是没有单位,因此在不想看函数code的情况下,想通过两次display仿真时间的方式得到这个自定义函数的延迟单位。

sv里有一个时间变量类型,realtime,这个类型以real(实数)存储时间。类似用法如下:

realtime time_1; 
time_1 = $realtime; 
$display("%t", time_1);

那么还有一个问题,如何控制display中%t的显示效果,或者说让他带上单位并且按照我需要的精度显示呢?

//$timeformat(unit#, prec#, "unit", minwidth);`
`$timeformat(-3, 2, " ms", 10);    // -3 and " ms" give useful display msg

unit      is the base that time is to be displayed in, from 0 to -15
precision is the number of decimal points to display.
"unit"    is a string appended to the time, such as " ns".
minwidth  is the minimum number of characters that will be displayed.

unit:  recommended "unit" text
  0 =   1 sec
 -1 = 100 ms
 -2 =  10 ms
 -3 =   1 ms 
 -4 = 100 us
 -5 =  10 us
 -6 =   1 us 
 -7 = 100 ns
 -8 =  10 ns
 -9 =   1 ns 
-10 = 100 ps
-11 =  10 ps
-12 =   1 ps 
-13 = 100 fs
-14 =  10 fs

所以在最前面调用$timeformat(),传入参数设定为自己需要的值。