2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
7 use work.crhelpers.all;
13 e_in : in Execute1ToWritebackType;
14 l_in : in DcacheToWritebackType;
15 m_in : in MultiplyToWritebackType;
16 d_in : in DividerToWritebackType;
18 w_out : out WritebackToRegisterFileType;
19 c_out : out WritebackToCrFileType;
21 complete_out : out std_ulogic
25 architecture behaviour of writeback is
26 subtype byte_index_t is unsigned(2 downto 0);
27 type permutation_t is array(0 to 7) of byte_index_t;
28 subtype byte_trim_t is std_ulogic_vector(1 downto 0);
29 type trim_ctl_t is array(0 to 7) of byte_trim_t;
30 type byte_sel_t is array(0 to 7) of std_ulogic;
32 signal data_len : unsigned(3 downto 0);
33 signal data_in : std_ulogic_vector(63 downto 0);
34 signal data_permuted : std_ulogic_vector(63 downto 0);
35 signal data_trimmed : std_ulogic_vector(63 downto 0);
36 signal data_latched : std_ulogic_vector(63 downto 0);
37 signal perm : permutation_t;
38 signal use_second : byte_sel_t;
39 signal byte_offset : unsigned(2 downto 0);
40 signal brev_lenm1 : unsigned(2 downto 0);
41 signal trim_ctl : trim_ctl_t;
42 signal rc : std_ulogic;
43 signal partial_write : std_ulogic;
44 signal sign_extend : std_ulogic;
45 signal negative : std_ulogic;
46 signal second_word : std_ulogic;
47 signal zero : std_ulogic;
49 writeback_0: process(clk)
51 if rising_edge(clk) then
52 if partial_write = '1' then
53 data_latched <= data_permuted;
58 writeback_1: process(all)
59 variable x : std_ulogic_vector(0 downto 0);
60 variable y : std_ulogic_vector(0 downto 0);
61 variable z : std_ulogic_vector(0 downto 0);
62 variable w : std_ulogic_vector(0 downto 0);
64 variable k : unsigned(3 downto 0);
65 variable cf: std_ulogic_vector(3 downto 0);
66 variable xe: xer_common_t;
72 assert (to_integer(unsigned(x)) + to_integer(unsigned(y)) + to_integer(unsigned(z)) + to_integer(unsigned(w))) <= 1 severity failure;
74 x := "" & e_in.write_enable;
75 y := "" & l_in.write_enable;
76 z := "" & m_in.write_reg_enable;
77 w := "" & d_in.write_reg_enable;
78 assert (to_integer(unsigned(x)) + to_integer(unsigned(y)) + to_integer(unsigned(z)) + to_integer(unsigned(w))) <= 1 severity failure;
80 w := "" & e_in.write_cr_enable;
81 x := "" & (e_in.write_enable and e_in.rc);
82 y := "" & (m_in.valid and m_in.rc);
83 z := "" & (d_in.valid and d_in.rc);
84 assert (to_integer(unsigned(w)) + to_integer(unsigned(x)) + to_integer(unsigned(y)) + to_integer(unsigned(z))) <= 1 severity failure;
86 x := "" & e_in.write_xerc_enable;
87 y := "" & m_in.write_xerc_enable;
88 z := "" & D_in.write_xerc_enable;
89 assert (to_integer(unsigned(x)) + to_integer(unsigned(y)) + to_integer(unsigned(z))) <= 1 severity failure;
91 w_out <= WritebackToRegisterFileInit;
92 c_out <= WritebackToCrFileInit;
95 if e_in.valid = '1' or l_in.valid = '1' or m_in.valid = '1' or d_in.valid = '1' then
101 byte_offset <= "000";
103 partial_write <= '0';
107 data_in <= (others => '0');
109 if e_in.write_enable = '1' then
110 w_out.write_reg <= e_in.write_reg;
111 w_out.write_enable <= '1';
112 data_in <= e_in.write_data;
113 data_len <= unsigned(e_in.write_len);
114 sign_extend <= e_in.sign_extend;
118 if e_in.write_cr_enable = '1' then
119 c_out.write_cr_enable <= '1';
120 c_out.write_cr_mask <= e_in.write_cr_mask;
121 c_out.write_cr_data <= e_in.write_cr_data;
124 if e_in.write_xerc_enable = '1' then
125 c_out.write_xerc_enable <= '1';
126 c_out.write_xerc_data <= e_in.xerc;
129 if l_in.write_enable = '1' then
130 w_out.write_reg <= gpr_to_gspr(l_in.write_reg);
131 data_in <= l_in.write_data;
132 data_len <= unsigned(l_in.write_len);
133 byte_offset <= unsigned(l_in.write_shift);
134 sign_extend <= l_in.sign_extend;
135 if l_in.byte_reverse = '1' then
136 brev_lenm1 <= unsigned(l_in.write_len(2 downto 0)) - 1;
138 w_out.write_enable <= '1';
139 second_word <= l_in.second_word;
140 if l_in.valid = '0' and (data_len + byte_offset > 8) then
141 partial_write <= '1';
146 if m_in.write_reg_enable = '1' then
147 w_out.write_enable <= '1';
148 w_out.write_reg <= gpr_to_gspr(m_in.write_reg_nr);
149 data_in <= m_in.write_reg_data;
154 if m_in.write_xerc_enable = '1' then
155 c_out.write_xerc_enable <= '1';
156 c_out.write_xerc_data <= m_in.xerc;
159 if d_in.write_reg_enable = '1' then
160 w_out.write_enable <= '1';
161 w_out.write_reg <= gpr_to_gspr(d_in.write_reg_nr);
162 data_in <= d_in.write_reg_data;
167 if d_in.write_xerc_enable = '1' then
168 c_out.write_xerc_enable <= '1';
169 c_out.write_xerc_data <= d_in.xerc;
172 -- shift and byte-reverse data bytes
174 k := ('0' & (to_unsigned(i, 3) xor brev_lenm1)) + ('0' & byte_offset);
175 perm(i) <= k(2 downto 0);
176 use_second(i) <= k(3);
179 j := to_integer(perm(i)) * 8;
180 data_permuted(i * 8 + 7 downto i * 8) <= data_in(j + 7 downto j);
183 -- If the data can arrive split over two cycles, this will be correct
184 -- provided we don't have both sign extension and byte reversal.
185 negative <= (data_len(3) and data_permuted(63)) or
186 (data_len(2) and data_permuted(31)) or
187 (data_len(1) and data_permuted(15)) or
188 (data_len(0) and data_permuted(7));
190 -- trim and sign-extend
192 if i < to_integer(data_len) then
193 if second_word = '1' then
194 trim_ctl(i) <= '1' & not use_second(i);
196 trim_ctl(i) <= not use_second(i) & '0';
199 trim_ctl(i) <= '0' & (negative and sign_extend);
202 zero <= not negative;
206 data_trimmed(i * 8 + 7 downto i * 8) <= data_latched(i * 8 + 7 downto i * 8);
208 data_trimmed(i * 8 + 7 downto i * 8) <= data_permuted(i * 8 + 7 downto i * 8);
209 if or data_permuted(i * 8 + 7 downto i * 8) /= '0' then
213 data_trimmed(i * 8 + 7 downto i * 8) <= x"FF";
215 data_trimmed(i * 8 + 7 downto i * 8) <= x"00";
219 -- deliver to regfile
220 w_out.write_data <= data_trimmed;
222 -- Perform CR0 update for RC forms
224 c_out.write_cr_enable <= '1';
225 c_out.write_cr_mask <= num_to_fxm(0);
227 cf(2) := not negative and not zero;
230 c_out.write_cr_data(31 downto 28) <= cf;