Add pretty gif demo of MicroPython on Microwatt to README.md
[microwatt.git] / crhelpers.vhdl
1 library ieee;
2 use ieee.std_logic_1164.all;
3
4 library work;
5 use work.common.all;
6
7 package crhelpers is
8 function fxm_to_num(fxm: std_ulogic_vector(7 downto 0)) return integer;
9 function num_to_fxm(num: integer) return std_ulogic_vector;
10 --function from_crfile(cr: crfile) return std_ulogic_vector;
11 --function extract_one_crfield(cr: crfile; fxm: std_ulogic_vector(7 downto 0)) return std_ulogic_vector;
12 --function insert_multiple_crfields(cr_in: crfile; rs: std_ulogic_vector(63 downto 0); fxm: std_ulogic_vector(7 downto 0)) return crfile;
13 --function insert_one_crfield(cr_in: crfile; rs: std_ulogic_vector(63 downto 0); fxm: std_ulogic_vector(7 downto 0)) return crfile;
14 end package crhelpers;
15
16 package body crhelpers is
17
18 function fxm_to_num(fxm: std_ulogic_vector(7 downto 0)) return integer is
19 begin
20 -- If multiple fields are set (undefined), match existing
21 -- hardware by returning the first one.
22 for i in 0 to 7 loop
23 -- Big endian bit numbering
24 if fxm(7-i) = '1' then
25 return i;
26 end if;
27 end loop;
28
29 -- If no fields are set (undefined), also match existing
30 -- hardware by returning cr7.
31 return 7;
32 end;
33
34 function num_to_fxm(num: integer) return std_ulogic_vector is
35 begin
36 case num is
37 when 0 =>
38 return "10000000";
39 when 1 =>
40 return "01000000";
41 when 2 =>
42 return "00100000";
43 when 3 =>
44 return "00010000";
45 when 4 =>
46 return "00001000";
47 when 5 =>
48 return "00000100";
49 when 6 =>
50 return "00000010";
51 when 7 =>
52 return "00000001";
53 when others =>
54 return "00000000";
55 end case;
56 end;
57
58 -- function from_crfile(cr: crfile) return std_ulogic_vector is
59 -- variable combined_cr : std_ulogic_vector(31 downto 0) := (others => '0');
60 -- variable high, low: integer range 0 to 31 := 0;
61 -- begin
62 -- for i in 0 to cr'length-1 loop
63 -- low := 4*(7-i);
64 -- high := low+3;
65 -- combined_cr(high downto low) := cr(i);
66 -- end loop;
67 --
68 -- return combined_cr;
69 -- end function;
70 --
71 -- function extract_one_crfield(cr: crfile; fxm: std_ulogic_vector(7 downto 0)) return std_ulogic_vector is
72 -- variable combined_cr : std_ulogic_vector(63 downto 0) := (others => '0');
73 -- variable crnum: integer range 0 to 7 := 0;
74 -- begin
75 -- crnum := fxm_to_num(fxm);
76 --
77 -- -- Vivado doesn't support non constant vector slice
78 -- -- low := 4*(7-crnum);
79 -- -- high := low+3;
80 -- -- combined_cr(high downto low) := cr(crnum);
81 -- case_0: case crnum is
82 -- when 0 =>
83 -- combined_cr(31 downto 28) := cr(0);
84 -- when 1 =>
85 -- combined_cr(27 downto 24) := cr(1);
86 -- when 2 =>
87 -- combined_cr(23 downto 20) := cr(2);
88 -- when 3 =>
89 -- combined_cr(19 downto 16) := cr(3);
90 -- when 4 =>
91 -- combined_cr(15 downto 12) := cr(4);
92 -- when 5 =>
93 -- combined_cr(11 downto 8) := cr(5);
94 -- when 6 =>
95 -- combined_cr(7 downto 4) := cr(6);
96 -- when 7 =>
97 -- combined_cr(3 downto 0) := cr(7);
98 -- end case;
99 --
100 -- return combined_cr;
101 -- end;
102 --
103 -- function insert_multiple_crfields(cr_in: crfile; rs: std_ulogic_vector(63 downto 0); fxm: std_ulogic_vector(7 downto 0)) return crfile is
104 -- variable cr : crfile;
105 -- variable combined_cr : std_ulogic_vector(63 downto 0) := (others => '0');
106 -- variable high, low: integer range 0 to 31 := 0;
107 -- begin
108 -- cr := cr_in;
109 --
110 -- for i in 0 to 7 loop
111 -- -- BE bit numbering
112 -- if fxm(7-i) = '1' then
113 -- low := 4*(7-i);
114 -- high := low+3;
115 -- cr(i) := rs(high downto low);
116 -- end if;
117 -- end loop;
118 --
119 -- return cr;
120 -- end;
121 --
122 -- function insert_one_crfield(cr_in: crfile; rs: std_ulogic_vector(63 downto 0); fxm: std_ulogic_vector(7 downto 0)) return crfile is
123 -- variable cr : crfile;
124 -- variable crnum: integer range 0 to 7 := 0;
125 -- variable high, low: integer range 0 to 31 := 0;
126 -- begin
127 -- cr := cr_in;
128 -- crnum := fxm_to_num(fxm);
129 -- low := 4*(7-crnum);
130 -- high := low+3;
131 -- cr(crnum) := rs(high downto low);
132 -- return cr;
133 -- end;
134 end package body crhelpers;