Forum Discussion
Altera_Forum
Honored Contributor
14 years agoVHDL integer causing RTL and Gate level simulation difference
I have a general question regarding the use of integers in VHDL.
If I have a lot of Array defined, we have to use integer as its index when accessing the arrays. However, when the index is converted from std_logic_vectors, it masked away the 'X' values, which masked my signal initiailization problem. Can anybody please let me know how to avoid this problem? When running simulation, I have the following warning: # ** Warning: NUMERIC_STD.TO_INTEGER: metavalue deteced, returning 0 The code example is below: SIGNAL a : ARRAY (INTEGER 0 TO 15) of STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL b : STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL c : STD_LOGIC_VECTOR(5 DOWNTO 0); c <= a(TO_INTEGER(UNSIGNED(b));15 Replies
- Altera_Forum
Honored Contributor
I am talking about ASICs.
- Altera_Forum
Honored Contributor
Anybody know how to avoid INTEGERs when access arrays? I really this can mask out a lot of bugs during simulations because it doesn't allow 'X'.
Unless we make sure there is no 'X' exist in our design, this is always a risk to use. - Altera_Forum
Honored Contributor
'X' values in gate level simulation are really indicating undetermined values, e.g. due to a timing violation. That's not a problem of using integers, it's in the hardware.
- Altera_Forum
Honored Contributor
--- Quote Start --- Anybody know how to avoid INTEGERs when access arrays? --- Quote End --- Use conversion operators that output an integer. For example;
Or as Tricky comments, define a range restricted integer for rddata_sel. However, as you note, you cannot see an 'X' in that case, so using std_logic is a little more general. Cheers, Davetype rddata_mux_t is array (0 to 7) of std_logic_vector(31 downto 0); signal rddata_mux : rddata_mux_t; signal rddata_sel : std_logic_vector(2 downto 0); rddata_mux(0) <= .... rddata_mux(1) <= .... rddata <= rddata_mux(to_integer(unsigned(rddata_sel))); - Altera_Forum
Honored Contributor
zhujianbinc,
you can't avoid using integers to access arrays. That said, that kind of RTL vs post-synthesis inconsistency is in no way limited to use of integers. In fact, at least when you're using integers you get warnings like those from the RTL simulation. Other cases may be dead silent.
Consider than a, b, c and d are all std_logic and think of how the code behaves when b = 1', c = 'X' and d = '0' . In RTL, a will be '0'; in post-synthesis it will be 'X'. Anyway, you can try and make RTL and post-synthesis simulations match better by coding the handling of "X" explicitly when needed. For example, replacea <= b when c = '0' else d;
withc <= a(TO_INTEGER(UNSIGNED(b));
It will synthesize the same, but you'll get XX when b has an X. PS: This is an Altera forum, people assume you're talking about (Altera) FPGAs here. If you're going to ask about something else, please start by making it crystal clear.c <= a(TO_INTEGER(UNSIGNED(b)) when not is_x(b) else (others => 'X');