While debugging the handling of custom physical types in Vivado ( read more ), I found a different behavior for converting types from real to integer.
Here is my sample code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.MATH_REAL.all;
entity Top_PhysicalTest_Simple is
port (
Clock : in STD_LOGIC;
Input : in STD_LOGIC;
Output : out STD_LOGIC
);
end;
architecture top of Top_PhysicalTest_Simple is
constant int_1 : INTEGER := natural(0.5);
constant int_2 : INTEGER := integer(-0.5);
-- constant int_2 : INTEGER := natural(-0.5);
begin
assert FALSE report "16 - int_1 (natural(0.5)): " & INTEGER'image(int_1) severity note;
assert FALSE report "17 - int_2 (natural(-0.5)): " & INTEGER'image(int_2) severity note;
Output <= Input when rising_edge(Clock);
end;
A mannequin-flip-flop is used so that some instruments do not complain about an empty structure.
XST 14.7:
Elaborating entity <Top_PhysicalTest_Simple> (architecture <top>) from library <work>.
Note: "16 - int_1 (natural(0.5)): 1"
Note: "17 - int_2 (natural(-0.5)): 0"
XST seems to use round up mode, and it handles checking the range of inclusions of the type. So I have to use integer(-0.5)instead natural(-0.5).
Vivado 2014.4:
[Synth 8-63] RTL assertion: "16 - int_1 (natural(0.5)): 1" ["D:/Temp/PhysicalTest_Vivado2014.4/vhdl/Top_PhysicalTest_Simple.vhdl":80]
[Synth 8-63] RTL assertion: "17 - int_2 (natural(-0.5)): -1" ["D:/Temp/PhysicalTest_Vivado2014.4/vhdl/Top_PhysicalTest_Simple.vhdl":81]
Synth, , round to . , , natural(..) integer(..).
: constant int_2 : INTEGER := natural(-0.5); .
GHDL 0.29:
GHDL 0.29 natural(..).
, , , 0,31, , .
GHDL 0.31:
. GHDL , :
Top_PhysicalTest_Simple.vhdl: 29: 14: std_logic_1164.v93
: