aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/issue1912/popcount.vhdl
blob: 174b50f5167ac85ebb1472406ee67b76eb37aec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

library work;
use work.all;

entity popcount is
	generic (
		SIZE  : natural := 32
	);
	port (
		-- Input data
		data : in std_logic_vector(SIZE-1 downto 0);
		-- Results
		num  : out std_logic
	);
end entity;

architecture synth of popcount is

	-- Component declaration of itself, for recursive instantiation

	component popcount is
		generic (
			SIZE  : natural := 32
		);
		port (
			-- Input data
			data : in std_logic_vector(SIZE-1 downto 0);
			-- Results
			num  : out std_logic
		);
	end component;

begin

	n5 : if SIZE <= 5 generate

		num <= '1';

	end generate;

	more : if SIZE >= 6 generate

		signal num_1 : std_logic;
		signal num_2 : std_logic;

		constant SIZE_LOWER : natural := 4 * (SIZE / 5);

	begin

		inst1 : popcount
			generic map (
				SIZE  => SIZE_LOWER
			)
			port map (
				data => data(SIZE_LOWER-1 downto 0),
				num  => num_1
			);

		inst2 : popcount
			generic map (
				SIZE  => SIZE - SIZE_LOWER
			)
			port map (
				data => data(SIZE-1 downto SIZE_LOWER),
				num  => num_2
			);

		num <= num_1 or num_2;

	end generate;

end architecture;