有符号乘法结果trim

Signed multiplication result trim

我有什么

我有两个 signed 信号,其中一个 10b 长度,另一个 2b 长度。

signal R_S_R      : signed(9 downto 0);
signal prbs_sup_u : signed(1 downto 0);

然后我想将它们相乘:

R_S_E <= R_S_R * prbs_sup_u;

将结果存储到另一个 10b 信号中。

为什么又10b

因为 prbs_sup_u 是 2b,它只有 [-1, 1] 值(只有这两个)。因此,虽然乘法的结果是 12b,但我认为(只要我没有弄错)我应该能够将运算的可能结果存储在另一个 10b 信号中。

所以你的问题是...

完成乘法后,我应该可以处理 12b 结果中的两位。

不过,哪些?因为是signed signal,不知道哪个是一次性的。当然不是第一个,因为它是标志,但之后...

只需使用 resize 操作来截断不需要的 MSB(幅度),例如:

R_S_E <= resize(R_S_R * prbs_sup_u, R_S_E'length);

您可以在 numeric_std.resize 中找到文档:

-- Id: R.1
function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED;
-- Result subtype: SIGNED(NEW_SIZE-1 downto 0)
-- Result: Resizes the SIGNED vector ARG to the specified size.
--         To create a larger vector, the new [leftmost] bit positions
--         are filled with the sign bit (ARG'LEFT). When truncating,
--         the sign bit is retained along with the rightmost part.

如果prbs_sup_u只能取值1或-1,那你也可以考虑:

if prbs_sup_u = 1 then
    R_S_E <= R_S_R;
else  -- prbs_sup_u = -1 
    R_S_E <= - R_S_R;
end if;

操作可能会更明显,并且电路会更小,因为实现不必包括处理未使用的 0 和 -2 值。