-- Model Name : cache_pack -- Author : Armita Peymandoust -- Last Updated : 09 / 15 / 1996 -- This document is © copyrighted by the Author.

    LIBRARY IEEE;
    USE IEEE.std_logic_1164.ALL;
    
    -------------------------------------------------------------------------
    
    PACKAGE cache_pack IS
     
      PROCEDURE int2std_logic (int : IN INTEGER; std : OUT std_logic_vector);
      FUNCTION std_logic2int (stdin : IN std_logic_vector) RETURN INTEGER;
      FUNCTION afunc (intin : IN INTEGER) RETURN INTEGER;
      
    END cache_pack;
    
    --------------------------------------------------------------------------
    
    PACKAGE BODY cache_pack IS
    
      FUNCTION afunc (intin : IN INTEGER) RETURN INTEGER IS
      BEGIN
        CASE intin IS
              WHEN 1 => RETURN 0;
              WHEN 2 => RETURN 0;
              WHEN 4 => RETURN 2;
              WHEN OTHERS => RETURN 0;
        END CASE;
    
      END afunc;
    
    --**********************************************************************   
    
      FUNCTION std_logic2int (stdin : IN std_logic_vector) RETURN INTEGER IS
    
        VARIABLE result : INTEGER;
    
      BEGIN
    
        result := 0;
    
        FOR i IN stdin'RIGHT TO stdin'LEFT LOOP
          IF stdin(i) = '1' THEN
            result := result + 2**(i-stdin'RIGHT);
          END IF;
        END LOOP;
    
        RETURN result;
    
      END std_logic2int;
    
    --***********************************************************************
    
      PROCEDURE int2std_logic (int : IN INTEGER; std : OUT std_logic_vector) IS
    
        VARIABLE tmp : INTEGER;
    
      BEGIN
    
        tmp := int;
    
        FOR i IN std'RIGHT TO std'LEFT LOOP
          IF (tmp MOD 2  =  1) THEN 
            std (i) := '1';
          ELSE std (i) := '0';
          END IF;
          tmp := tmp / 2;
        END LOOP;
    
      END int2std_logic;
    
    --************************************************************************
    
    END cache_pack;