Discussion:
fixed point syntax question
(too old to reply)
sanborne
2008-12-11 22:33:41 UTC
Permalink
I cannot figure out what the problem is in the following code:

-- begin code
library ieee_proposed;
use ieee_proposed.std_logic_1164_additions.all;
use ieee_proposed.math_utility_pkg.all;
use ieee_proposed.fixed_pkg.all;

library ieee;
use ieee.numeric_std.all;

entity test is

port (
a : in unsigned(31 downto 0);
x : out sfixed(1 downto -30));

end test;

architecture imp1 of test is
begin -- imp1
--the following works:
-- x <= resize(sfixed(a) * to_sfixed(0.5,0,-1), 1, -30);

--this does not...I need to be able to control the rounding and
overflow behavior
x <= resize(sfixed(a) * to_sfixed(0.5,0,-1), 1, -30, true, false);

end imp1;
-- end code

I expect that this is an easy problem, but the error the ModelSim
compiler gives is that there is no feasible subprogram "resize". The
syntax above is definitely in the documentation, and I have found some
examples online also. Any thoughts? Is it a problem with my conversion
from the unsigned input? But then why would the code that is commented
out compile? I would sure like to understand this.

SY
KJ
2008-12-11 23:14:08 UTC
Permalink
Post by sanborne
-- x <= resize(sfixed(a) * to_sfixed(0.5,0,-1), 1, -30);
--this does not...I need to be able to control the rounding and
overflow behavior
x <= resize(sfixed(a) * to_sfixed(0.5,0,-1), 1, -30, true, false);
The last two parameters to resize are not booleans. Your choices are

type fixed_round_style_type is (fixed_round, fixed_truncate);

type fixed_overflow_style_type is (fixed_saturate, fixed_wrap);

Kevin Jennings
David Bishop
2008-12-13 16:58:49 UTC
Permalink
Post by KJ
Post by sanborne
-- x <= resize(sfixed(a) * to_sfixed(0.5,0,-1), 1, -30);
--this does not...I need to be able to control the rounding and
overflow behavior
x <= resize(sfixed(a) * to_sfixed(0.5,0,-1), 1, -30, true, false);
The last two parameters to resize are not booleans. Your choices are
type fixed_round_style_type is (fixed_round, fixed_truncate);
type fixed_overflow_style_type is (fixed_saturate, fixed_wrap);
Exactly. The resize function looks like this:

function resize (
arg : UNRESOLVED_sfixed; -- input
constant left_index : INTEGER; -- integer portion
constant right_index : INTEGER; -- size of fraction
constant overflow_style : fixed_overflow_style_type :=
fixed_overflow_style;
constant round_style : fixed_round_style_type :=
fixed_round_style)
return UNRESOLVED_sfixed;

"fixed_overflow_style" defaults to "fixed_saturate", which I find very
useful in my designs.
"fixed_round_style" defaults to "fixed_round". I only use
"fixed_truncate" if I need some area savings.

So, what you want is:
x <= resize(
arg => sfixed(a) * to_sfixed(0.5,0,-1),
left_index => 1,
right_index => -30,
overflow_style => fixed_saturate,
round_style => fixed_truncate);

Continue reading on narkive:
Loading...