M
Marios Barlas
Guest
Hello,
I am facing a pretty wierd error as regards an operation which is pretty crutial for my code.
I am trying to do a left shift operation on an unsigned vector. My NBITS is defined generically as natural and my delta vector is unsigned. All compiles well but when iŕm doing the simulation my delta_shifted receives X values. for me that seems to suggest that the sll operation is not performed. Any1 has an idea as to where the problem could be ?
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
entity sqroot_comb is
generic (constant NBITS : natural := 8); --design implementation
port (
signal arg : in std_logic_vector(NBITS-1 downto 0);
signal roundup : in std_logic := '0'; --determine if roundup is done or not
signal sqroot : out std_logic_vector(NBITS/2 downto 0));
end entity sqroot_comb;
architecture rtl of sqroot_comb is
use ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
--Internal signal definitions
signal delta : unsigned(NBITS-1 downto 0);
signal delta_shifted : unsigned(NBITS-1 downto 0);
signal delta_shifted_prev : unsigned(NBITS-1 downto 0);
signal res : unsigned(NBITS-1 downto 0);
signal res_prev : unsigned(NBITS-1 downto 0);
signal sqroot_temp_prev : unsigned(NBITS-1 downto 0);
signal sqroot_temp : unsigned(NBITS-1 downto 0);
--Signal Assignments
begin
delta <= to_unsigned(2**(NBITS-2),delta'length);
sqroot_temp <= to_unsigned(0,delta'length);
sqroot_temp_prev <= to_unsigned(0,delta'length);
delta_shifted_prev <= to_unsigned(0,delta'length);
res_prev <= to_unsigned(0,delta'length);
delta_shifted <= (delta sll NBITS-2); -- shifted // temp = delta^(NBITS-2)
res <= unsigned(arg);
process( arg, roundup )
--Internal variable definitions
--variable delta_int : integer := 1;
--variable sqroot_int : integer :=0;
--variable res_int : integer := to_integer(unsigned(arg));
begin
for i in 0 to 2*NBITS-1 loop
if (delta_shifted >= 1) then
if ( (sqroot_temp + delta_shifted) <= res ) then
res <= res -(sqroot_temp + delta_shifted);
sqroot_temp <= sqroot_temp + 2*delta_shifted;
else
sqroot_temp <= sqroot_temp_prev;
res <= res_prev;
delta_shifted <= delta_shifted_prev;
end if;
end if;
sqroot_temp <= sqroot_temp/2;
delta_shifted <= delta_shifted/4;
--Update previous values of sqroot and residual
sqroot_temp_prev <= sqroot_temp;
res_prev <= res;
end loop;
if ( (roundup = '1') and (res > sqroot_temp) ) then
sqroot_temp <= sqroot_temp + 1;
else
sqroot_temp <= sqroot_temp_prev;
end if;
sqroot <= std_logic_vector(resize( sqroot_temp,sqroot'length ));
end process;
end architecture rtl;
I am facing a pretty wierd error as regards an operation which is pretty crutial for my code.
I am trying to do a left shift operation on an unsigned vector. My NBITS is defined generically as natural and my delta vector is unsigned. All compiles well but when iŕm doing the simulation my delta_shifted receives X values. for me that seems to suggest that the sll operation is not performed. Any1 has an idea as to where the problem could be ?
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
entity sqroot_comb is
generic (constant NBITS : natural := 8); --design implementation
port (
signal arg : in std_logic_vector(NBITS-1 downto 0);
signal roundup : in std_logic := '0'; --determine if roundup is done or not
signal sqroot : out std_logic_vector(NBITS/2 downto 0));
end entity sqroot_comb;
architecture rtl of sqroot_comb is
use ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
--Internal signal definitions
signal delta : unsigned(NBITS-1 downto 0);
signal delta_shifted : unsigned(NBITS-1 downto 0);
signal delta_shifted_prev : unsigned(NBITS-1 downto 0);
signal res : unsigned(NBITS-1 downto 0);
signal res_prev : unsigned(NBITS-1 downto 0);
signal sqroot_temp_prev : unsigned(NBITS-1 downto 0);
signal sqroot_temp : unsigned(NBITS-1 downto 0);
--Signal Assignments
begin
delta <= to_unsigned(2**(NBITS-2),delta'length);
sqroot_temp <= to_unsigned(0,delta'length);
sqroot_temp_prev <= to_unsigned(0,delta'length);
delta_shifted_prev <= to_unsigned(0,delta'length);
res_prev <= to_unsigned(0,delta'length);
delta_shifted <= (delta sll NBITS-2); -- shifted // temp = delta^(NBITS-2)
res <= unsigned(arg);
process( arg, roundup )
--Internal variable definitions
--variable delta_int : integer := 1;
--variable sqroot_int : integer :=0;
--variable res_int : integer := to_integer(unsigned(arg));
begin
for i in 0 to 2*NBITS-1 loop
if (delta_shifted >= 1) then
if ( (sqroot_temp + delta_shifted) <= res ) then
res <= res -(sqroot_temp + delta_shifted);
sqroot_temp <= sqroot_temp + 2*delta_shifted;
else
sqroot_temp <= sqroot_temp_prev;
res <= res_prev;
delta_shifted <= delta_shifted_prev;
end if;
end if;
sqroot_temp <= sqroot_temp/2;
delta_shifted <= delta_shifted/4;
--Update previous values of sqroot and residual
sqroot_temp_prev <= sqroot_temp;
res_prev <= res;
end loop;
if ( (roundup = '1') and (res > sqroot_temp) ) then
sqroot_temp <= sqroot_temp + 1;
else
sqroot_temp <= sqroot_temp_prev;
end if;
sqroot <= std_logic_vector(resize( sqroot_temp,sqroot'length ));
end process;
end architecture rtl;