K
Kausi
Iam struggling with a piece of code that has been giving me sleepless
nights for the past one week. What i fail to understand is that the
code works absolutely fine, without even a glitch in modelsim. But
when i burn the code on an fpga (spartan-3), i get weird results. Find
the snipet of my code below.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Non_restoring_float_sqrt is
Port ( Float_Input_IEEE_Format: in bit_vector(31 downto 0);
Result: out bit_vector(31 downto 0);
reset: in bit;
CLK: in bit);
end Non_restoring_float_sqrt;
architecture Behavioral of Non_restoring_float_sqrt is
type dstate is range 24 downto 0;
signal state : dstate;
signal result_temp : bit_vector(8 downto 0);
signal Shift_Reg: bit_vector(23 downto 0);
begin
process(Float_Input_IEEE_Format,reset)
variable A_exponent: bit_vector(7 downto 0);
constant B_exponent: bit_vector(7 downto 0):="00111111";
variable Float_Local_exponent: bit_vector(7 downto 0);
variable Float_Local_fraction: bit_vector(22 downto 0);
variable Sum_Temp_variable: bit_vector(8 downto 0);
variable Sign_bit: bit;
begin
if reset='1' and reset'event then
Sign_bit:=Float_Input_IEEE_Format(31);
Float_Local_exponent := Float_Input_IEEE_Format(30 downto 23);
Float_Local_fraction := Float_Input_IEEE_Format(22 downto 0);
A_exponent:= '0' & Float_Local_exponent(7 downto 1);
-- I have not pasted the function to reduce the length.
Sum_Temp_variable:=Adder_for_exponent(A_exponent,B_exponent,Float_Local_exponent(0));
result_temp(8 downto 0)<= Sign_bit & Sum_Temp_variable(7 downto 0);
if Float_Local_exponent(0)= '0' then
Shift_Reg<='1' & Float_Local_fraction(22 downto 0);
else
Shift_Reg<= "01" & Float_Local_fraction(22 downto 1);
end if;
else null;
end if;
end process;
process(Shift_Reg,state)
variable r0: bit_vector(1 downto 0);
variable r2: bit_vector(23 downto 0);
variable c_temp,control: bit;
variable A,B: bit_vector(23 downto 0);
variable r : bit_vector(23 downto 0);
variable sh : bit_vector(23 downto 0);
variable d_sub : bit_vector(23 downto 0);
begin
case state is
when 23 =>
d_sub:=Shift_Reg;
A:="000000000000000000000000";
B:="000000000000000000000000";
sh:="000000000000000000000000";
c_temp:=d_sub(23) or d_sub(22);
r2:="000000000000000000000000";
r0(0):= not d_sub(22);
r0(1):= d_sub(23) xnor d_sub(22);
control:=r2(23);
r2:=addsub(A,B,c_temp,control);
sh:=sh(22 downto 0)& (not r2(23));
r:=r2(21 downto 0)& r0(1 downto 0);
d_sub:=d_sub(21 downto 0)& "00";
when 22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1 =>
c_temp:=d_sub(23) or d_sub(22);
r0(0):= not d_sub(22);
r0(1):= d_sub(23) xnor d_sub(22);
B:=sh;
A:=r;
control:=r2(23);
r2:=addsub(A,B,c_temp,control);
sh:=sh(22 downto 0)& (not r2(23));
r:=r2(21 downto 0)& r0(1 downto 0);
d_sub:=d_sub(21 downto 0)& "00";
when 0 =>
c_temp:=d_sub(23) or d_sub(22);
r0(0):= not d_sub(22);
r0(1):= d_sub(23) xnor d_sub(22);
B:=sh;
A:=r;
control:=r2(23);
r2:=addsub(A,B,c_temp,control);
sh:=sh(22 downto 0)& (not r2(23));
r:=r2(21 downto 0)& r0(1 downto 0);
d_sub:=d_sub(21 downto 0)& "00";
Result(31 downto 0)<=result_temp( 8 downto 0) & sh(23 downto 1);
when others=> null;
end case;
end process;
process(CLK,reset)
begin
if(CLK='1' and CLK'event and reset='1' ) then
if state/=0 then
state<=state-1;
else
state<=23;
end if;
end if;
end process;
end Behavioral;
The value of "Result" which is reflected by modelsim is as expected
for all possible combinations of input. Somehow after burning the code
on d fpga, it gives a weird output.
I do get some warnings when i synthesize, which i otherwise ignore.
The warnings are as below-
1. <r2> is unconnected in block <non_restoring_float_sqrt>.
2. Found 24-bit latch for signal <d_sub>.
Found 24-bit latch for signal <r>.
Found 24-bit latch for signal <sh>.
Found 24-bit latch for signal <r2>.
***************************************************************************************************
Any sort of help would be appreciated.
nights for the past one week. What i fail to understand is that the
code works absolutely fine, without even a glitch in modelsim. But
when i burn the code on an fpga (spartan-3), i get weird results. Find
the snipet of my code below.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Non_restoring_float_sqrt is
Port ( Float_Input_IEEE_Format: in bit_vector(31 downto 0);
Result: out bit_vector(31 downto 0);
reset: in bit;
CLK: in bit);
end Non_restoring_float_sqrt;
architecture Behavioral of Non_restoring_float_sqrt is
type dstate is range 24 downto 0;
signal state : dstate;
signal result_temp : bit_vector(8 downto 0);
signal Shift_Reg: bit_vector(23 downto 0);
begin
process(Float_Input_IEEE_Format,reset)
variable A_exponent: bit_vector(7 downto 0);
constant B_exponent: bit_vector(7 downto 0):="00111111";
variable Float_Local_exponent: bit_vector(7 downto 0);
variable Float_Local_fraction: bit_vector(22 downto 0);
variable Sum_Temp_variable: bit_vector(8 downto 0);
variable Sign_bit: bit;
begin
if reset='1' and reset'event then
Sign_bit:=Float_Input_IEEE_Format(31);
Float_Local_exponent := Float_Input_IEEE_Format(30 downto 23);
Float_Local_fraction := Float_Input_IEEE_Format(22 downto 0);
A_exponent:= '0' & Float_Local_exponent(7 downto 1);
-- I have not pasted the function to reduce the length.
Sum_Temp_variable:=Adder_for_exponent(A_exponent,B_exponent,Float_Local_exponent(0));
result_temp(8 downto 0)<= Sign_bit & Sum_Temp_variable(7 downto 0);
if Float_Local_exponent(0)= '0' then
Shift_Reg<='1' & Float_Local_fraction(22 downto 0);
else
Shift_Reg<= "01" & Float_Local_fraction(22 downto 1);
end if;
else null;
end if;
end process;
process(Shift_Reg,state)
variable r0: bit_vector(1 downto 0);
variable r2: bit_vector(23 downto 0);
variable c_temp,control: bit;
variable A,B: bit_vector(23 downto 0);
variable r : bit_vector(23 downto 0);
variable sh : bit_vector(23 downto 0);
variable d_sub : bit_vector(23 downto 0);
begin
case state is
when 23 =>
d_sub:=Shift_Reg;
A:="000000000000000000000000";
B:="000000000000000000000000";
sh:="000000000000000000000000";
c_temp:=d_sub(23) or d_sub(22);
r2:="000000000000000000000000";
r0(0):= not d_sub(22);
r0(1):= d_sub(23) xnor d_sub(22);
control:=r2(23);
r2:=addsub(A,B,c_temp,control);
sh:=sh(22 downto 0)& (not r2(23));
r:=r2(21 downto 0)& r0(1 downto 0);
d_sub:=d_sub(21 downto 0)& "00";
when 22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1 =>
c_temp:=d_sub(23) or d_sub(22);
r0(0):= not d_sub(22);
r0(1):= d_sub(23) xnor d_sub(22);
B:=sh;
A:=r;
control:=r2(23);
r2:=addsub(A,B,c_temp,control);
sh:=sh(22 downto 0)& (not r2(23));
r:=r2(21 downto 0)& r0(1 downto 0);
d_sub:=d_sub(21 downto 0)& "00";
when 0 =>
c_temp:=d_sub(23) or d_sub(22);
r0(0):= not d_sub(22);
r0(1):= d_sub(23) xnor d_sub(22);
B:=sh;
A:=r;
control:=r2(23);
r2:=addsub(A,B,c_temp,control);
sh:=sh(22 downto 0)& (not r2(23));
r:=r2(21 downto 0)& r0(1 downto 0);
d_sub:=d_sub(21 downto 0)& "00";
Result(31 downto 0)<=result_temp( 8 downto 0) & sh(23 downto 1);
when others=> null;
end case;
end process;
process(CLK,reset)
begin
if(CLK='1' and CLK'event and reset='1' ) then
if state/=0 then
state<=state-1;
else
state<=23;
end if;
end if;
end process;
end Behavioral;
The value of "Result" which is reflected by modelsim is as expected
for all possible combinations of input. Somehow after burning the code
on d fpga, it gives a weird output.
I do get some warnings when i synthesize, which i otherwise ignore.
The warnings are as below-
1. <r2> is unconnected in block <non_restoring_float_sqrt>.
2. Found 24-bit latch for signal <d_sub>.
Found 24-bit latch for signal <r>.
Found 24-bit latch for signal <sh>.
Found 24-bit latch for signal <r2>.
***************************************************************************************************
Any sort of help would be appreciated.