Virtuoso VerilogA 常用函数

速查:类型转换、仿真环境查询、常用系统任务。详细分类见 09 - VerilogA 仿真器函数。

类型转换

  1. $rtoi将实数转换为整数。当您想要截断实数的小数部分并获取其整数表示形式时,使用此函数。

    integer  $rtoi(real_val);  // For example, 192.15 becomes 192
    
  2. $itor将整数转换为实数。当您想要执行涉及实数但以整数值开头的计算时,使用此函数。

    real  $itor(int_val);  // For example, 192 becomes 192.0
    
  3. $realtobits将实数转换为其二进制 (位) 等效值。当您需要以二进制形式表示浮点值以进行存储或传输时,此函数非常有用。

    [63:0]  $realtobits(real_val);
    
  4. $bitstoreal将位模式(二进制表示形式)转换为实数。当您需要将二进制值解释为浮点数时,此函数非常有用。

    real  $bitstoreal(bit_val);
    

仿真时间与环境

函数 说明
$abstime() 瞬态仿真当前绝对时间
$realtime([unit]) 当前时间,可按单位返回(1/10/100 × s/ms/us/ns/ps/fs)
$temperature() 当前仿真温度(绝对温度,室温 300K)
$vt([temp]) 热电压 KT/q,可指定温度
$simparam("scale"/"gmin"/"iteration") 查询仿真器参数
$strobe("t=%g T=%g vt=%g", $abstime, $temperature(), $vt);

数学与信号

函数 说明
abs/ceil/floor/exp/ln/log/pow/sqrt 基础数学(见 08 - VerilogA 数学函数)
max(x,y) / min(x,y) 最大/最小值
sin/cos/tan/asin/acos/atan/atan2/hypot 三角函数
sinh/cosh/tanh/asinh/acosh/atanh 双曲函数
ddt(x) 时间微分(电容建模等)
idt(x [,ic[,assert]]) 时间积分
limexp(x) 有限指数(收敛性好,二极管用)
transition(x, td, tr, tf) 边沿/延时滤波器(数字→模拟输出用)
slew(x, sr_p, sr_n) 摆率限制
absdelay(x, td) 绝对延时
laplace_nd/zp/zd/np(...) S 域滤波
zi_nd/zp/zd/np(...) Z 域滤波

输出与调试

$strobe("fmt", args);    // 打印+换行(%m = 实例名,%g = 实数)
$display("fmt", args);   // 同 strobe
$write("fmt", args);     // 不换行
$monitor("fmt", args);   // 变化才打印
$finish(code); $stop(code);

文件

$fopen/$fscanf/$fstrobe/$fdisplay/$fwrite/$fclose(详见 09 - VerilogA 仿真器函数)

随机数

$random(seed);分布:$rdist_normal(seed, mean, sdev)、$rdist_uniform(seed, a, b)、$rdist_poisson、$rdist_exponential、$rdist_chi_square、$rdist_t、$rdist_erlang;整数版为 $dist_*。

相关笔记