Altera_Forum
Honored Contributor
13 years agoincorrect variables synthesis or expected behavior for simple adder function
Sorry if this is redundant or stupid, I was not able to find similar question on the forum or even Google.
Actually, Google yielded some thread where the below code is quoted as a valid example of variables use for synthesis. Given very simple VHDL code: =========================================== library ieee; use ieee.std_logic_1164.all; entity toplevel is port ( a,b : in std_logic_vector(3 downto 0); c,d : out std_logic_vector(3 downto 0) ); end entity; architecture rtl of toplevel is function plus_s_s (a,b : std_logic_vector) return std_logic_vector is variable s: std_logic_vector(a'range); variable carry: std_logic; begin carry := '0'; for i in a'low to a'high loop s(i) := (a(i) xor b(i)) xor carry; carry := ((a(i) or b(i)) and carry ) or (a(i) and b(i)); end loop; return s; end; begin c <= plus_s_s(a,B"0001"); d <= plus_s_s(a,b); end rtl; =========================================== Results in proper "hand-made" adder for d output, but for c output, instead of generating logic to increment a input, it generates c <= a I'm attaching RTL view and this .vhdl this happens on Quartus 12.1 build 177 for Linux, using Cyclone V device EP4CE115F29C7 Thank you for any help on insights. V.L.