(VHDL)存储为std_logic_vectors的IEEE 754编码浮点值的算术运算

时间:2012-09-03 13:54:02

标签: floating-point vhdl

我需要对存储为std_logic_vector信号的IEEE 754浮点数进行操作。

e.g:

signal a, b, ans : std_logic_vector( 63 downto 0 );
..
ans <= std_logic_vector(to_float(a) + to_float(b));

我该怎么做? (我想我需要在转换过程中的某个位置定义位数?) 编辑:代码是可综合的,但我收到警告。代码:

variable tempfloat1, tempfloat2, tempfloat3 : float32;
..
tempfloat1 := to_float(s_do_ssc2wb, exponent_width => 8, fraction_width => 23 );
tempfloat2 := to_float(s_do_wb2ssc, exponent_width => 8, fraction_width => 23 );
tempfloat3 := tempfloat1 + tempfloat2;

警告:

 "float_pkg_c.vhdl" line 1515: VHDL Assertion Statement with non constant condition is ignored.
    "float_pkg_c.vhdl" line 1600: Index value(s) does not match array range, simulation mismatch.

我想知道它的正确语法是什么......“添加”功能不接受用户指南中示例中的参数。

2 个答案:

答案 0 :(得分:4)

对于VHDL 2008,使用内置的float_pkg,它提供可以转换为std_logic_vector和从std_logic_vector转换的float类型。对于早期版本的VHDL,您可以使用http://www.vhdl.org/fphdl/index.html中这些相同软件包的原始预标准版本。

使用float类型时,它们非常直接,类似于无符号类型:你可以对它们进行算术运算,调整它们等等。

答案 1 :(得分:1)

最后,我使用了ISE中IP核生成器生成的浮点IP核。上面链接的浮点包实际上没有价值,因为合成花了一个小时,Spartan3的最大频率只有~6 MHZ。使用IP核:40 MHz和3-5分钟的合成时间。