K
Ken Cecka
I'm playing around with different ways to count the number of '1' bits in a vector. I'll only be dealing with 6 bit vectors, so I could just do this with a lookup table, but I started with the most readable implementation to see how it would synthesize (copied below).
The Xilinx tools are synthesizing this into a single counter with a feedback loop, and then telling me me that the design can run at 700MHz. I'm a little skeptical - anyone know if it's reasonable to expect timing analysis to unroll a feedback loop like this?
Ken
ENTITY test IS
GENERIC
(
bits : INTEGER := 6
);
PORT
(
reset : IN STD_LOGIC;
clk : IN STD_LOGIC;
input : IN STD_LOGIC_VECTOR((bits - 1) DOWNTO 0);
ones : OUT STD_LOGIC_VECTOR(log2(bits) DOWNTO 0)
);
END test;
ARCHITECTURE model OF test IS
SIGNAL input_l : STD_LOGIC_VECTOR(input'RANGE);
SIGNAL count : STD_LOGIC_VECTOR(ones'RANGE);
BEGIN
-- latch inputs and outputs for timing analysis
PROCESS (reset, clk)
BEGIN
IF (reset = '1') THEN
input_l <= (OTHERS => '0');
ones <= (OTHERS => '0');
ELSIF (clk'EVENT) AND (clk = '1') THEN
input_l <= input;
ones <= count;
END IF;
END PROCESS;
-- count ones
PROCESS (input_l, count)
BEGIN
FOR i IN input_l'RANGE LOOP
IF (input_l(i) = '1') THEN
count <= count + 1;
END IF;
END LOOP;
END PROCESS;
END;
The Xilinx tools are synthesizing this into a single counter with a feedback loop, and then telling me me that the design can run at 700MHz. I'm a little skeptical - anyone know if it's reasonable to expect timing analysis to unroll a feedback loop like this?
Ken
ENTITY test IS
GENERIC
(
bits : INTEGER := 6
);
PORT
(
reset : IN STD_LOGIC;
clk : IN STD_LOGIC;
input : IN STD_LOGIC_VECTOR((bits - 1) DOWNTO 0);
ones : OUT STD_LOGIC_VECTOR(log2(bits) DOWNTO 0)
);
END test;
ARCHITECTURE model OF test IS
SIGNAL input_l : STD_LOGIC_VECTOR(input'RANGE);
SIGNAL count : STD_LOGIC_VECTOR(ones'RANGE);
BEGIN
-- latch inputs and outputs for timing analysis
PROCESS (reset, clk)
BEGIN
IF (reset = '1') THEN
input_l <= (OTHERS => '0');
ones <= (OTHERS => '0');
ELSIF (clk'EVENT) AND (clk = '1') THEN
input_l <= input;
ones <= count;
END IF;
END PROCESS;
-- count ones
PROCESS (input_l, count)
BEGIN
FOR i IN input_l'RANGE LOOP
IF (input_l(i) = '1') THEN
count <= count + 1;
END IF;
END LOOP;
END PROCESS;
END;