forked from antonblanchard/microwatt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crhelpers.vhdl
57 lines (49 loc) · 1.47 KB
/
crhelpers.vhdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library ieee;
use ieee.std_logic_1164.all;
library work;
use work.common.all;
package crhelpers is
subtype crnum_t is integer range 0 to 7;
subtype crmask_t is std_ulogic_vector(7 downto 0);
function fxm_to_num(fxm: crmask_t) return crnum_t;
function num_to_fxm(num: crnum_t) return crmask_t;
end package crhelpers;
package body crhelpers is
function fxm_to_num(fxm: crmask_t) return crnum_t is
begin
-- If multiple fields are set (undefined), match existing
-- hardware by returning the first one.
for i in 0 to 7 loop
-- Big endian bit numbering
if fxm(7-i) = '1' then
return i;
end if;
end loop;
-- If no fields are set (undefined), also match existing
-- hardware by returning cr7.
return 7;
end;
function num_to_fxm(num: crnum_t) return crmask_t is
begin
case num is
when 0 =>
return "10000000";
when 1 =>
return "01000000";
when 2 =>
return "00100000";
when 3 =>
return "00010000";
when 4 =>
return "00001000";
when 5 =>
return "00000100";
when 6 =>
return "00000010";
when 7 =>
return "00000001";
when others =>
return "00000000";
end case;
end;
end package body crhelpers;