我正在尝试在我正在编写的模块中实现 shift_left() 函数,以对两个 32 位浮点数求和。我无法调用函数来停止生成红色波浪线。
请注意,这段代码不是最终的,我专注于让 vivado/vhdl 能够接受我对 shift_left() 的调用,然后再继续。我开始将变量 eshift 声明为整数,但在查找库后,它需要是自然变量,但将变量声明为自然变量并不会对其进行排序..它表示 std_logic_vector 的期望,但将 manB 转换为无符号或本身并不能解决这个问题..是否像我写入的向量应该更大以允许移位?我也知道连接零是被建议为最简单的方法,但这似乎是如果我知道我想提前进行多少次逻辑转换。对此的见解非常受欢迎,我正在使用 C 语言解决问题的所有课程,但有关 VHDL 的某些内容似乎很困难。谢谢!
--function to sum
function floatSum(A_in, B_in: std_logic_vector(31 downto 0)) return std_logic_vector is
variable sum : std_logic_vector(31 downto 0);
variable expA, expB : integer;
variable eshift : natural;
variable manA, manB, manNew : std_logic_vector(22 downto 0);
variable newExp : std_logic_vector(7 downto 0);
begin
expA := conv_integer(A_in(30 downto 23)) - 127;
expB := conv_integer(B_in(30 downto 23)) - 127;
manA := A_in(22 downto 0);
manB := B_in(22 downto 0);
--tests for exponent cases and shifts the exponents accordingly
if expA = expB then
eShift := 0;
manNew := manA + manB;
elsif expA > expB then
eShift := expA - expB;
sum(30 downto 23) := A_in(30 downto 23);
--issue is here
**manNew := shift_left(unsigned(manB), eShift);**
else
eShift := expB - expA;
end if;
return(sum);
end floatSum;
第一次海报堆满溢出..
更新:检查了这个答案并强制转换 shift_left 调用只是让它对多个 use 子句感到愤怒,而删除未签名的强制转换让它抱怨更多的事情。 https://stackoverflow.com/questions/66832409/no-feasible-entry-to-subprogram-shift-left-type-error-near
请提供有关 VHDL shift_left() 函数的帮助。
std_logic_arith 和 numeric_std 都提供有符号和无符号类型。包含这两个包将使这些类型不可见并且需要直接引用。我建议删除非标准 std_logic_arith 包并仅使用 numeric_std – Tricky
删除 std_logic_arith 库解决了我的问题。