library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity NthLsbDetector is generic( num_dirs : positive := 2; n : positive := 1 ); port ( dirs : in std_logic_vector(num_dirs-1 downto 0); grant_dirs : out std_logic_vector(num_dirs-1 downto 0) ); end NthLsbDetector; architecture rtl of NthLsbDetector is type DIR_TYPE is array(natural range<>) of std_logic_vector(num_dirs-1 downto 0); signal s_grant_dirs : DIR_TYPE(n-1 downto 0); signal masked_dirs : DIR_TYPE(n-1 downto 0); begin g_LSB_UNIT: for i in 0 to n-1 generate signal grant : std_logic_vector(num_dirs-1 downto 0); begin grant <= (not masked_dirs(i)(num_dirs-2 downto 0) and grant(num_dirs-2 downto 0)) & '1'; s_grant_dirs(i) <= masked_dirs(i) and grant; end generate; g_masked_dirs: for i in 1 to n-1 generate masked_dirs(i) <= not s_grant_dirs(i-1) and masked_dirs(i-1); end generate; masked_dirs(0) <= dirs; grant_dirs <= s_grant_dirs(n-1); end rtl;