--------------------------------------------------------------
-- Copyright 1996 by Doone Publications. All rights reserved.
--
-- Design:  PRI_EN8_3_CASE
-- Name:    Doug Smith
-- Date:    1st June 1996
--
-- Description:
--   8-3 priority encoder using a "case" statement.
--------------------------------------------------------------

library IEEE;
use IEEE.STD_Logic_1164.all, IEEE.Numeric_STD.all;
 
entity PRI_EN8_3_CASE is
   port (A:     in  unsigned(7 downto 0);
         Valid: out std_logic;
         Y:     out unsigned(2 downto 0));
end entity PRI_EN8_3_CASE;

architecture COND_DATA_FLOW of PRI_EN8_3_CASE is
begin
   process (A)
      variable A_int: integer range 0 to 255;
   begin
      A_int := to_integer(A);
      Valid <= '1';
      case A_int is
         when 128 to 255 =>  Y <= "000";
         when  64 to 128 =>  Y <= "001";
         when  32 to 63  =>  Y <= "010";
         when  16 to 31  =>  Y <= "011";
         when   8 to 15  =>  Y <= "100";
         when   4 to 7   =>  Y <= "101";
         when   2 to 3   =>  Y <= "110";
         when   1        =>  Y <= "111";
         when others     =>  Valid <= '0';
                             Y <= "XXX";
      end case;
   end process;
end architecture COND_DATA_FLOW;