alu/div: weniger code und weniger logic elements
[hwmod.git] / src / gen_pkg.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5 package gen_pkg is
6         type alu_ops is (NOP, SUB, ADD, MUL, DIV, DONE);
7         constant CBITS : integer := 32;
8         subtype csigned is signed((CBITS-1) downto 0);
9         --TODO: bei CBITS-1 gibts einen overflow :/
10         subtype cinteger is integer range -(2**(CBITS-2)) to ((2**(CBITS-2))-1);
11         function find_msb(a : csigned) return natural;
12 end package gen_pkg;
13
14 package body gen_pkg is
15         function find_msb(a : csigned) return natural is
16                 variable r : natural := 0;
17         begin
18                 for i in (CBITS-1) downto 0 loop
19                         exit when a(i) = '1';
20                         r := r+1;
21                 end loop;
22                 return (CBITS - r);
23         end function find_msb;
24 end package body gen_pkg;
25