2 use ieee.std_logic_1164.all;
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;
16 package body crhelpers is
18 function fxm_to_num(fxm: std_ulogic_vector(7 downto 0)) return integer is
20 -- If multiple fields are set (undefined), match existing
21 -- hardware by returning the first one.
23 -- Big endian bit numbering
24 if fxm(7-i) = '1' then
29 -- If no fields are set (undefined), also match existing
30 -- hardware by returning cr7.
34 function num_to_fxm(num: integer) return std_ulogic_vector is
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;
62 -- for i in 0 to cr'length-1 loop
65 -- combined_cr(high downto low) := cr(i);
68 -- return combined_cr;
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;
75 -- crnum := fxm_to_num(fxm);
77 -- -- Vivado doesn't support non constant vector slice
78 -- -- low := 4*(7-crnum);
80 -- -- combined_cr(high downto low) := cr(crnum);
81 -- case_0: case crnum is
83 -- combined_cr(31 downto 28) := cr(0);
85 -- combined_cr(27 downto 24) := cr(1);
87 -- combined_cr(23 downto 20) := cr(2);
89 -- combined_cr(19 downto 16) := cr(3);
91 -- combined_cr(15 downto 12) := cr(4);
93 -- combined_cr(11 downto 8) := cr(5);
95 -- combined_cr(7 downto 4) := cr(6);
97 -- combined_cr(3 downto 0) := cr(7);
100 -- return combined_cr;
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;
110 -- for i in 0 to 7 loop
111 -- -- BE bit numbering
112 -- if fxm(7-i) = '1' then
115 -- cr(i) := rs(high downto low);
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;
128 -- crnum := fxm_to_num(fxm);
129 -- low := 4*(7-crnum);
131 -- cr(crnum) := rs(high downto low);
134 end package body crhelpers;