A
arubin
Guest
Hello All,
Let's start with a simple problem: Given a buffer of "Buf_Depth"
elements (let's say they are unsigned vectors with "Data_Width" number
of bits), find the minimum element in the buffer.
Our first solution is straightforward:
-----------------------
PROCESS
VARIABLE min : UNSIGNED(Data_Width-1 DOWNTO 0);
BEGIN
min := Data_Buf(0);
FOR i IN 1 TO Buf_Depth-1 LOOP
IF (Data_Buf(i) < min) THEN
min := Data_Buf(i)
END IF;
END LOOP;
FinalResult <= min;
END PROCESS;
--------------------------
The nice thing about this solution is that it will work for any value
"Buf_Depth". Everything seems great until we look at the timing
analysis (after synthesis). This design is painfully slow.
To get better performance, we can speed up the design with some
pipelining. Setting "Buf_Depth" = 4, we get:
-----------------------
SIGNAL pipeA, pipeB : UNSIGNED(Data_Width-1 DOWNTO 0);
PROCESS(Clk)
BEGIN
IF (rising_edge(Clk)) THEN
IF (Data_Buf(0) < Data_Buf(1)) THEN
pipeA <= Data_Buf(0);
ELSE
pipeA <= Data_Buf(1);
END IF;
IF (Data_Buf(2) < Data_Buf(3)) THEN
pipeB <= Data_Buf(2);
ELSE
pipeB <= Data_Buf(3);
END IF;
IF (pipeA < pipeB) THEN
FinalResult <= pipeA;
ELSE
FinalResult <= pipeB;
END IF;
END IF;
END PROCESS;
-----------------------
This solution (after synthesis) is very fast, but Buf_Depth is hard
coded to '4' - ie it is not a generic solution.
So here is my question: How can I code up a VHDL block similar to
the pipelined solution that can be instantiated for any value of
Buff_Depth?
Thanks,
Amir
Let's start with a simple problem: Given a buffer of "Buf_Depth"
elements (let's say they are unsigned vectors with "Data_Width" number
of bits), find the minimum element in the buffer.
Our first solution is straightforward:
-----------------------
PROCESS
VARIABLE min : UNSIGNED(Data_Width-1 DOWNTO 0);
BEGIN
min := Data_Buf(0);
FOR i IN 1 TO Buf_Depth-1 LOOP
IF (Data_Buf(i) < min) THEN
min := Data_Buf(i)
END IF;
END LOOP;
FinalResult <= min;
END PROCESS;
--------------------------
The nice thing about this solution is that it will work for any value
"Buf_Depth". Everything seems great until we look at the timing
analysis (after synthesis). This design is painfully slow.
To get better performance, we can speed up the design with some
pipelining. Setting "Buf_Depth" = 4, we get:
-----------------------
SIGNAL pipeA, pipeB : UNSIGNED(Data_Width-1 DOWNTO 0);
PROCESS(Clk)
BEGIN
IF (rising_edge(Clk)) THEN
IF (Data_Buf(0) < Data_Buf(1)) THEN
pipeA <= Data_Buf(0);
ELSE
pipeA <= Data_Buf(1);
END IF;
IF (Data_Buf(2) < Data_Buf(3)) THEN
pipeB <= Data_Buf(2);
ELSE
pipeB <= Data_Buf(3);
END IF;
IF (pipeA < pipeB) THEN
FinalResult <= pipeA;
ELSE
FinalResult <= pipeB;
END IF;
END IF;
END PROCESS;
-----------------------
This solution (after synthesis) is very fast, but Buf_Depth is hard
coded to '4' - ie it is not a generic solution.
So here is my question: How can I code up a VHDL block similar to
the pipelined solution that can be instantiated for any value of
Buff_Depth?
Thanks,
Amir