floating point result is wrong

Guest #7006031
Rate this post
• ▲ useful
▼ not useful
Hello friends, the result of floating point multiplication on hardware 
is wrong. Although it is correct in the simulation, it is wrong when I 
upload it on Cmod A7.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
use work.float_pkg.all;

entity test_block is
    Port (
        data_in : in std_logic_vector (31 downto 0);
        data_out : out std_logic_vector (31 downto 0)
    );
end test_block;

architecture Behavioral of test_block is
    constant adc_coef : real := 0.000000298023223876953125;
begin
    data_out <= to_slv(to_float(signed(data_in))*adc_coef);
end Behavioral;

I am multiplying the hexadecimal number x"000727AC" (decimal 468908) by 
0.000000298023223876953125. The result should be 0x3e0f1970 (float 
0.139745) as a single precision floating point. It turns out right in 
the simulation.

However, when I upload it on the card, the integrated logic analyzer 
shows as 0x34a8f197 (float 0.000000314682182).

The result that is correct in the simulation is wrong on the hardware. I 
tried to multiply with different numbers, the result is the same wrong. 
Why such wrong results?
Attached files:
Guest #7006291
Rate this post
• ▲ useful
▼ not useful
You can't implement an FP multiplication in real hardware just by 
writing "*" as for integer. FP mult is much more complex and the 
synthesis tool does not generate a hardware for that automatically. 
Remember that you need to multiply the mantissas, add the exponents, 
normalize if required, handle special cases like NaN etc. You will have 
to instantiate an FP multiplier core explicitely.

Did you have a look into the logfiles? There should also be an 
approriate warning about that.

VHDL makes hardware design easy, but not that easy...

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.