On 27 Apr, 08:43, Peter <peter.hermans...@sts.saab.se> wrote:
> I was surprised by how the resize function works. My intention was to
> substract two 32-bit signals (std_logic_vectors, but representing 2-
> complement numbers) and decrease the signal width from 32 bits to 14.
> The code below does not work:
>
> daout <= std_logic_vector( resize((signed(tx_mix_i) - signed
> (tx_mix_q)),14) );
>
> But this code does:
>
> idaout <= std_logic_vector( signed(tx_mix_i) - signed(tx_mix_q) );
> daout <= idaout(31 downto 1
;
>
> I seems as the rezise function selects the 14 lowest bits in the
> argument instead of the 14 highest.
>
> Any comments?
>
> /Peter
As to exactly why, Im sure someone knows better, but thats exactly
what it says in the package in the comments/documentation (as the
comments are pretty much the only docs on the package afaik).
-- Id: R.1
function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED;
attribute builtin_subprogram of
RESIZE[SIGNED, NATURAL return SIGNED]: function is
"numstd_resize_sns";
-- 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.
This implies that if you declare your signed value as s(0 to n)
instead of downto, you will get the desired outcome (and looking at
the actual function, it uses the 'left attribute rather than 'high
when taking the return value).