---------------------------------------------------------------------- -- File: cnt1s - Count 1's -- Author: -- Creation: -- Verified: -- Version: ----------------------------------------------------------------------- -- 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 of 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); N := 0; END PROCESS; END ARCHITECTURE behav;