---------------------------------------------------------------------- -- File: cnt1s - Count 1's -- Author: Jerry H. Tucker -- Creation: 9/19/99 -- Verified: 9/19/99 -- Version: 1.0 ------------------------------------------------------------------------ -- Requires: pkgmips.vhd LIBRARY IEEE; USE work.mips.all; USE IEEE.Std_Logic_1164.all; USE IEEE.std_logic_unsigned.all; use ieee.std_logic_arith.all; ------------------------------------------------------------------------ -- FUNCTION: cnt1s - Sets Cnt to number off 1's in Rin. ------------------------------------------------------------------------ ENTITY cnt1s IS PORT(Rin: IN std_logic_vector(DWordSize-1 downto 0); Cnt: OUT std_logic_vector(4 downto 0)); END ENTITY cnt1s; ARCHITECTURE behav OF cnt1s IS BEGIN PROCESS(Rin) is VARIABLE I: INTEGER; VARIABLE N: INTEGER := 0; BEGIN FOR I in 0 to DWordSize-1 loop IF Rin(I) = '1' THEN N := N+1; END IF; END LOOP; Cnt <= CONV_STD_LOGIC_VECTOR(N, 5); END PROCESS; END ARCHITECTURE behav;