alu/div: dision in hardwaregerechte art und weise
[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                 variable count : boolean := true;
18         begin
19                 for i in (CBITS-1) downto 0 loop
20                         if count then
21                                 if a(i) = '1' then
22                                         count := false;
23                                 else
24                                         r := r+1;
25                                 end if;
26                         else
27                                 null;
28                         end if;
29                 end loop;
30                 return (CBITS - r);
31         end function find_msb;
32 end package body gen_pkg;
33