1 |
2 |
tobiflex |
------------------------------------------------------------------------------
|
2 |
|
|
------------------------------------------------------------------------------
|
3 |
|
|
-- --
|
4 |
4 |
tobiflex |
-- Copyright (c) 2009-2019 Tobias Gubener --
|
5 |
|
|
-- Patches by MikeJ, Till Harbaum, Rok Krajnk, ... --
|
6 |
2 |
tobiflex |
-- Subdesign fAMpIGA by TobiFlex --
|
7 |
|
|
-- --
|
8 |
|
|
-- This source file is free software: you can redistribute it and/or modify --
|
9 |
|
|
-- it under the terms of the GNU Lesser General Public License as published --
|
10 |
|
|
-- by the Free Software Foundation, either version 3 of the License, or --
|
11 |
|
|
-- (at your option) any later version. --
|
12 |
|
|
-- --
|
13 |
|
|
-- This source file is distributed in the hope that it will be useful, --
|
14 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
15 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
16 |
|
|
-- GNU General Public License for more details. --
|
17 |
|
|
-- --
|
18 |
|
|
-- You should have received a copy of the GNU General Public License --
|
19 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
|
20 |
|
|
-- --
|
21 |
|
|
------------------------------------------------------------------------------
|
22 |
|
|
------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
library ieee;
|
25 |
|
|
use ieee.std_logic_1164.all;
|
26 |
|
|
use ieee.std_logic_unsigned.all;
|
27 |
|
|
use IEEE.numeric_std.all;
|
28 |
|
|
use work.TG68K_Pack.all;
|
29 |
|
|
|
30 |
|
|
entity TG68K_ALU is
|
31 |
|
|
generic(
|
32 |
4 |
tobiflex |
MUL_Mode : integer; --0=>16Bit, 1=>32Bit, 2=>switchable with CPU(1), 3=>no MUL,
|
33 |
|
|
MUL_Hardware : integer; --0=>no, 1=>yes,
|
34 |
|
|
DIV_Mode : integer; --0=>16Bit, 1=>32Bit, 2=>switchable with CPU(1), 3=>no DIV,
|
35 |
|
|
BarrelShifter :integer --0=>no, 1=>yes, 2=>switchable with CPU(1)
|
36 |
2 |
tobiflex |
);
|
37 |
6 |
tobiflex |
port(clk : in std_logic;
|
38 |
|
|
Reset : in std_logic;
|
39 |
|
|
clkena_lw : in std_logic:='1';
|
40 |
11 |
tobiflex |
CPU : in std_logic_vector(1 downto 0):="00"; -- 00->68000 01->68010 11->68020(only some parts - yet)
|
41 |
6 |
tobiflex |
execOPC : in bit;
|
42 |
|
|
decodeOPC : in bit;
|
43 |
|
|
exe_condition : in std_logic;
|
44 |
|
|
exec_tas : in std_logic;
|
45 |
|
|
long_start : in bit;
|
46 |
|
|
non_aligned : in std_logic;
|
47 |
|
|
movem_presub : in bit;
|
48 |
|
|
set_stop : in bit;
|
49 |
|
|
Z_error : in bit;
|
50 |
|
|
rot_bits : in std_logic_vector(1 downto 0);
|
51 |
|
|
exec : in bit_vector(lastOpcBit downto 0);
|
52 |
|
|
OP1out : in std_logic_vector(31 downto 0);
|
53 |
|
|
OP2out : in std_logic_vector(31 downto 0);
|
54 |
|
|
reg_QA : in std_logic_vector(31 downto 0);
|
55 |
|
|
reg_QB : in std_logic_vector(31 downto 0);
|
56 |
|
|
opcode : in std_logic_vector(15 downto 0);
|
57 |
|
|
exe_opcode : in std_logic_vector(15 downto 0);
|
58 |
|
|
exe_datatype : in std_logic_vector(1 downto 0);
|
59 |
|
|
sndOPC : in std_logic_vector(15 downto 0);
|
60 |
|
|
last_data_read : in std_logic_vector(15 downto 0);
|
61 |
|
|
data_read : in std_logic_vector(15 downto 0);
|
62 |
|
|
FlagsSR : in std_logic_vector(7 downto 0);
|
63 |
|
|
micro_state : in micro_states;
|
64 |
|
|
bf_ext_in : in std_logic_vector(7 downto 0);
|
65 |
|
|
bf_ext_out : out std_logic_vector(7 downto 0);
|
66 |
|
|
bf_shift : in std_logic_vector(5 downto 0);
|
67 |
|
|
bf_width : in std_logic_vector(5 downto 0);
|
68 |
|
|
bf_ffo_offset : in std_logic_vector(31 downto 0);
|
69 |
|
|
bf_loffset : in std_logic_vector(4 downto 0);
|
70 |
5 |
tobiflex |
|
71 |
6 |
tobiflex |
set_V_Flag : buffer bit;
|
72 |
|
|
Flags : buffer std_logic_vector(7 downto 0);
|
73 |
|
|
c_out : buffer std_logic_vector(2 downto 0);
|
74 |
|
|
addsub_q : buffer std_logic_vector(31 downto 0);
|
75 |
|
|
ALUout : out std_logic_vector(31 downto 0)
|
76 |
5 |
tobiflex |
);
|
77 |
2 |
tobiflex |
end TG68K_ALU;
|
78 |
|
|
|
79 |
|
|
architecture logic of TG68K_ALU is
|
80 |
|
|
-----------------------------------------------------------------------------
|
81 |
|
|
-----------------------------------------------------------------------------
|
82 |
|
|
-- ALU and more
|
83 |
|
|
-----------------------------------------------------------------------------
|
84 |
|
|
-----------------------------------------------------------------------------
|
85 |
6 |
tobiflex |
signal OP1in : std_logic_vector(31 downto 0);
|
86 |
|
|
signal addsub_a : std_logic_vector(31 downto 0);
|
87 |
|
|
signal addsub_b : std_logic_vector(31 downto 0);
|
88 |
|
|
signal notaddsub_b : std_logic_vector(33 downto 0);
|
89 |
|
|
signal add_result : std_logic_vector(33 downto 0);
|
90 |
|
|
signal addsub_ofl : std_logic_vector(2 downto 0);
|
91 |
|
|
signal opaddsub : bit;
|
92 |
|
|
signal c_in : std_logic_vector(3 downto 0);
|
93 |
|
|
signal flag_z : std_logic_vector(2 downto 0);
|
94 |
|
|
signal set_Flags : std_logic_vector(3 downto 0); --NZVC
|
95 |
|
|
signal CCRin : std_logic_vector(7 downto 0);
|
96 |
11 |
tobiflex |
signal last_Flags1 : std_logic_vector(3 downto 0); --NZVC
|
97 |
2 |
tobiflex |
|
98 |
|
|
--BCD
|
99 |
6 |
tobiflex |
signal bcd_pur : std_logic_vector(9 downto 0);
|
100 |
|
|
signal bcd_kor : std_logic_vector(8 downto 0);
|
101 |
|
|
signal halve_carry : std_logic;
|
102 |
|
|
signal Vflag_a : std_logic;
|
103 |
|
|
signal bcd_a_carry : std_logic;
|
104 |
|
|
signal bcd_a : std_logic_vector(8 downto 0);
|
105 |
|
|
signal result_mulu : std_logic_vector(127 downto 0);
|
106 |
|
|
signal result_div : std_logic_vector(63 downto 0);
|
107 |
|
|
signal set_mV_Flag : std_logic;
|
108 |
|
|
signal V_Flag : bit;
|
109 |
|
|
|
110 |
|
|
signal rot_rot : std_logic;
|
111 |
|
|
signal rot_lsb : std_logic;
|
112 |
|
|
signal rot_msb : std_logic;
|
113 |
|
|
signal rot_X : std_logic;
|
114 |
|
|
signal rot_C : std_logic;
|
115 |
|
|
signal rot_out : std_logic_vector(31 downto 0);
|
116 |
|
|
signal asl_VFlag : std_logic;
|
117 |
|
|
signal bit_bits : std_logic_vector(1 downto 0);
|
118 |
|
|
signal bit_number : std_logic_vector(4 downto 0);
|
119 |
|
|
signal bits_out : std_logic_vector(31 downto 0);
|
120 |
|
|
signal one_bit_in : std_logic;
|
121 |
|
|
signal bchg : std_logic;
|
122 |
|
|
signal bset : std_logic;
|
123 |
|
|
|
124 |
|
|
signal mulu_sign : std_logic;
|
125 |
|
|
signal mulu_signext : std_logic_vector(16 downto 0);
|
126 |
|
|
signal muls_msb : std_logic;
|
127 |
|
|
signal mulu_reg : std_logic_vector(63 downto 0);
|
128 |
|
|
signal FAsign : std_logic;
|
129 |
|
|
signal faktorA : std_logic_vector(31 downto 0);
|
130 |
|
|
signal faktorB : std_logic_vector(31 downto 0);
|
131 |
|
|
|
132 |
|
|
signal div_reg : std_logic_vector(63 downto 0);
|
133 |
|
|
signal div_quot : std_logic_vector(63 downto 0);
|
134 |
|
|
signal div_ovl : std_logic;
|
135 |
|
|
signal div_neg : std_logic;
|
136 |
|
|
signal div_bit : std_logic;
|
137 |
|
|
signal div_sub : std_logic_vector(32 downto 0);
|
138 |
|
|
signal div_over : std_logic_vector(32 downto 0);
|
139 |
|
|
signal nozero : std_logic;
|
140 |
|
|
signal div_qsign : std_logic;
|
141 |
11 |
tobiflex |
signal divident : std_logic_vector(63 downto 0);
|
142 |
6 |
tobiflex |
signal divs : std_logic;
|
143 |
|
|
signal signedOP : std_logic;
|
144 |
|
|
signal OP1_sign : std_logic;
|
145 |
|
|
signal OP2_sign : std_logic;
|
146 |
|
|
signal OP2outext : std_logic_vector(15 downto 0);
|
147 |
2 |
tobiflex |
|
148 |
6 |
tobiflex |
signal in_offset : std_logic_vector(5 downto 0);
|
149 |
|
|
signal datareg : std_logic_vector(31 downto 0);
|
150 |
|
|
signal insert : std_logic_vector(31 downto 0);
|
151 |
|
|
signal bf_datareg : std_logic_vector(31 downto 0);
|
152 |
|
|
signal result : std_logic_vector(39 downto 0);
|
153 |
|
|
signal result_tmp : std_logic_vector(39 downto 0);
|
154 |
|
|
signal unshifted_bitmask: std_logic_vector(31 downto 0);
|
155 |
|
|
signal bf_set1 : std_logic_vector(39 downto 0);
|
156 |
|
|
signal inmux0 : std_logic_vector(39 downto 0);
|
157 |
|
|
signal inmux1 : std_logic_vector(39 downto 0);
|
158 |
|
|
signal inmux2 : std_logic_vector(39 downto 0);
|
159 |
|
|
signal inmux3 : std_logic_vector(31 downto 0);
|
160 |
|
|
signal shifted_bitmask : std_logic_vector(39 downto 0);
|
161 |
|
|
signal bitmaskmux0 : std_logic_vector(37 downto 0);
|
162 |
|
|
signal bitmaskmux1 : std_logic_vector(35 downto 0);
|
163 |
|
|
signal bitmaskmux2 : std_logic_vector(31 downto 0);
|
164 |
|
|
signal bitmaskmux3 : std_logic_vector(31 downto 0);
|
165 |
|
|
signal bf_set2 : std_logic_vector(31 downto 0);
|
166 |
|
|
signal shift : std_logic_vector(39 downto 0);
|
167 |
|
|
signal bf_firstbit : std_logic_vector(5 downto 0);
|
168 |
|
|
signal mux : std_logic_vector(3 downto 0);
|
169 |
|
|
signal bitnr : std_logic_vector(4 downto 0);
|
170 |
|
|
signal mask : std_logic_vector(31 downto 0);
|
171 |
|
|
signal mask_not_zero : std_logic;
|
172 |
|
|
signal bf_bset : std_logic;
|
173 |
|
|
signal bf_NFlag : std_logic;
|
174 |
|
|
signal bf_bchg : std_logic;
|
175 |
|
|
signal bf_ins : std_logic;
|
176 |
|
|
signal bf_exts : std_logic;
|
177 |
|
|
signal bf_fffo : std_logic;
|
178 |
|
|
signal bf_d32 : std_logic;
|
179 |
|
|
signal bf_s32 : std_logic;
|
180 |
|
|
signal index : std_logic_vector(4 downto 0);
|
181 |
|
|
-- signal i : integer range 0 to 31;
|
182 |
|
|
-- signal i : integer range 0 to 31;
|
183 |
|
|
-- signal i : std_logic_vector(5 downto 0);
|
184 |
2 |
tobiflex |
|
185 |
7 |
tobiflex |
signal hot_msb : std_logic_vector(33 downto 0);
|
186 |
6 |
tobiflex |
signal vector : std_logic_vector(32 downto 0);
|
187 |
|
|
signal result_bs : std_logic_vector(65 downto 0);
|
188 |
|
|
signal bit_nr : std_logic_vector(5 downto 0);
|
189 |
|
|
signal bit_msb : std_logic_vector(5 downto 0);
|
190 |
|
|
signal bs_shift : std_logic_vector(5 downto 0);
|
191 |
|
|
signal bs_shift_mod : std_logic_vector(5 downto 0);
|
192 |
|
|
signal asl_over : std_logic_vector(32 downto 0);
|
193 |
|
|
signal asl_over_xor : std_logic_vector(32 downto 0);
|
194 |
|
|
signal asr_sign : std_logic_vector(32 downto 0);
|
195 |
|
|
signal msb : std_logic;
|
196 |
|
|
signal ring : std_logic_vector(5 downto 0);
|
197 |
|
|
signal ALU : std_logic_vector(31 downto 0);
|
198 |
|
|
signal BSout : std_logic_vector(31 downto 0);
|
199 |
|
|
signal bs_V : std_logic;
|
200 |
|
|
signal bs_C : std_logic;
|
201 |
|
|
signal bs_X : std_logic;
|
202 |
2 |
tobiflex |
|
203 |
6 |
tobiflex |
|
204 |
2 |
tobiflex |
BEGIN
|
205 |
|
|
-----------------------------------------------------------------------------
|
206 |
|
|
-- set OP1in
|
207 |
|
|
-----------------------------------------------------------------------------
|
208 |
|
|
PROCESS (OP2out, reg_QB, opcode, OP1out, OP1in, exe_datatype, addsub_q, execOPC, exec,
|
209 |
6 |
tobiflex |
bcd_a, result_mulu, result_div, exe_condition, bf_shift, bf_ffo_offset, mulu_reg, BSout,
|
210 |
|
|
Flags, FlagsSR, bits_out, exec_tas, rot_out, exe_opcode, result, bf_fffo, bf_firstbit, bf_datareg)
|
211 |
2 |
tobiflex |
BEGIN
|
212 |
|
|
ALUout <= OP1in;
|
213 |
|
|
ALUout(7) <= OP1in(7) OR exec_tas;
|
214 |
|
|
IF exec(opcBFwb)='1' THEN
|
215 |
|
|
ALUout <= result(31 downto 0);
|
216 |
|
|
IF bf_fffo='1' THEN
|
217 |
|
|
ALUout <= bf_ffo_offset - bf_firstbit;
|
218 |
|
|
END IF;
|
219 |
|
|
END IF;
|
220 |
|
|
|
221 |
|
|
OP1in <= addsub_q;
|
222 |
|
|
IF exec(opcABCD)='1' OR exec(opcSBCD)='1' THEN
|
223 |
|
|
OP1in(7 downto 0) <= bcd_a(7 downto 0);
|
224 |
|
|
ELSIF exec(opcMULU)='1' AND MUL_Mode/=3 THEN
|
225 |
|
|
IF MUL_Hardware=0 THEN
|
226 |
|
|
IF exec(write_lowlong)='1' AND (MUL_Mode=1 OR MUL_Mode=2) THEN
|
227 |
|
|
OP1in <= result_mulu(31 downto 0);
|
228 |
|
|
ELSE
|
229 |
|
|
OP1in <= result_mulu(63 downto 32);
|
230 |
|
|
END IF;
|
231 |
|
|
ELSE
|
232 |
|
|
IF exec(write_lowlong)='1' THEN --AND (MUL_Mode=1 OR MUL_Mode=2) THEN
|
233 |
|
|
OP1in <= result_mulu(31 downto 0);
|
234 |
|
|
ELSE
|
235 |
|
|
-- OP1in <= result_mulu(63 downto 32);
|
236 |
|
|
OP1in <= mulu_reg(31 downto 0);
|
237 |
|
|
END IF;
|
238 |
|
|
END IF;
|
239 |
|
|
ELSIF exec(opcDIVU)='1' AND DIV_Mode/=3 THEN
|
240 |
|
|
IF exe_opcode(15)='1' OR DIV_Mode=0 THEN
|
241 |
|
|
-- IF exe_opcode(15)='1' THEN
|
242 |
10 |
tobiflex |
OP1in <= result_div(47 downto 32)&result_div(15 downto 0); --word
|
243 |
2 |
tobiflex |
ELSE --64bit
|
244 |
|
|
IF exec(write_reminder)='1' THEN
|
245 |
|
|
OP1in <= result_div(63 downto 32);
|
246 |
|
|
ELSE
|
247 |
|
|
OP1in <= result_div(31 downto 0);
|
248 |
|
|
END IF;
|
249 |
|
|
END IF;
|
250 |
|
|
ELSIF exec(opcOR)='1' THEN
|
251 |
|
|
OP1in <= OP2out OR OP1out;
|
252 |
|
|
ELSIF exec(opcAND)='1' THEN
|
253 |
|
|
OP1in <= OP2out AND OP1out;
|
254 |
|
|
ELSIF exec(opcScc)='1' THEN
|
255 |
|
|
OP1in(7 downto 0) <= (others=>exe_condition);
|
256 |
|
|
ELSIF exec(opcEOR)='1' THEN
|
257 |
|
|
OP1in <= OP2out XOR OP1out;
|
258 |
11 |
tobiflex |
-- ELSIF exec(alu_move)='1' OR exec(exg)='1' THEN
|
259 |
|
|
ELSIF exec(alu_move)='1' THEN
|
260 |
2 |
tobiflex |
-- OP1in <= OP2out(31 downto 8)&(OP2out(7)OR exec_tas)&OP2out(6 downto 0);
|
261 |
|
|
OP1in <= OP2out;
|
262 |
|
|
ELSIF exec(opcROT)='1' THEN
|
263 |
|
|
OP1in <= rot_out;
|
264 |
|
|
ELSIF exec(exec_BS)='1' THEN
|
265 |
|
|
OP1in <= BSout;
|
266 |
|
|
ELSIF exec(opcSWAP)='1' THEN
|
267 |
|
|
OP1in <= OP1out(15 downto 0)& OP1out(31 downto 16);
|
268 |
|
|
ELSIF exec(opcBITS)='1' THEN
|
269 |
|
|
OP1in <= bits_out;
|
270 |
|
|
ELSIF exec(opcBF)='1' THEN
|
271 |
|
|
OP1in <= bf_datareg; --new bitfieldvector for bfins - for others the old bitfieldvector
|
272 |
|
|
ELSIF exec(opcMOVESR)='1' THEN
|
273 |
|
|
OP1in(7 downto 0) <= Flags;
|
274 |
|
|
IF exe_opcode(9)='1' THEN
|
275 |
|
|
OP1in(15 downto 8) <= "00000000";
|
276 |
|
|
ELSE
|
277 |
|
|
OP1in(15 downto 8) <= FlagsSR;
|
278 |
|
|
END IF;
|
279 |
|
|
ELSIF exec(opcPACK)='1' THEN
|
280 |
|
|
OP1in(7 downto 0) <= addsub_q(11 downto 8) & addsub_q(3 downto 0);
|
281 |
|
|
END IF;
|
282 |
|
|
END PROCESS;
|
283 |
|
|
|
284 |
|
|
-----------------------------------------------------------------------------
|
285 |
|
|
-- addsub
|
286 |
|
|
-----------------------------------------------------------------------------
|
287 |
|
|
PROCESS (OP1out, OP2out, execOPC, Flags, long_start, movem_presub, exe_datatype, exec, addsub_a, addsub_b, opaddsub,
|
288 |
|
|
notaddsub_b, add_result, c_in, sndOPC, non_aligned)
|
289 |
|
|
BEGIN
|
290 |
|
|
addsub_a <= OP1out;
|
291 |
|
|
IF exec(get_bfoffset)='1' THEN
|
292 |
|
|
IF sndOPC(11)='1' THEN
|
293 |
|
|
addsub_a <= OP1out(31)&OP1out(31)&OP1out(31)&OP1out(31 downto 3);
|
294 |
|
|
ELSE
|
295 |
|
|
addsub_a <= "000000000000000000000000000000"&sndOPC(10 downto 9);
|
296 |
|
|
END IF;
|
297 |
|
|
END IF;
|
298 |
|
|
|
299 |
|
|
IF exec(subidx)='1' THEN
|
300 |
|
|
opaddsub <= '1';
|
301 |
|
|
ELSE
|
302 |
|
|
opaddsub <= '0';
|
303 |
|
|
END IF;
|
304 |
|
|
|
305 |
|
|
c_in(0) <='0';
|
306 |
|
|
addsub_b <= OP2out;
|
307 |
|
|
IF exec(opcUNPACK)='1' THEN
|
308 |
|
|
addsub_b(15 downto 0) <= "0000" & OP2out(7 downto 4) & "0000" & OP2out(3 downto 0);
|
309 |
|
|
ELSIF execOPC='0' AND exec(OP2out_one)='0' AND exec(get_bfoffset)='0'THEN
|
310 |
|
|
IF long_start='0' AND exe_datatype="00" AND exec(use_SP)='0' THEN
|
311 |
|
|
addsub_b <= "00000000000000000000000000000001";
|
312 |
|
|
ELSIF long_start='0' AND exe_datatype="10" AND (exec(presub) OR exec(postadd) OR movem_presub)='1' THEN
|
313 |
|
|
IF exec(movem_action)='1' THEN
|
314 |
|
|
addsub_b <= "00000000000000000000000000000110";
|
315 |
|
|
ELSE
|
316 |
|
|
addsub_b <= "00000000000000000000000000000100";
|
317 |
|
|
END IF;
|
318 |
|
|
ELSE
|
319 |
|
|
addsub_b <= "00000000000000000000000000000010";
|
320 |
|
|
END IF;
|
321 |
|
|
ELSE
|
322 |
10 |
tobiflex |
IF (exec(use_XZFlag)='1' AND Flags(4)='1') OR exec(opcCHK)='1' THEN
|
323 |
2 |
tobiflex |
c_in(0) <= '1';
|
324 |
|
|
END IF;
|
325 |
|
|
opaddsub <= exec(addsub);
|
326 |
|
|
END IF;
|
327 |
|
|
|
328 |
|
|
-- patch for un-aligned movem --mikej
|
329 |
|
|
if (exec(movem_action) = '1') then
|
330 |
|
|
if (movem_presub = '0') then -- up
|
331 |
|
|
if (non_aligned = '1') and (long_start = '0') then -- hold
|
332 |
|
|
addsub_b <= (others => '0');
|
333 |
|
|
end if;
|
334 |
|
|
else
|
335 |
|
|
if (non_aligned = '1') and (long_start = '0') then
|
336 |
|
|
if (exe_datatype = "10") then
|
337 |
|
|
addsub_b <= "00000000000000000000000000001000";
|
338 |
|
|
else
|
339 |
|
|
addsub_b <= "00000000000000000000000000000100";
|
340 |
|
|
end if;
|
341 |
|
|
end if;
|
342 |
|
|
end if;
|
343 |
|
|
end if;
|
344 |
|
|
|
345 |
|
|
IF opaddsub='0' OR long_start='1' THEN --ADD
|
346 |
|
|
notaddsub_b <= '0'&addsub_b&c_in(0);
|
347 |
|
|
ELSE --SUB
|
348 |
|
|
notaddsub_b <= NOT ('0'&addsub_b&c_in(0));
|
349 |
|
|
END IF;
|
350 |
|
|
add_result <= (('0'&addsub_a¬addsub_b(0))+notaddsub_b);
|
351 |
|
|
c_in(1) <= add_result(9) XOR addsub_a(8) XOR addsub_b(8);
|
352 |
|
|
c_in(2) <= add_result(17) XOR addsub_a(16) XOR addsub_b(16);
|
353 |
|
|
c_in(3) <= add_result(33);
|
354 |
|
|
addsub_q <= add_result(32 downto 1);
|
355 |
|
|
addsub_ofl(0) <= (c_in(1) XOR add_result(8) XOR addsub_a(7) XOR addsub_b(7)); --V Byte
|
356 |
|
|
addsub_ofl(1) <= (c_in(2) XOR add_result(16) XOR addsub_a(15) XOR addsub_b(15)); --V Word
|
357 |
|
|
addsub_ofl(2) <= (c_in(3) XOR add_result(32) XOR addsub_a(31) XOR addsub_b(31)); --V Long
|
358 |
|
|
c_out <= c_in(3 downto 1);
|
359 |
|
|
END PROCESS;
|
360 |
|
|
|
361 |
|
|
------------------------------------------------------------------------------
|
362 |
|
|
--ALU
|
363 |
|
|
------------------------------------------------------------------------------
|
364 |
11 |
tobiflex |
PROCESS (OP1out, OP2out, CPU, exec, add_result, bcd_pur, bcd_a, bcd_kor, halve_carry, c_in)
|
365 |
2 |
tobiflex |
BEGIN
|
366 |
|
|
--BCD_ARITH-------------------------------------------------------------------
|
367 |
|
|
--04.04.2017 by Tobiflex - BCD handling with all undefined behavior!
|
368 |
|
|
bcd_pur <= c_in(1)&add_result(8 downto 0);
|
369 |
|
|
bcd_kor <= "000000000";
|
370 |
|
|
halve_carry <= OP1out(4) XOR OP2out(4) XOR bcd_pur(5);
|
371 |
|
|
IF halve_carry='1' THEN
|
372 |
|
|
bcd_kor(3 downto 0) <= "0110"; -- -6
|
373 |
|
|
END IF;
|
374 |
|
|
IF bcd_pur(9)='1' THEN
|
375 |
|
|
bcd_kor(7 downto 4) <= "0110"; -- -60
|
376 |
|
|
END IF;
|
377 |
|
|
IF exec(opcABCD)='1' THEN
|
378 |
|
|
Vflag_a <= NOT bcd_pur(8) AND bcd_a(7);
|
379 |
|
|
-- bcd_pur <= ('0'&OP1out(7 downto 0)&'1') + ('0'&OP2out(7 downto 0)&Flags(4));
|
380 |
|
|
bcd_a <= bcd_pur(9 downto 1) + bcd_kor;
|
381 |
|
|
IF (bcd_pur(4) AND (bcd_pur(3) OR bcd_pur(2)))='1' THEN
|
382 |
|
|
bcd_kor(3 downto 0) <= "0110"; -- +6
|
383 |
|
|
END IF;
|
384 |
|
|
IF (bcd_pur(8) AND (bcd_pur(7) OR bcd_pur(6) OR (bcd_pur(5) AND bcd_pur(4) AND (bcd_pur(3) OR bcd_pur(2)))))='1' THEN
|
385 |
|
|
bcd_kor(7 downto 4) <= "0110"; -- +60
|
386 |
|
|
END IF;
|
387 |
|
|
ELSE --opcSBCD
|
388 |
|
|
Vflag_a <= bcd_pur(8) AND NOT bcd_a(7);
|
389 |
|
|
-- bcd_pur <= ('0'&OP1out(7 downto 0)&'0') - ('0'&OP2out(7 downto 0)&Flags(4));
|
390 |
|
|
bcd_a <= bcd_pur(9 downto 1) - bcd_kor;
|
391 |
|
|
END IF;
|
392 |
11 |
tobiflex |
IF cpu(1)='1' THEN
|
393 |
|
|
Vflag_a <= '0'; --68020
|
394 |
|
|
END IF;
|
395 |
2 |
tobiflex |
bcd_a_carry <= bcd_pur(9) OR bcd_a(8);
|
396 |
|
|
END PROCESS;
|
397 |
|
|
|
398 |
|
|
-----------------------------------------------------------------------------
|
399 |
|
|
-- Bits
|
400 |
|
|
-----------------------------------------------------------------------------
|
401 |
|
|
PROCESS (clk, exe_opcode, OP1out, OP2out, reg_QB, one_bit_in, bchg, bset, bit_Number, sndOPC)
|
402 |
|
|
BEGIN
|
403 |
|
|
IF rising_edge(clk) THEN
|
404 |
|
|
IF clkena_lw = '1' THEN
|
405 |
|
|
bchg <= '0';
|
406 |
|
|
bset <= '0';
|
407 |
|
|
CASE opcode(7 downto 6) IS
|
408 |
|
|
WHEN "01" => --bchg
|
409 |
|
|
bchg <= '1';
|
410 |
|
|
WHEN "11" => --bset
|
411 |
|
|
bset <= '1';
|
412 |
|
|
WHEN OTHERS => NULL;
|
413 |
|
|
END CASE;
|
414 |
|
|
END IF;
|
415 |
|
|
END IF;
|
416 |
|
|
|
417 |
|
|
IF exe_opcode(8)='0' THEN
|
418 |
|
|
IF exe_opcode(5 downto 4)="00" THEN
|
419 |
|
|
bit_number <= sndOPC(4 downto 0);
|
420 |
|
|
ELSE
|
421 |
|
|
bit_number <= "00"&sndOPC(2 downto 0);
|
422 |
|
|
END IF;
|
423 |
|
|
ELSE
|
424 |
|
|
IF exe_opcode(5 downto 4)="00" THEN
|
425 |
|
|
bit_number <= reg_QB(4 downto 0);
|
426 |
|
|
ELSE
|
427 |
|
|
bit_number <= "00"®_QB(2 downto 0);
|
428 |
|
|
END IF;
|
429 |
|
|
END IF;
|
430 |
|
|
|
431 |
|
|
one_bit_in <= OP1out(conv_integer(bit_Number));
|
432 |
|
|
bits_out <= OP1out;
|
433 |
|
|
bits_out(conv_integer(bit_Number)) <= (bchg AND NOT one_bit_in) OR bset ;
|
434 |
|
|
END PROCESS;
|
435 |
|
|
|
436 |
|
|
-----------------------------------------------------------------------------
|
437 |
|
|
-- Bit Field
|
438 |
|
|
-----------------------------------------------------------------------------
|
439 |
|
|
|
440 |
|
|
PROCESS (clk, mux, mask, bitnr, bf_ins, bf_bchg, bf_bset, bf_exts, bf_shift, inmux0, inmux1, inmux2, inmux3, bf_set2, OP1out, OP2out,
|
441 |
|
|
result_tmp, bf_ext_in, mask_not_zero, exec, shift, datareg, bf_NFlag, result, reg_QB, unshifted_bitmask, bf_d32, bf_s32,
|
442 |
|
|
shifted_bitmask, bf_loffset, bitmaskmux0, bitmaskmux1, bitmaskmux2, bitmaskmux3, bf_width)
|
443 |
|
|
BEGIN
|
444 |
|
|
IF rising_edge(clk) THEN
|
445 |
4 |
tobiflex |
IF clkena_lw = '1' THEN
|
446 |
2 |
tobiflex |
bf_bset <= '0';
|
447 |
|
|
bf_bchg <= '0';
|
448 |
|
|
bf_ins <= '0';
|
449 |
|
|
bf_exts <= '0';
|
450 |
|
|
bf_fffo <= '0';
|
451 |
|
|
bf_d32 <= '0';
|
452 |
|
|
bf_s32 <= '0';
|
453 |
5 |
tobiflex |
-- 000-bftst, 001-bfextu, 010-bfchg, 011-bfexts, 100-bfclr, 101-bfff0, 110-bfset, 111-bfins
|
454 |
|
|
IF opcode(5 downto 4) ="00" THEN
|
455 |
|
|
bf_s32 <= '1';
|
456 |
|
|
END IF;
|
457 |
2 |
tobiflex |
CASE opcode(10 downto 8) IS
|
458 |
5 |
tobiflex |
WHEN "010" => bf_bchg <= '1'; --BFCHG
|
459 |
|
|
WHEN "011" => bf_exts <= '1'; --BFEXTS
|
460 |
|
|
-- WHEN "100" => insert <= (OTHERS =>'0'); --BFCLR
|
461 |
|
|
WHEN "101" => bf_fffo <= '1'; --BFFFO
|
462 |
|
|
WHEN "110" => bf_bset <= '1'; --BFSET
|
463 |
2 |
tobiflex |
WHEN "111" => bf_ins <= '1'; --BFINS
|
464 |
5 |
tobiflex |
bf_s32 <= '1';
|
465 |
2 |
tobiflex |
WHEN OTHERS => NULL;
|
466 |
|
|
END CASE;
|
467 |
|
|
IF opcode(4 downto 3)="00" THEN
|
468 |
|
|
bf_d32 <= '1';
|
469 |
|
|
END IF;
|
470 |
|
|
bf_ext_out <= result(39 downto 32);
|
471 |
|
|
END IF;
|
472 |
|
|
END IF;
|
473 |
|
|
|
474 |
|
|
IF bf_ins='1' THEN
|
475 |
|
|
datareg <= reg_QB;
|
476 |
|
|
ELSE
|
477 |
|
|
datareg <= bf_set2;
|
478 |
|
|
END IF;
|
479 |
|
|
|
480 |
|
|
|
481 |
|
|
-- create bitmask for operation
|
482 |
|
|
-- unshifted bitmask '0' => bit is in the Bitfieldvector
|
483 |
|
|
-- '1' => bit isn't in the Bitfieldvector
|
484 |
|
|
-- Example bf_with=11 => "11111111 11111111 11111000 00000000"
|
485 |
|
|
-- datareg
|
486 |
|
|
unshifted_bitmask <= (OTHERS => '0');
|
487 |
|
|
FOR i in 0 to 31 LOOP
|
488 |
|
|
IF i>bf_width(4 downto 0) THEN
|
489 |
|
|
datareg(i) <= '0';
|
490 |
|
|
unshifted_bitmask(i) <= '1';
|
491 |
|
|
END IF;
|
492 |
|
|
END LOOP;
|
493 |
|
|
|
494 |
|
|
bf_NFlag <= datareg(conv_integer(bf_width));
|
495 |
|
|
IF bf_exts='1' AND bf_NFlag='1' THEN
|
496 |
|
|
bf_datareg <= datareg OR unshifted_bitmask;
|
497 |
|
|
ELSE
|
498 |
|
|
bf_datareg <= datareg;
|
499 |
|
|
END IF;
|
500 |
|
|
|
501 |
|
|
-- shift bitmask for operation
|
502 |
|
|
IF bf_loffset(4)='1' THEN
|
503 |
|
|
bitmaskmux3 <= unshifted_bitmask(15 downto 0)&unshifted_bitmask(31 downto 16);
|
504 |
|
|
ELSE
|
505 |
|
|
bitmaskmux3 <= unshifted_bitmask;
|
506 |
|
|
END IF;
|
507 |
|
|
IF bf_loffset(3)='1' THEN
|
508 |
|
|
bitmaskmux2(31 downto 0) <= bitmaskmux3(23 downto 0)&bitmaskmux3(31 downto 24);
|
509 |
|
|
ELSE
|
510 |
|
|
bitmaskmux2(31 downto 0) <= bitmaskmux3;
|
511 |
|
|
END IF;
|
512 |
|
|
IF bf_loffset(2)='1' THEN
|
513 |
|
|
bitmaskmux1 <= bitmaskmux2&"1111";
|
514 |
|
|
IF bf_d32='1' THEN
|
515 |
|
|
bitmaskmux1(3 downto 0) <= bitmaskmux2(31 downto 28);
|
516 |
|
|
END IF;
|
517 |
|
|
ELSE
|
518 |
|
|
bitmaskmux1 <= "1111"&bitmaskmux2;
|
519 |
|
|
END IF;
|
520 |
|
|
IF bf_loffset(1)='1' THEN
|
521 |
|
|
bitmaskmux0 <= bitmaskmux1&"11";
|
522 |
|
|
IF bf_d32='1' THEN
|
523 |
|
|
bitmaskmux0(1 downto 0) <= bitmaskmux1(31 downto 30);
|
524 |
|
|
END IF;
|
525 |
|
|
ELSE
|
526 |
|
|
bitmaskmux0 <= "11"&bitmaskmux1;
|
527 |
|
|
END IF;
|
528 |
|
|
IF bf_loffset(0)='1' THEN
|
529 |
|
|
shifted_bitmask <= '1'&bitmaskmux0&'1';
|
530 |
|
|
IF bf_d32='1' THEN
|
531 |
|
|
shifted_bitmask(0) <= bitmaskmux0(31);
|
532 |
|
|
END IF;
|
533 |
|
|
ELSE
|
534 |
|
|
shifted_bitmask <= "11"&bitmaskmux0;
|
535 |
|
|
END IF;
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
-- shift for ins
|
539 |
|
|
shift <= bf_ext_in&OP2out;
|
540 |
|
|
IF bf_s32='1' THEN
|
541 |
|
|
shift(39 downto 32) <= OP2out(7 downto 0);
|
542 |
|
|
END IF;
|
543 |
|
|
|
544 |
|
|
IF bf_shift(0)='1' THEN
|
545 |
|
|
inmux0 <= shift(0)&shift(39 downto 1);
|
546 |
|
|
ELSE
|
547 |
|
|
inmux0 <= shift;
|
548 |
|
|
END IF;
|
549 |
|
|
IF bf_shift(1)='1' THEN
|
550 |
|
|
inmux1 <= inmux0(1 downto 0)&inmux0(39 downto 2);
|
551 |
|
|
ELSE
|
552 |
|
|
inmux1 <= inmux0;
|
553 |
|
|
END IF;
|
554 |
|
|
IF bf_shift(2)='1' THEN
|
555 |
|
|
inmux2 <= inmux1(3 downto 0)&inmux1(39 downto 4);
|
556 |
|
|
ELSE
|
557 |
|
|
inmux2 <= inmux1;
|
558 |
|
|
END IF;
|
559 |
|
|
IF bf_shift(3)='1' THEN
|
560 |
|
|
inmux3 <= inmux2(7 downto 0)&inmux2(31 downto 8);
|
561 |
|
|
ELSE
|
562 |
|
|
inmux3 <= inmux2(31 downto 0);
|
563 |
|
|
END IF;
|
564 |
|
|
IF bf_shift(4)='1' THEN
|
565 |
|
|
bf_set2(31 downto 0) <= inmux3(15 downto 0)&inmux3(31 downto 16);
|
566 |
|
|
ELSE
|
567 |
|
|
bf_set2(31 downto 0) <= inmux3;
|
568 |
|
|
END IF;
|
569 |
|
|
|
570 |
|
|
IF bf_ins='1' THEN
|
571 |
|
|
result(31 downto 0) <= bf_set2;
|
572 |
|
|
result(39 downto 32) <= bf_set2(7 downto 0);
|
573 |
|
|
ELSIF bf_bchg='1' THEN
|
574 |
|
|
result(31 downto 0) <= NOT OP2out;
|
575 |
|
|
result(39 downto 32) <= NOT bf_ext_in;
|
576 |
|
|
ELSE
|
577 |
|
|
result <= (OTHERS => '0');
|
578 |
|
|
END IF;
|
579 |
|
|
IF bf_bset='1' THEN
|
580 |
|
|
result <= (OTHERS => '1');
|
581 |
|
|
END IF;
|
582 |
|
|
--
|
583 |
|
|
IF bf_ins='1' THEN
|
584 |
|
|
result_tmp <= bf_ext_in&OP1out;
|
585 |
|
|
ELSE
|
586 |
|
|
result_tmp <= bf_ext_in&OP2out;
|
587 |
|
|
END IF;
|
588 |
|
|
FOR i in 0 to 39 LOOP
|
589 |
|
|
IF shifted_bitmask(i)='1' THEN
|
590 |
|
|
result(i) <= result_tmp(i); --restore old data
|
591 |
|
|
END IF;
|
592 |
|
|
END LOOP;
|
593 |
|
|
|
594 |
|
|
--BFFFO
|
595 |
|
|
mask <= datareg;
|
596 |
|
|
bf_firstbit <= ('0'&bitnr)+mask_not_zero;
|
597 |
|
|
bitnr <= "11111";
|
598 |
|
|
mask_not_zero <= '1';
|
599 |
|
|
IF mask(31 downto 28)="0000" THEN
|
600 |
|
|
IF mask(27 downto 24)="0000" THEN
|
601 |
|
|
IF mask(23 downto 20)="0000" THEN
|
602 |
|
|
IF mask(19 downto 16)="0000" THEN
|
603 |
|
|
bitnr(4) <= '0';
|
604 |
|
|
IF mask(15 downto 12)="0000" THEN
|
605 |
|
|
IF mask(11 downto 8)="0000" THEN
|
606 |
|
|
bitnr(3) <= '0';
|
607 |
|
|
IF mask(7 downto 4)="0000" THEN
|
608 |
|
|
bitnr(2) <= '0';
|
609 |
|
|
mux <= mask(3 downto 0);
|
610 |
|
|
ELSE
|
611 |
|
|
mux <= mask(7 downto 4);
|
612 |
|
|
END IF;
|
613 |
|
|
ELSE
|
614 |
|
|
mux <= mask(11 downto 8);
|
615 |
|
|
bitnr(2) <= '0';
|
616 |
|
|
END IF;
|
617 |
|
|
ELSE
|
618 |
|
|
mux <= mask(15 downto 12);
|
619 |
|
|
END IF;
|
620 |
|
|
ELSE
|
621 |
|
|
mux <= mask(19 downto 16);
|
622 |
|
|
bitnr(3) <= '0';
|
623 |
|
|
bitnr(2) <= '0';
|
624 |
|
|
END IF;
|
625 |
|
|
ELSE
|
626 |
|
|
mux <= mask(23 downto 20);
|
627 |
|
|
bitnr(3) <= '0';
|
628 |
|
|
END IF;
|
629 |
|
|
ELSE
|
630 |
|
|
mux <= mask(27 downto 24);
|
631 |
|
|
bitnr(2) <= '0';
|
632 |
|
|
END IF;
|
633 |
|
|
ELSE
|
634 |
|
|
mux <= mask(31 downto 28);
|
635 |
|
|
END IF;
|
636 |
|
|
|
637 |
|
|
IF mux(3 downto 2)="00" THEN
|
638 |
|
|
bitnr(1) <= '0';
|
639 |
|
|
IF mux(1)='0' THEN
|
640 |
|
|
bitnr(0) <= '0';
|
641 |
|
|
IF mux(0)='0' THEN
|
642 |
|
|
mask_not_zero <= '0';
|
643 |
|
|
END IF;
|
644 |
|
|
END IF;
|
645 |
|
|
ELSE
|
646 |
|
|
IF mux(3)='0' THEN
|
647 |
|
|
bitnr(0) <= '0';
|
648 |
|
|
END IF;
|
649 |
|
|
END IF;
|
650 |
|
|
END PROCESS;
|
651 |
|
|
|
652 |
|
|
-----------------------------------------------------------------------------
|
653 |
|
|
-- Rotation
|
654 |
|
|
-----------------------------------------------------------------------------
|
655 |
|
|
PROCESS (exe_opcode, OP1out, Flags, rot_bits, rot_msb, rot_lsb, rot_rot, exec, BSout)
|
656 |
|
|
BEGIN
|
657 |
|
|
CASE exe_opcode(7 downto 6) IS
|
658 |
|
|
WHEN "00" => --Byte
|
659 |
|
|
rot_rot <= OP1out(7);
|
660 |
|
|
WHEN "01"|"11" => --Word
|
661 |
|
|
rot_rot <= OP1out(15);
|
662 |
|
|
WHEN "10" => --Long
|
663 |
|
|
rot_rot <= OP1out(31);
|
664 |
|
|
WHEN OTHERS => NULL;
|
665 |
|
|
END CASE;
|
666 |
|
|
|
667 |
|
|
CASE rot_bits IS
|
668 |
|
|
WHEN "00" => --ASL, ASR
|
669 |
|
|
rot_lsb <= '0';
|
670 |
|
|
rot_msb <= rot_rot;
|
671 |
|
|
WHEN "01" => --LSL, LSR
|
672 |
|
|
rot_lsb <= '0';
|
673 |
|
|
rot_msb <= '0';
|
674 |
|
|
WHEN "10" => --ROXL, ROXR
|
675 |
|
|
rot_lsb <= Flags(4);
|
676 |
|
|
rot_msb <= Flags(4);
|
677 |
|
|
WHEN "11" => --ROL, ROR
|
678 |
|
|
rot_lsb <= rot_rot;
|
679 |
|
|
rot_msb <= OP1out(0);
|
680 |
|
|
WHEN OTHERS => NULL;
|
681 |
|
|
END CASE;
|
682 |
|
|
|
683 |
|
|
IF exec(rot_nop)='1' THEN
|
684 |
|
|
rot_out <= OP1out;
|
685 |
|
|
rot_X <= Flags(4);
|
686 |
|
|
IF rot_bits="10" THEN --ROXL, ROXR
|
687 |
|
|
rot_C <= Flags(4);
|
688 |
|
|
ELSE
|
689 |
|
|
rot_C <= '0';
|
690 |
|
|
END IF;
|
691 |
|
|
ELSE
|
692 |
|
|
IF exe_opcode(8)='1' THEN --left
|
693 |
|
|
rot_out <= OP1out(30 downto 0)&rot_lsb;
|
694 |
|
|
rot_X <= rot_rot;
|
695 |
|
|
rot_C <= rot_rot;
|
696 |
|
|
ELSE --right
|
697 |
|
|
rot_X <= OP1out(0);
|
698 |
|
|
rot_C <= OP1out(0);
|
699 |
|
|
rot_out <= rot_msb&OP1out(31 downto 1);
|
700 |
|
|
CASE exe_opcode(7 downto 6) IS
|
701 |
|
|
WHEN "00" => --Byte
|
702 |
|
|
rot_out(7) <= rot_msb;
|
703 |
|
|
WHEN "01"|"11" => --Word
|
704 |
|
|
rot_out(15) <= rot_msb;
|
705 |
|
|
WHEN OTHERS => NULL;
|
706 |
|
|
END CASE;
|
707 |
|
|
END IF;
|
708 |
|
|
IF BarrelShifter/=0 THEN
|
709 |
|
|
rot_out <= BSout;
|
710 |
|
|
END IF;
|
711 |
|
|
END IF;
|
712 |
|
|
END PROCESS;
|
713 |
|
|
|
714 |
|
|
-----------------------------------------------------------------------------
|
715 |
|
|
-- Barrel Shifter
|
716 |
|
|
-----------------------------------------------------------------------------
|
717 |
7 |
tobiflex |
process (OP1out, OP2out, opcode, bit_nr, bit_msb, bs_shift, bs_shift_mod, ring, result_bs, exe_opcode, vector,
|
718 |
|
|
rot_bits, Flags, bs_C, msb, hot_msb, asl_over, asl_over_xor, ALU, asr_sign, exec)
|
719 |
2 |
tobiflex |
begin
|
720 |
|
|
ring <= "100000";
|
721 |
|
|
IF rot_bits="10" THEN --ROX L/R
|
722 |
|
|
CASE exe_opcode(7 downto 6) IS
|
723 |
|
|
WHEN "00" => --Byte
|
724 |
|
|
ring <= "001001";
|
725 |
|
|
WHEN "01"|"11" => --Word
|
726 |
|
|
ring <= "010001";
|
727 |
|
|
WHEN "10" => --Long
|
728 |
|
|
ring <= "100001";
|
729 |
|
|
WHEN OTHERS => NULL;
|
730 |
|
|
END CASE;
|
731 |
|
|
ELSE
|
732 |
|
|
CASE exe_opcode(7 downto 6) IS
|
733 |
|
|
WHEN "00" => --Byte
|
734 |
|
|
ring <= "001000";
|
735 |
|
|
WHEN "01"|"11" => --Word
|
736 |
|
|
ring <= "010000";
|
737 |
|
|
WHEN "10" => --Long
|
738 |
|
|
ring <= "100000";
|
739 |
|
|
WHEN OTHERS => NULL;
|
740 |
|
|
END CASE;
|
741 |
|
|
END IF;
|
742 |
|
|
|
743 |
|
|
IF exe_opcode(7 downto 6)="11" OR exec(exec_BS)='0' THEN
|
744 |
|
|
bs_shift <="000001";
|
745 |
|
|
ELSIF exe_opcode(5)='1' THEN
|
746 |
|
|
bs_shift <= OP2out(5 downto 0);
|
747 |
|
|
ELSE
|
748 |
|
|
bs_shift(2 downto 0) <= exe_opcode(11 downto 9);
|
749 |
|
|
IF exe_opcode(11 downto 9)="000" THEN
|
750 |
|
|
bs_shift(5 downto 3) <="001";
|
751 |
|
|
ELSE
|
752 |
|
|
bs_shift(5 downto 3) <="000";
|
753 |
|
|
END IF;
|
754 |
|
|
END IF;
|
755 |
|
|
|
756 |
|
|
-- calc V-Flag by ASL
|
757 |
7 |
tobiflex |
bit_msb <= "000000";
|
758 |
2 |
tobiflex |
hot_msb <= (OTHERS =>'0');
|
759 |
|
|
hot_msb(conv_integer(bit_msb)) <= '1';
|
760 |
7 |
tobiflex |
IF bs_shift < ring THEN
|
761 |
2 |
tobiflex |
bit_msb <= ring-bs_shift;
|
762 |
6 |
tobiflex |
END IF;
|
763 |
|
|
asl_over_xor <= (('0'&vector(30 downto 0)) XOR ('0'&vector(31 downto 1)))&msb;
|
764 |
|
|
CASE exe_opcode(7 downto 6) IS
|
765 |
|
|
WHEN "00" => --Byte
|
766 |
|
|
asl_over_xor(8) <= '0';
|
767 |
|
|
WHEN "01"|"11" => --Word
|
768 |
|
|
asl_over_xor(16) <= '0';
|
769 |
|
|
WHEN OTHERS => NULL;
|
770 |
|
|
END CASE;
|
771 |
|
|
asl_over <= asl_over_xor - ('0'&hot_msb(31 downto 0));
|
772 |
2 |
tobiflex |
bs_V <= '0';
|
773 |
|
|
IF rot_bits="00" AND exe_opcode(8)='1' THEN --ASL
|
774 |
|
|
bs_V <= not asl_over(32);
|
775 |
|
|
END IF;
|
776 |
|
|
|
777 |
7 |
tobiflex |
bs_X <= bs_C;
|
778 |
2 |
tobiflex |
IF exe_opcode(8)='0' THEN --right shift
|
779 |
|
|
bs_C <= result_bs(31);
|
780 |
|
|
ELSE --left shift
|
781 |
|
|
CASE exe_opcode(7 downto 6) IS
|
782 |
|
|
WHEN "00" => --Byte
|
783 |
|
|
bs_C <= result_bs(8);
|
784 |
|
|
WHEN "01"|"11" => --Word
|
785 |
|
|
bs_C <= result_bs(16);
|
786 |
|
|
WHEN "10" => --Long
|
787 |
|
|
bs_C <= result_bs(32);
|
788 |
|
|
WHEN OTHERS => NULL;
|
789 |
|
|
END CASE;
|
790 |
|
|
END IF;
|
791 |
|
|
|
792 |
|
|
ALU <= (others=>'-');
|
793 |
|
|
IF rot_bits="11" THEN --RO L/R
|
794 |
|
|
bs_X <= Flags(4);
|
795 |
|
|
CASE exe_opcode(7 downto 6) IS
|
796 |
|
|
WHEN "00" => --Byte
|
797 |
|
|
ALU(7 downto 0) <= result_bs(7 downto 0) OR result_bs(15 downto 8);
|
798 |
6 |
tobiflex |
bs_C <= ALU(7);
|
799 |
2 |
tobiflex |
WHEN "01"|"11" => --Word
|
800 |
|
|
ALU(15 downto 0) <= result_bs(15 downto 0) OR result_bs(31 downto 16);
|
801 |
6 |
tobiflex |
bs_C <= ALU(15);
|
802 |
2 |
tobiflex |
WHEN "10" => --Long
|
803 |
|
|
ALU <= result_bs(31 downto 0) OR result_bs(63 downto 32);
|
804 |
6 |
tobiflex |
bs_C <= ALU(31);
|
805 |
2 |
tobiflex |
WHEN OTHERS => NULL;
|
806 |
|
|
END CASE;
|
807 |
6 |
tobiflex |
IF exe_opcode(8)='1' THEN --left shift
|
808 |
2 |
tobiflex |
bs_C <= ALU(0);
|
809 |
|
|
END IF;
|
810 |
|
|
ELSIF rot_bits="10" THEN --ROX L/R
|
811 |
|
|
CASE exe_opcode(7 downto 6) IS
|
812 |
|
|
WHEN "00" => --Byte
|
813 |
|
|
ALU(7 downto 0) <= result_bs(7 downto 0) OR result_bs(16 downto 9);
|
814 |
|
|
bs_C <= result_bs(8) OR result_bs(17);
|
815 |
|
|
WHEN "01"|"11" => --Word
|
816 |
|
|
ALU(15 downto 0) <= result_bs(15 downto 0) OR result_bs(32 downto 17);
|
817 |
|
|
bs_C <= result_bs(16) OR result_bs(33);
|
818 |
|
|
WHEN "10" => --Long
|
819 |
|
|
ALU <= result_bs(31 downto 0) OR result_bs(64 downto 33);
|
820 |
|
|
bs_C <= result_bs(32) OR result_bs(65);
|
821 |
|
|
WHEN OTHERS => NULL;
|
822 |
|
|
END CASE;
|
823 |
|
|
ELSE
|
824 |
|
|
IF exe_opcode(8)='0' THEN --right shift
|
825 |
|
|
ALU <= result_bs(63 downto 32);
|
826 |
|
|
ELSE --left shift
|
827 |
|
|
ALU <= result_bs(31 downto 0);
|
828 |
|
|
END IF;
|
829 |
|
|
END IF;
|
830 |
|
|
|
831 |
|
|
IF(bs_shift = "000000") THEN
|
832 |
|
|
IF rot_bits="10" THEN --ROX L/R
|
833 |
6 |
tobiflex |
bs_C <= Flags(4);
|
834 |
2 |
tobiflex |
ELSE
|
835 |
6 |
tobiflex |
bs_C <= '0';
|
836 |
2 |
tobiflex |
END IF;
|
837 |
|
|
bs_X <= Flags(4);
|
838 |
|
|
bs_V <= '0';
|
839 |
|
|
END IF;
|
840 |
|
|
|
841 |
7 |
tobiflex |
-- calc shift count
|
842 |
|
|
bs_shift_mod <= std_logic_vector(unsigned(bs_shift) rem unsigned(ring));
|
843 |
|
|
bit_nr <= bs_shift_mod(5 downto 0);
|
844 |
|
|
IF exe_opcode(8)='0' THEN --right shift
|
845 |
|
|
bit_nr <= ring-bs_shift_mod;
|
846 |
|
|
END IF;
|
847 |
|
|
IF rot_bits(1)='0' THEN --only shift
|
848 |
|
|
IF exe_opcode(8)='0' THEN --right shift
|
849 |
|
|
bit_nr <= 32-bs_shift_mod;
|
850 |
|
|
END IF;
|
851 |
|
|
IF bs_shift = ring THEN
|
852 |
|
|
IF exe_opcode(8)='0' THEN --right shift
|
853 |
|
|
bit_nr <= 32-ring;
|
854 |
|
|
ELSE
|
855 |
|
|
bit_nr <= ring;
|
856 |
|
|
END IF;
|
857 |
|
|
END IF;
|
858 |
|
|
IF bs_shift > ring THEN
|
859 |
|
|
IF exe_opcode(8)='0' THEN --right shift
|
860 |
|
|
bit_nr <= "000000";
|
861 |
|
|
bs_C <= '0';
|
862 |
|
|
ELSE
|
863 |
|
|
bit_nr <= ring+1;
|
864 |
|
|
END IF;
|
865 |
|
|
END IF;
|
866 |
|
|
END IF;
|
867 |
|
|
|
868 |
2 |
tobiflex |
-- calc ASR sign
|
869 |
|
|
BSout <= ALU;
|
870 |
|
|
asr_sign <= (OTHERS =>'0');
|
871 |
|
|
asr_sign(32 downto 1) <= asr_sign(31 downto 0) OR hot_msb(31 downto 0);
|
872 |
|
|
IF rot_bits="00" AND exe_opcode(8)='0' AND msb='1' THEN --ASR
|
873 |
|
|
BSout <= ALU or asr_sign(32 downto 1);
|
874 |
|
|
IF bs_shift > ring THEN
|
875 |
|
|
bs_C <= '1';
|
876 |
|
|
END IF;
|
877 |
|
|
END IF;
|
878 |
|
|
|
879 |
|
|
vector(32 downto 0) <= '0'&OP1out;
|
880 |
|
|
CASE exe_opcode(7 downto 6) IS
|
881 |
|
|
WHEN "00" => --Byte
|
882 |
|
|
msb <= OP1out(7);
|
883 |
|
|
vector(31 downto 8) <= X"000000";
|
884 |
|
|
BSout(31 downto 8) <= X"000000";
|
885 |
|
|
IF rot_bits="10" THEN --ROX L/R
|
886 |
|
|
vector(8) <= Flags(4);
|
887 |
|
|
END IF;
|
888 |
|
|
WHEN "01"|"11" => --Word
|
889 |
|
|
msb <= OP1out(15);
|
890 |
|
|
vector(31 downto 16) <= X"0000";
|
891 |
|
|
BSout(31 downto 16) <= X"0000";
|
892 |
|
|
IF rot_bits="10" THEN --ROX L/R
|
893 |
|
|
vector(16) <= Flags(4);
|
894 |
|
|
END IF;
|
895 |
|
|
WHEN "10" => --Long
|
896 |
|
|
msb <= OP1out(31);
|
897 |
|
|
IF rot_bits="10" THEN --ROX L/R
|
898 |
|
|
vector(32) <= Flags(4);
|
899 |
|
|
END IF;
|
900 |
|
|
WHEN OTHERS => NULL;
|
901 |
|
|
END CASE;
|
902 |
7 |
tobiflex |
result_bs <= std_logic_vector(unsigned('0'&X"00000000"&vector) sll to_integer(unsigned(bit_nr(5 downto 0))));
|
903 |
2 |
tobiflex |
|
904 |
|
|
end process;
|
905 |
|
|
|
906 |
|
|
|
907 |
|
|
------------------------------------------------------------------------------
|
908 |
|
|
--CCR op
|
909 |
|
|
------------------------------------------------------------------------------
|
910 |
|
|
PROCESS (clk, Reset, exe_opcode, exe_datatype, Flags, last_data_read, OP2out, flag_z, OP1IN, c_out, addsub_ofl,
|
911 |
|
|
bcd_a, bcd_a_carry, Vflag_a, exec)
|
912 |
|
|
BEGIN
|
913 |
|
|
IF exec(andiSR)='1' THEN
|
914 |
|
|
CCRin <= Flags AND last_data_read(7 downto 0);
|
915 |
|
|
ELSIF exec(eoriSR)='1' THEN
|
916 |
|
|
CCRin <= Flags XOR last_data_read(7 downto 0);
|
917 |
|
|
ELSIF exec(oriSR)='1' THEN
|
918 |
|
|
CCRin <= Flags OR last_data_read(7 downto 0);
|
919 |
|
|
ELSE
|
920 |
|
|
CCRin <= OP2out(7 downto 0);
|
921 |
|
|
END IF;
|
922 |
|
|
|
923 |
|
|
------------------------------------------------------------------------------
|
924 |
|
|
--Flags
|
925 |
|
|
------------------------------------------------------------------------------
|
926 |
|
|
flag_z <= "000";
|
927 |
|
|
IF exec(use_XZFlag)='1' AND flags(2)='0' THEN
|
928 |
|
|
flag_z <= "000";
|
929 |
|
|
ELSIF OP1in(7 downto 0)="00000000" THEN
|
930 |
|
|
flag_z(0) <= '1';
|
931 |
|
|
IF OP1in(15 downto 8)="00000000" THEN
|
932 |
|
|
flag_z(1) <= '1';
|
933 |
|
|
IF OP1in(31 downto 16)="0000000000000000" THEN
|
934 |
|
|
flag_z(2) <= '1';
|
935 |
|
|
END IF;
|
936 |
|
|
END IF;
|
937 |
|
|
END IF;
|
938 |
|
|
|
939 |
|
|
-- --Flags NZVC
|
940 |
|
|
IF exe_datatype="00" THEN --Byte
|
941 |
|
|
set_flags <= OP1IN(7)&flag_z(0)&addsub_ofl(0)&c_out(0);
|
942 |
|
|
IF exec(opcABCD)='1' OR exec(opcSBCD)='1' THEN
|
943 |
|
|
set_flags(0) <= bcd_a_carry;
|
944 |
|
|
set_flags(1) <= Vflag_a;
|
945 |
|
|
END IF;
|
946 |
|
|
ELSIF exe_datatype="10" OR exec(opcCPMAW)='1' THEN --Long
|
947 |
|
|
set_flags <= OP1IN(31)&flag_z(2)&addsub_ofl(2)&c_out(2);
|
948 |
|
|
ELSE --Word
|
949 |
|
|
set_flags <= OP1IN(15)&flag_z(1)&addsub_ofl(1)&c_out(1);
|
950 |
|
|
END IF;
|
951 |
|
|
|
952 |
|
|
IF rising_edge(clk) THEN
|
953 |
6 |
tobiflex |
IF Reset='1' THEN
|
954 |
4 |
tobiflex |
Flags(7 downto 0) <= "00000000";
|
955 |
6 |
tobiflex |
ELSIF clkena_lw = '1' THEN
|
956 |
2 |
tobiflex |
IF exec(directSR)='1' OR set_stop='1' THEN
|
957 |
|
|
Flags(7 downto 0) <= data_read(7 downto 0);
|
958 |
|
|
END IF;
|
959 |
|
|
IF exec(directCCR)='1' THEN
|
960 |
|
|
Flags(7 downto 0) <= data_read(7 downto 0);
|
961 |
|
|
END IF;
|
962 |
|
|
|
963 |
|
|
IF exec(opcROT)='1' AND decodeOPC='0' THEN
|
964 |
|
|
asl_VFlag <= ((set_flags(3) XOR rot_rot) OR asl_VFlag);
|
965 |
|
|
ELSE
|
966 |
|
|
asl_VFlag <= '0';
|
967 |
|
|
END IF;
|
968 |
|
|
IF exec(to_CCR)='1' THEN
|
969 |
|
|
Flags(7 downto 0) <= CCRin(7 downto 0); --CCR
|
970 |
|
|
ELSIF Z_error='1' THEN
|
971 |
|
|
IF exe_opcode(8)='0' THEN
|
972 |
|
|
-- Flags(3 downto 0) <= reg_QA(31)&"000";
|
973 |
|
|
Flags(3 downto 0) <= '0'&NOT reg_QA(31)&"00";
|
974 |
|
|
ELSE
|
975 |
|
|
Flags(3 downto 0) <= "0100";
|
976 |
|
|
END IF;
|
977 |
|
|
ELSIF exec(no_Flags)='0' THEN
|
978 |
11 |
tobiflex |
last_Flags1 <= Flags(3 downto 0);
|
979 |
2 |
tobiflex |
IF exec(opcADD)='1' THEN
|
980 |
|
|
Flags(4) <= set_flags(0);
|
981 |
|
|
ELSIF exec(opcROT)='1' AND rot_bits/="11" AND exec(rot_nop)='0' THEN
|
982 |
|
|
Flags(4) <= rot_X;
|
983 |
|
|
ELSIF exec(exec_BS)='1' THEN
|
984 |
|
|
Flags(4) <= BS_X;
|
985 |
|
|
END IF;
|
986 |
|
|
|
987 |
11 |
tobiflex |
-- IF (exec(opcADD) OR exec(opcCMP))='1' OR exec(alu_setFlags)='1' THEN
|
988 |
|
|
IF (exec(opcCMP) OR exec(alu_setFlags))='1' THEN
|
989 |
2 |
tobiflex |
Flags(3 downto 0) <= set_flags;
|
990 |
|
|
ELSIF exec(opcDIVU)='1' AND DIV_Mode/=3 THEN
|
991 |
|
|
IF V_Flag='1' THEN
|
992 |
|
|
Flags(3 downto 0) <= "1010";
|
993 |
10 |
tobiflex |
ELSIF exe_opcode(15)='1' OR DIV_Mode=0 THEN
|
994 |
|
|
Flags(3 downto 0) <= OP1IN(15)&flag_z(1)&"00";
|
995 |
2 |
tobiflex |
ELSE
|
996 |
10 |
tobiflex |
Flags(3 downto 0) <= OP1IN(31)&flag_z(2)&"00";
|
997 |
2 |
tobiflex |
END IF;
|
998 |
|
|
ELSIF exec(write_reminder)='1' AND MUL_Mode/=3 THEN -- z-flag MULU.l
|
999 |
|
|
Flags(3) <= set_flags(3);
|
1000 |
|
|
Flags(2) <= set_flags(2) AND Flags(2);
|
1001 |
|
|
Flags(1) <= '0';
|
1002 |
|
|
Flags(0) <= '0';
|
1003 |
|
|
ELSIF exec(write_lowlong)='1' AND (MUL_Mode=1 OR MUL_Mode=2) THEN -- flag MULU.l
|
1004 |
|
|
Flags(3) <= set_flags(3);
|
1005 |
|
|
Flags(2) <= set_flags(2);
|
1006 |
|
|
Flags(1) <= set_mV_Flag; --V
|
1007 |
|
|
Flags(0) <= '0';
|
1008 |
|
|
ELSIF exec(opcOR)='1' OR exec(opcAND)='1' OR exec(opcEOR)='1' OR exec(opcMOVE)='1' OR exec(opcMOVEQ)='1' OR exec(opcSWAP)='1' OR exec(opcBF)='1' OR (exec(opcMULU)='1' AND MUL_Mode/=3) THEN
|
1009 |
|
|
Flags(1 downto 0) <= "00";
|
1010 |
|
|
Flags(3 downto 2) <= set_flags(3 downto 2);
|
1011 |
|
|
IF exec(opcBF)='1' THEN
|
1012 |
|
|
Flags(3) <= bf_NFlag;
|
1013 |
|
|
END IF;
|
1014 |
|
|
ELSIF exec(opcROT)='1' THEN
|
1015 |
|
|
Flags(3 downto 2) <= set_flags(3 downto 2);
|
1016 |
|
|
Flags(0) <= rot_C;
|
1017 |
|
|
IF rot_bits="00" AND ((set_flags(3) XOR rot_rot) OR asl_VFlag)='1' THEN --ASL/ASR
|
1018 |
|
|
Flags(1) <= '1';
|
1019 |
|
|
ELSE
|
1020 |
|
|
Flags(1) <= '0';
|
1021 |
|
|
END IF;
|
1022 |
|
|
ELSIF exec(exec_BS)='1' THEN
|
1023 |
|
|
Flags(3 downto 2) <= set_flags(3 downto 2);
|
1024 |
|
|
Flags(0) <= BS_C;
|
1025 |
|
|
Flags(1) <= BS_V;
|
1026 |
|
|
ELSIF exec(opcBITS)='1' THEN
|
1027 |
|
|
Flags(2) <= NOT one_bit_in;
|
1028 |
11 |
tobiflex |
ELSIF exec(opcCHK2)='1' THEN
|
1029 |
|
|
Flags(0) <= '0';
|
1030 |
|
|
Flags(2) <= Flags(2) OR set_flags(2);
|
1031 |
|
|
----lower bound first
|
1032 |
|
|
IF last_Flags1(0)='0' THEN --unsigned OP
|
1033 |
|
|
Flags(0) <= Flags(0) OR (NOT set_flags(0) AND NOT set_flags(2));
|
1034 |
|
|
ELSE --signed OP
|
1035 |
|
|
Flags(0) <= (Flags(3) AND NOT Flags(1)) OR (NOT Flags(3) AND Flags(1)) OR --LT
|
1036 |
|
|
(set_flags(3) AND set_flags(1) AND NOT set_flags(2)) OR (NOT set_flags(3) AND NOT set_flags(1) AND NOT set_flags(2)); --GT
|
1037 |
|
|
END IF;
|
1038 |
2 |
tobiflex |
ELSIF exec(opcCHK)='1' THEN
|
1039 |
|
|
IF exe_datatype="01" THEN --Word
|
1040 |
|
|
Flags(3) <= OP1out(15);
|
1041 |
|
|
ELSE
|
1042 |
|
|
Flags(3) <= OP1out(31);
|
1043 |
|
|
END IF;
|
1044 |
|
|
IF OP1out(15 downto 0)=X"0000" AND (exe_datatype="01" OR OP1out(31 downto 16)=X"0000") THEN
|
1045 |
|
|
Flags(2) <='1';
|
1046 |
|
|
ELSE
|
1047 |
|
|
Flags(2) <='0';
|
1048 |
|
|
END IF;
|
1049 |
10 |
tobiflex |
Flags(1) <= '0';
|
1050 |
11 |
tobiflex |
Flags(0) <= '0';
|
1051 |
2 |
tobiflex |
END IF;
|
1052 |
|
|
END IF;
|
1053 |
|
|
END IF;
|
1054 |
|
|
Flags(7 downto 5) <= "000";
|
1055 |
|
|
END IF;
|
1056 |
|
|
END PROCESS;
|
1057 |
|
|
|
1058 |
|
|
---------------------------------------------------------------------------------
|
1059 |
|
|
------ MULU/MULS
|
1060 |
|
|
---------------------------------------------------------------------------------
|
1061 |
|
|
PROCESS (exe_opcode, OP2out, muls_msb, mulu_reg, FAsign, mulu_sign, reg_QA, faktorA, faktorB, result_mulu, signedOP)
|
1062 |
|
|
--PROCESS (exec, reg_QA, OP2out, faktorA, faktorB, signedOP)
|
1063 |
|
|
BEGIN
|
1064 |
|
|
IF MUL_Hardware=1 THEN
|
1065 |
|
|
-- IF exe_opcode(15)='1' OR MUL_Mode=0 THEN -- 16 Bit
|
1066 |
|
|
IF MUL_Mode=0 THEN -- 16 Bit
|
1067 |
|
|
IF signedOP='1' AND reg_QA(15)='1' THEN
|
1068 |
|
|
faktorA <= X"FFFFFFFF";
|
1069 |
|
|
ELSE
|
1070 |
|
|
faktorA <= X"00000000";
|
1071 |
|
|
END IF;
|
1072 |
|
|
IF signedOP='1' AND OP2out(15)='1' THEN
|
1073 |
|
|
faktorB <= X"FFFFFFFF";
|
1074 |
|
|
ELSE
|
1075 |
|
|
faktorB <= X"00000000";
|
1076 |
|
|
END IF;
|
1077 |
|
|
result_mulu(63 downto 0) <= (faktorA(15 downto 0) & reg_QA(15 downto 0)) * (faktorB(15 downto 0) & OP2out(15 downto 0));
|
1078 |
|
|
ELSE
|
1079 |
|
|
IF exe_opcode(15)='1' THEN -- 16 Bit
|
1080 |
|
|
IF signedOP='1' AND reg_QA(15)='1' THEN
|
1081 |
|
|
faktorA <= X"FFFFFFFF";
|
1082 |
|
|
ELSE
|
1083 |
|
|
faktorA <= X"00000000";
|
1084 |
|
|
END IF;
|
1085 |
|
|
IF signedOP='1' AND OP2out(15)='1' THEN
|
1086 |
|
|
faktorB <= X"FFFFFFFF";
|
1087 |
|
|
ELSE
|
1088 |
|
|
faktorB <= X"00000000";
|
1089 |
|
|
END IF;
|
1090 |
|
|
ELSE
|
1091 |
|
|
faktorA(15 downto 0) <= reg_QA(31 downto 16);
|
1092 |
|
|
faktorB(15 downto 0) <= OP2out(31 downto 16);
|
1093 |
|
|
IF signedOP='1' AND reg_QA(31)='1' THEN
|
1094 |
|
|
faktorA(31 downto 16) <= X"FFFF";
|
1095 |
|
|
ELSE
|
1096 |
|
|
faktorA(31 downto 16) <= X"0000";
|
1097 |
|
|
END IF;
|
1098 |
|
|
IF signedOP='1' AND OP2out(31)='1' THEN
|
1099 |
|
|
faktorB(31 downto 16) <= X"FFFF";
|
1100 |
|
|
ELSE
|
1101 |
|
|
faktorB(31 downto 16) <= X"0000";
|
1102 |
|
|
END IF;
|
1103 |
|
|
END IF;
|
1104 |
|
|
result_mulu(127 downto 0) <= (faktorA(31 downto 16) & faktorA(31 downto 0) & reg_QA(15 downto 0)) * (faktorB(31 downto 16) & faktorB(31 downto 0) & OP2out(15 downto 0));
|
1105 |
|
|
END IF;
|
1106 |
|
|
-- END PROCESS;
|
1107 |
|
|
-------------------------------------------------------------------------------
|
1108 |
|
|
---- MULU/MULS
|
1109 |
|
|
-------------------------------------------------------------------------------
|
1110 |
|
|
--PROCESS (exe_opcode, OP2out, muls_msb, mulu_reg, FAsign, mulu_sign, reg_QA, faktorB, result_mulu, signedOP)
|
1111 |
|
|
-- BEGIN
|
1112 |
|
|
ELSE
|
1113 |
|
|
IF (signedOP='1' AND faktorB(31)='1') OR FAsign='1' THEN
|
1114 |
|
|
muls_msb <= mulu_reg(63);
|
1115 |
|
|
ELSE
|
1116 |
|
|
muls_msb <= '0';
|
1117 |
|
|
END IF;
|
1118 |
|
|
|
1119 |
|
|
IF signedOP='1' AND faktorB(31)='1' THEN
|
1120 |
|
|
mulu_sign <= '1';
|
1121 |
|
|
ELSE
|
1122 |
|
|
mulu_sign <= '0';
|
1123 |
|
|
END IF;
|
1124 |
|
|
|
1125 |
|
|
IF MUL_Mode=0 THEN -- 16 Bit
|
1126 |
|
|
result_mulu(63 downto 32) <= muls_msb&mulu_reg(63 downto 33);
|
1127 |
|
|
result_mulu(15 downto 0) <= 'X'&mulu_reg(15 downto 1);
|
1128 |
|
|
IF mulu_reg(0)='1' THEN
|
1129 |
|
|
IF FAsign='1' THEN
|
1130 |
|
|
result_mulu(63 downto 47) <= (muls_msb&mulu_reg(63 downto 48)-(mulu_sign&faktorB(31 downto 16)));
|
1131 |
|
|
ELSE
|
1132 |
|
|
result_mulu(63 downto 47) <= (muls_msb&mulu_reg(63 downto 48)+(mulu_sign&faktorB(31 downto 16)));
|
1133 |
|
|
END IF;
|
1134 |
|
|
END IF;
|
1135 |
|
|
ELSE -- 32 Bit
|
1136 |
|
|
result_mulu(63 downto 0) <= muls_msb&mulu_reg(63 downto 1);
|
1137 |
|
|
IF mulu_reg(0)='1' THEN
|
1138 |
|
|
IF FAsign='1' THEN
|
1139 |
|
|
result_mulu(63 downto 31) <= (muls_msb&mulu_reg(63 downto 32)-(mulu_sign&faktorB));
|
1140 |
|
|
ELSE
|
1141 |
|
|
result_mulu(63 downto 31) <= (muls_msb&mulu_reg(63 downto 32)+(mulu_sign&faktorB));
|
1142 |
|
|
END IF;
|
1143 |
|
|
END IF;
|
1144 |
|
|
END IF;
|
1145 |
|
|
IF exe_opcode(15)='1' OR MUL_Mode=0 THEN
|
1146 |
|
|
faktorB(31 downto 16) <= OP2out(15 downto 0);
|
1147 |
|
|
faktorB(15 downto 0) <= (OTHERS=>'0');
|
1148 |
|
|
ELSE
|
1149 |
|
|
faktorB <= OP2out;
|
1150 |
|
|
END IF;
|
1151 |
|
|
END IF;
|
1152 |
|
|
IF (result_mulu(63 downto 32)=X"00000000" AND (signedOP='0' OR result_mulu(31)='0')) OR
|
1153 |
|
|
(result_mulu(63 downto 32)=X"FFFFFFFF" AND signedOP='1' AND result_mulu(31)='1') THEN
|
1154 |
|
|
set_mV_Flag <= '0';
|
1155 |
|
|
ELSE
|
1156 |
|
|
set_mV_Flag <= '1';
|
1157 |
|
|
END IF;
|
1158 |
|
|
END PROCESS;
|
1159 |
|
|
|
1160 |
|
|
PROCESS (clk)
|
1161 |
|
|
BEGIN
|
1162 |
|
|
IF rising_edge(clk) THEN
|
1163 |
|
|
IF clkena_lw='1' THEN
|
1164 |
|
|
IF MUL_Hardware=0 THEN
|
1165 |
|
|
IF micro_state=mul1 THEN
|
1166 |
|
|
mulu_reg(63 downto 32) <= (OTHERS=>'0');
|
1167 |
|
|
IF divs='1' AND ((exe_opcode(15)='1' AND reg_QA(15)='1') OR (exe_opcode(15)='0' AND reg_QA(31)='1')) THEN --MULS Neg faktor
|
1168 |
|
|
FAsign <= '1';
|
1169 |
|
|
mulu_reg(31 downto 0) <= 0-reg_QA;
|
1170 |
|
|
ELSE
|
1171 |
|
|
FAsign <= '0';
|
1172 |
|
|
mulu_reg(31 downto 0) <= reg_QA;
|
1173 |
|
|
END IF;
|
1174 |
|
|
ELSIF exec(opcMULU)='0' THEN
|
1175 |
|
|
mulu_reg <= result_mulu(63 downto 0);
|
1176 |
|
|
END IF;
|
1177 |
|
|
ELSE
|
1178 |
|
|
mulu_reg(31 downto 0) <= result_mulu(63 downto 32);
|
1179 |
|
|
END IF;
|
1180 |
|
|
END IF;
|
1181 |
|
|
END IF;
|
1182 |
|
|
END PROCESS;
|
1183 |
|
|
|
1184 |
|
|
-------------------------------------------------------------------------------
|
1185 |
|
|
---- DIVU/DIVS
|
1186 |
|
|
-------------------------------------------------------------------------------
|
1187 |
|
|
|
1188 |
|
|
PROCESS (execOPC, OP1out, OP2out, div_reg, div_neg, div_bit, div_sub, div_quot, OP1_sign, div_over, result_div, reg_QA, opcode, sndOPC, divs, exe_opcode, reg_QB,
|
1189 |
|
|
signedOP, nozero, div_qsign, OP2outext)
|
1190 |
|
|
BEGIN
|
1191 |
|
|
divs <= (opcode(15) AND opcode(8)) OR (NOT opcode(15) AND sndOPC(11));
|
1192 |
11 |
tobiflex |
divident(15 downto 0) <= (OTHERS=> '0');
|
1193 |
|
|
divident(63 downto 32) <= (OTHERS=> divs AND reg_QA(31));
|
1194 |
2 |
tobiflex |
IF exe_opcode(15)='1' OR DIV_Mode=0 THEN
|
1195 |
11 |
tobiflex |
divident(47 downto 16) <= reg_QA;
|
1196 |
2 |
tobiflex |
ELSE
|
1197 |
11 |
tobiflex |
divident(31 downto 0) <= reg_QA;
|
1198 |
2 |
tobiflex |
IF exe_opcode(14)='1' AND sndOPC(10)='1' THEN
|
1199 |
11 |
tobiflex |
divident(63 downto 32) <= reg_QB;
|
1200 |
2 |
tobiflex |
END IF;
|
1201 |
|
|
END IF;
|
1202 |
|
|
IF signedOP='1' OR opcode(15)='0' THEN
|
1203 |
|
|
OP2outext <= OP2out(31 downto 16);
|
1204 |
|
|
ELSE
|
1205 |
|
|
OP2outext <= (OTHERS=> '0');
|
1206 |
|
|
END IF;
|
1207 |
|
|
IF signedOP='1' AND OP2out(31) ='1' THEN
|
1208 |
|
|
div_sub <= (div_reg(63 downto 31))+('1'&OP2out(31 downto 0));
|
1209 |
|
|
ELSE
|
1210 |
|
|
div_sub <= (div_reg(63 downto 31))-('0'&OP2outext(15 downto 0)&OP2out(15 downto 0));
|
1211 |
|
|
END IF;
|
1212 |
|
|
IF DIV_Mode=0 THEN
|
1213 |
|
|
div_bit <= div_sub(16);
|
1214 |
|
|
ELSE
|
1215 |
|
|
div_bit <= div_sub(32);
|
1216 |
|
|
END IF;
|
1217 |
|
|
IF div_bit='1' THEN
|
1218 |
|
|
div_quot(63 downto 32) <= div_reg(62 downto 31);
|
1219 |
|
|
ELSE
|
1220 |
|
|
div_quot(63 downto 32) <= div_sub(31 downto 0);
|
1221 |
|
|
END IF;
|
1222 |
|
|
div_quot(31 downto 0) <= div_reg(30 downto 0)&NOT div_bit;
|
1223 |
|
|
|
1224 |
|
|
|
1225 |
|
|
IF ((nozero='1' AND signedOP='1' AND (OP2out(31) XOR OP1_sign XOR div_neg XOR div_qsign)='1' ) --Overflow DIVS
|
1226 |
|
|
OR (signedOP='0' AND div_over(32)='0')) AND DIV_Mode/=3 THEN --Overflow DIVU
|
1227 |
|
|
set_V_Flag <= '1';
|
1228 |
|
|
ELSE
|
1229 |
|
|
set_V_Flag <= '0';
|
1230 |
|
|
END IF;
|
1231 |
|
|
END PROCESS;
|
1232 |
|
|
|
1233 |
|
|
PROCESS (clk)
|
1234 |
|
|
BEGIN
|
1235 |
|
|
IF rising_edge(clk) THEN
|
1236 |
|
|
IF clkena_lw='1' THEN
|
1237 |
|
|
V_Flag <= set_V_Flag;
|
1238 |
|
|
signedOP <= divs;
|
1239 |
|
|
IF micro_state=div1 THEN
|
1240 |
|
|
nozero <= '0';
|
1241 |
11 |
tobiflex |
IF divs='1' AND divident(63)='1' THEN -- Neg divident
|
1242 |
2 |
tobiflex |
OP1_sign <= '1';
|
1243 |
11 |
tobiflex |
div_reg <= 0-divident;
|
1244 |
2 |
tobiflex |
ELSE
|
1245 |
|
|
OP1_sign <= '0';
|
1246 |
11 |
tobiflex |
div_reg <= divident;
|
1247 |
2 |
tobiflex |
END IF;
|
1248 |
|
|
ELSE
|
1249 |
|
|
div_reg <= div_quot;
|
1250 |
|
|
nozero <= NOT div_bit OR nozero;
|
1251 |
|
|
END IF;
|
1252 |
|
|
IF micro_state=div2 THEN
|
1253 |
|
|
div_qsign <= NOT div_bit;
|
1254 |
|
|
div_neg <= signedOP AND (OP2out(31) XOR OP1_sign);
|
1255 |
|
|
IF DIV_Mode=0 THEN
|
1256 |
|
|
div_over(32 downto 16) <= ('0'&div_reg(47 downto 32))-('0'&OP2out(15 downto 0));
|
1257 |
|
|
ELSE
|
1258 |
|
|
div_over <= ('0'&div_reg(63 downto 32))-('0'&OP2out);
|
1259 |
|
|
END IF;
|
1260 |
|
|
END IF;
|
1261 |
|
|
IF exec(write_reminder)='0' THEN
|
1262 |
|
|
-- IF exec_DIVU='0' THEN
|
1263 |
|
|
IF div_neg='1' THEN
|
1264 |
|
|
result_div(31 downto 0) <= 0-div_quot(31 downto 0);
|
1265 |
|
|
ELSE
|
1266 |
|
|
result_div(31 downto 0) <= div_quot(31 downto 0);
|
1267 |
|
|
END IF;
|
1268 |
|
|
|
1269 |
|
|
IF OP1_sign='1' THEN
|
1270 |
|
|
result_div(63 downto 32) <= 0-div_quot(63 downto 32);
|
1271 |
|
|
ELSE
|
1272 |
|
|
result_div(63 downto 32) <= div_quot(63 downto 32);
|
1273 |
|
|
END IF;
|
1274 |
|
|
END IF;
|
1275 |
|
|
END IF;
|
1276 |
|
|
END IF;
|
1277 |
|
|
END PROCESS;
|
1278 |
|
|
END;
|