Verilog 構文の数学関数

        Verilog-2005 はいくつかの単純な数学関数をサポートしており、そのパラメータのデータ型は整数と実数のみです。

整数型演算関数

        $clog2 は 2 を底とする対数関数で、結果は切り上げられます。戻り値の一般的な形式は次のとおりです。

整数の結果;

結果 = $clog2(n);

        最も典型的なアプリケーションは、パラメータ化によって変数のビット幅を見つけることです.使用方法は、別の記事で詳しく紹介されています: Verilog デザインで変数のビット幅を一致させるには? ($clog2 システム関数)

実数型数学関数

        そのパラメーターのデータ型は実数型で、戻り値も実数型です。つまり、次の数学関数は合成できません。

関数 説明
$ln(x) N 自然対数 (基数 e の対数)
$log10(x) 十進対数 (10 を底とする対数)
exp(x) e^x ,e=2.718281828...
平方根(x) 平方根
$pow(x, y) x^y
$床(x) 切り捨て
$ceil(x) 切り上げ
$hypot(x, y) 平方根(xx + yy)。2 つの数値の平方根と平方根
$sin(x)
$cos(x) コス
$tan(x) 日焼け
$asin(x) アークサイン
$acos(x) アークコス
$atan(x) アークコス
$atan2(x, y) x/y のアークタンジェント
$誕生(x) 双曲線正弦
$cosh(x) 双曲線余弦
$tan(x) 双曲線正接
$asinh(x) 逆双曲線正弦
$acosh(x) 逆双曲線余弦
$atanh(x) 逆双曲線正接

        検証するための簡単なテストベンチを modelsim に記述します。

module tb_math_fuc;
	real x, y;		//这些函数的参数需要是real类型,返回也是real类型

initial begin		//0.3f表示取小数点后3位,下同
    x = 10000;$display("$log10(%0.3f) = %0.3f", x, $log10(x));				//以10为底的对数	
    x = 1;$display("$ln(%0.3f) = %0.3f", x, $ln(x));						//以e为底的对数
    x = 2;$display("$exp(%0.3f) = %0.3f", x, $exp(x));						//e^x
    x = 25;$display("$sqrt(%0.3f) = %0.3f", x, $sqrt(x));					//开平方
    x = 5;y = 3;$display("$pow(%0.3f, %0.3f) = %0.3f", x, y, $pow(x, y));	//x^y
    x = 2.7813;$display("$floor(%0.3f) = %0.3f", x, $floor(x));				//向下取整
    x = 7.1111;$display("$ceil(%0.3f) = %0.3f", x, $ceil(x));				//向上取整
	
    x = 30 * (22.0/7.0) / 180;$display("$sin(%0.3f) = %0.3f", x, $sin(x));	//sin函数
    x = 90 * (22.0/7.0) / 180;$display("$cos(%0.3f) = %0.3f", x, $cos(x));	//cos函数
    x = 45 * (22.0/7.0) / 180;$display("$tan(%0.3f) = %0.3f", x, $tan(x));	//tan函数
	
    x = 0.5;$display("$asin(%0.3f) = %0.3f rad, %0.3f deg", x, $asin(x), $asin(x) * 7.0/22.0 * 180);//arcsin函数
    x = 0;$display("$acos(%0.3f) = %0.3f rad, %0.3f deg", x, $acos(x), $acos(x) * 7.0/22.0 * 180);	//arccos函数
    x = 1;$display("$atan(%0.3f) = %0.3f rad, %f deg", x, $atan(x), $atan(x) * 7.0/22.0 * 180);		//arctan函数
	
end

endmodule

        以下が検証結果です。

おすすめ

転載: blog.csdn.net/wuzhikaidetb/article/details/128990633