2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
9 rs : in std_ulogic_vector(63 downto 0);
10 count_right : in std_ulogic;
11 is_32bit : in std_ulogic;
12 result : out std_ulogic_vector(63 downto 0)
14 end entity zero_counter;
16 architecture behaviour of zero_counter is
18 zerocounter0: process(all)
19 variable l32, r32 : std_ulogic;
20 variable v32 : std_ulogic_vector(31 downto 0);
21 variable v16 : std_ulogic_vector(15 downto 0);
22 variable v8 : std_ulogic_vector(7 downto 0);
23 variable v4 : std_ulogic_vector(3 downto 0);
24 variable sel : std_ulogic_vector(5 downto 0);
28 v32 := (others => '0');
29 v16 := (others => '0');
30 v8 := (others => '0');
31 v4 := (others => '0');
32 sel := (others => '0');
34 l32 := or (rs(63 downto 32));
35 r32 := or (rs(31 downto 0));
36 if (l32 = '0' or is_32bit = '1') and r32 = '0' then
37 -- operand is zero, return 32 for 32-bit, else 64
38 result <= x"00000000000000" & '0' & not is_32bit & is_32bit & "00000";
41 if count_right = '0' then
42 sel(5) := l32 and (not is_32bit);
44 sel(5) := (not r32) and (not is_32bit);
47 v32 := rs(63 downto 32);
49 v32 := rs(31 downto 0);
52 if count_right = '0' then
53 sel(4) := or (v32(31 downto 16));
55 sel(4) := not (or (v32(15 downto 0)));
58 v16 := v32(31 downto 16);
60 v16 := v32(15 downto 0);
63 if count_right = '0' then
64 sel(3) := or (v16(15 downto 8));
66 sel(3) := not (or (v16(7 downto 0)));
69 v8 := v16(15 downto 8);
71 v8 := v16(7 downto 0);
74 if count_right = '0' then
75 sel(2) := or (v8(7 downto 4));
77 sel(2) := not (or (v8(3 downto 0)));
85 if count_right = '0' then
87 sel(1 downto 0) := "11";
88 elsif v4(2) = '1' then
89 sel(1 downto 0) := "10";
90 elsif v4(1) = '1' then
91 sel(1 downto 0) := "01";
93 sel(1 downto 0) := "00";
95 result <= x"00000000000000" & "00" & (not sel(5) and not is_32bit) & not sel(4 downto 0);
98 sel(1 downto 0) := "00";
99 elsif v4(1) = '1' then
100 sel(1 downto 0) := "01";
101 elsif v4(2) = '1' then
102 sel(1 downto 0) := "10";
104 sel(1 downto 0) := "11";
106 result <= x"00000000000000" & "00" & sel;