Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Latch inference is Quartus bug or specified VHDL behaviour?

Hello,

does anybody know, why Quartus infers latches for the below combinational function if we use an initial value expression for the variable definition of mirrored_data? I looks like a Quartus bug at first sight, because all output bits are actually defined, there's nothing to be latched.

The latches are generated for the function result. If you register y in the upper level, the problem disappears.

The problem is originated from this Edaboard discussion: http://www.edaboard.com/thread273938.html

Best regards,

Frank

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
ENTITY test IS
GENERIC (
size: integer :=7);
PORT (
  x: IN UNSIGNED( size DOWNTO 0);
  a: IN INTEGER RANGE 0 TO size;
  b: IN INTEGER RANGE 0 TO size;
  y : OUT UNSIGNED (size DOWNTO 0));
END;
ARCHITECTURE FLOW OF test IS
function mirror ( data : unsigned ; top : integer ; bottom : integer ) return unsigned is
-- Using an initial value expression in this place causes latch inference, why?
-- variable mirrored_data : unsigned ( data ' range ) := data;
variable mirrored_data : unsigned ( data ' range );
begin
   mirrored_data := data;
   for index in 0 to data ' length - 1 loop
      if (index <= top) and (index >= bottom) then
         mirrored_data ( index ) := data ( top - index + bottom ) ;
      end if ;
   end loop ;	
   return mirrored_data ;
end function mirror ;
BEGIN
y <= mirror ( x , a , b ) ;
END FLOW;

11 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I think it is safe to say it is a Quartus bug, but wouldn't bother to file an SR as the Altera gang will tell us to work-around it the way Kaz proposes. Which is not a problem to me, I never initialize a variable at the declaration, not even in C or C++ programs. I always initialise a variable just prior to the first use, to my idea it better documents what's going on.

    --- Quote End ---

    I would still file a SR so at least it's there for them to consider. But I also dont think they'll bother fixing it. Ive had several other VHDL SRs relating to imference of RAMs and full VHDL 2008 support that dont seem to get fixed. But they will only do them if people request them.