OpenCores
URL https://opencores.org/ocsvn/pavr/pavr/trunk

Subversion Repositories pavr

[/] [pavr/] [trunk/] [src/] [pavr_alu.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 doru
-- <File header>
2
-- Project
3
--    pAVR (pipelined AVR) is an 8 bit RISC controller, compatible with Atmel's
4
--    AVR core, but about 3x faster in terms of both clock frequency and MIPS.
5
--    The increase in speed comes from a relatively deep pipeline. The original
6
--    AVR core has only two pipeline stages (fetch and execute), while pAVR has
7
--    6 pipeline stages:
8
--       1. PM    (read Program Memory)
9
--       2. INSTR (load Instruction)
10
--       3. RFRD  (decode Instruction and read Register File)
11
--       4. OPS   (load Operands)
12
--       5. ALU   (execute ALU opcode or access Unified Memory)
13
--       6. RFWR  (write Register File)
14
-- Version
15
--    0.32
16
-- Date
17
--    2002 August 07
18
-- Author
19
--    Doru Cuturela, doruu@yahoo.com
20
-- License
21
--    This program is free software; you can redistribute it and/or modify
22
--    it under the terms of the GNU General Public License as published by
23
--    the Free Software Foundation; either version 2 of the License, or
24
--    (at your option) any later version.
25
--    This program is distributed in the hope that it will be useful,
26
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
27
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
--    GNU General Public License for more details.
29
--    You should have received a copy of the GNU General Public License
30
--    along with this program; if not, write to the Free Software
31
--    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
-- </File header>
33
 
34
 
35
 
36
-- <File info>
37
-- This is pAVR's ALU.
38
-- The ALU asychronousely computes:
39
--    - output
40
--    - output flags,
41
--    based on:
42
--    - input 1
43
--    - input 2
44
--    - input flags
45
-- Flags:
46
--    - C (cary)
47
--    - Z (zero)
48
--    - N (negative)
49
--    - V (two's complement overflow)
50
--    - S (N xor V, for signed tests)
51
--    - H (half carry)
52
--       *** The half carry is computed as specified in the AVR instruction set.
53
--       However, Atmel's AVRStudio computes it differently. To see where is the
54
--       bug, in the AVR instruction set document or in AVRStudio.
55
-- </File info>
56
 
57
 
58
 
59
-- <File body>
60
library work;
61
use work.std_util.all;
62
use work.pavr_util.all;
63
use work.pavr_constants.all;
64
library ieee;
65
use ieee.std_logic_1164.all;
66
 
67
 
68
 
69
entity pavr_alu is
70
   port(
71
      pavr_alu_op1:      in  std_logic_vector(15 downto 0);
72
      pavr_alu_op2:      in  std_logic_vector(7 downto 0);
73
      pavr_alu_out:      out std_logic_vector(15 downto 0);
74
      pavr_alu_opcode:   in  std_logic_vector(pavr_alu_opcode_w - 1 downto 0);
75
      pavr_alu_flagsin:  in  std_logic_vector(5 downto 0);
76
      pavr_alu_flagsout: out std_logic_vector(5 downto 0)
77
   );
78
end;
79
 
80
 
81
 
82
architecture pavr_alu_arch of pavr_alu is
83
   -- Wires
84
   signal tmp10_1, tmp10_2, tmp10_3 : std_logic_vector(9 downto 0);
85
   signal tmp18_1, tmp18_2, tmp18_3 : std_logic_vector(17 downto 0);
86
 
87
   signal pavr_alu_h_sel: std_logic_vector(pavr_alu_h_sel_w - 1 downto 0);
88
   signal pavr_alu_s_sel: std_logic;
89
   signal pavr_alu_v_sel: std_logic_vector(pavr_alu_v_sel_w - 1 downto 0);
90
   signal pavr_alu_n_sel: std_logic_vector(pavr_alu_n_sel_w - 1 downto 0);
91
   signal pavr_alu_z_sel: std_logic_vector(pavr_alu_z_sel_w - 1 downto 0);
92
   signal pavr_alu_c_sel: std_logic_vector(pavr_alu_c_sel_w - 1 downto 0);
93
 
94
   signal pavr_alu_out_int: std_logic_vector(15 downto 0);
95
   signal pavr_alu_flagsout_int: std_logic_vector(5 downto 0);
96
 
97
   -- Registers
98
   --    No registers
99
begin
100
 
101
   -- Compute ALU output and selectors for flags muxers.
102
   alu_out:
103
   process(pavr_alu_op1, pavr_alu_op2, pavr_alu_out_int, pavr_alu_opcode, pavr_alu_flagsin,
104
           tmp10_1, tmp10_2, tmp10_3,
105
           tmp18_1, tmp18_2, tmp18_3
106
          )
107
   begin
108
      -- Default ALU output to 0.
109
      pavr_alu_out_int <= int_to_std_logic_vector(0, pavr_alu_out_int'length);
110
 
111
      -- Default 8 bit adders's operands to ls8bits(operand1), operand2, carry in and carry out to 0.
112
      tmp10_1(0) <= '0';
113
      tmp10_2(0) <= '0';
114
      tmp10_1(8 downto 1) <= pavr_alu_op1(7 downto 0);
115
      tmp10_2(8 downto 1) <= pavr_alu_op2(7 downto 0);
116
      tmp10_1(9) <= '0';
117
      tmp10_2(9) <= '0';
118
 
119
      -- Default 16 bit adders's operands to operand1, signExtendTo16bits(operand2), carry in and carry out to 0.
120
      tmp18_1(0) <= '0';
121
      tmp18_2(0) <= '0';
122
      tmp18_1(16 downto 1) <= pavr_alu_op1(15 downto 0);
123
      tmp18_2(16 downto 1) <= sign_extend(pavr_alu_op2, 16);
124
      tmp18_1(17) <= '0';
125
      tmp18_2(17) <= '0';
126
 
127
      -- Default adders's outputs
128
      tmp10_3 <= int_to_std_logic_vector(0, tmp10_3'length);
129
      tmp18_3 <= int_to_std_logic_vector(0, tmp18_3'length);
130
 
131
      -- Default flags out to flags in.
132
      pavr_alu_h_sel <= pavr_alu_h_sel_same;
133
      pavr_alu_s_sel <= pavr_alu_s_sel_same;
134
      pavr_alu_v_sel <= pavr_alu_v_sel_same;
135
      pavr_alu_n_sel <= pavr_alu_n_sel_same;
136
      pavr_alu_z_sel <= pavr_alu_z_sel_same;
137
      pavr_alu_c_sel <= pavr_alu_c_sel_same;
138
 
139
      -- Build ALU output.
140
      case std_logic_vector_to_nat(pavr_alu_opcode) is
141
         when pavr_alu_opcode_add8 =>
142
            tmp10_3 <= tmp10_1 + tmp10_2;
143
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
144
            pavr_alu_h_sel <= pavr_alu_h_sel_add8;
145
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
146
            pavr_alu_v_sel <= pavr_alu_v_sel_add8;
147
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
148
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
149
            pavr_alu_c_sel <= pavr_alu_c_sel_add8;
150
         when pavr_alu_opcode_adc8 =>
151
            tmp10_1(0) <= pavr_alu_flagsin(0);
152
            tmp10_2(0) <= pavr_alu_flagsin(0);
153
            tmp10_3 <= tmp10_1 + tmp10_2;
154
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
155
            pavr_alu_h_sel <= pavr_alu_h_sel_add8;
156
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
157
            pavr_alu_v_sel <= pavr_alu_v_sel_add8;
158
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
159
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
160
            pavr_alu_c_sel <= pavr_alu_c_sel_add8;
161
         when pavr_alu_opcode_sub8 =>
162
            tmp10_1(0) <= '1';
163
            tmp10_3 <= tmp10_1 + (not tmp10_2);
164
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
165
            pavr_alu_h_sel <= pavr_alu_h_sel_sub8;
166
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
167
            pavr_alu_v_sel <= pavr_alu_v_sel_sub8;
168
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
169
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
170
            pavr_alu_c_sel <= pavr_alu_c_sel_sub8;
171
         when pavr_alu_opcode_sbc8 =>
172
            tmp10_1(0) <= not pavr_alu_flagsin(0);
173
            tmp10_2(0) <= pavr_alu_flagsin(0);
174
            tmp10_3 <= tmp10_1 + (not tmp10_2);
175
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
176
            pavr_alu_h_sel <= pavr_alu_h_sel_sub8;
177
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
178
            pavr_alu_v_sel <= pavr_alu_v_sel_sub8;
179
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
180
            pavr_alu_z_sel <= pavr_alu_z_sel_z8c;
181
            pavr_alu_c_sel <= pavr_alu_c_sel_sub8;
182
         when pavr_alu_opcode_and8 =>
183
            pavr_alu_out_int(7 downto 0) <= pavr_alu_op1(7 downto 0) and pavr_alu_op2;
184
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
185
            pavr_alu_v_sel <= pavr_alu_v_sel_z;
186
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
187
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
188
         when pavr_alu_opcode_eor8 =>
189
            pavr_alu_out_int(7 downto 0) <= pavr_alu_op1(7 downto 0) xor pavr_alu_op2;
190
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
191
            pavr_alu_v_sel <= pavr_alu_v_sel_z;
192
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
193
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
194
         when pavr_alu_opcode_or8 =>
195
            pavr_alu_out_int(7 downto 0) <= pavr_alu_op1(7 downto 0) or pavr_alu_op2;
196
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
197
            pavr_alu_v_sel <= pavr_alu_v_sel_z;
198
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
199
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
200
         when pavr_alu_opcode_op1 =>
201
            pavr_alu_out_int <= pavr_alu_op1;
202
         when pavr_alu_opcode_op2 =>
203
            pavr_alu_out_int <= zero_extend(pavr_alu_op2, pavr_alu_out_int'length);
204
         when pavr_alu_opcode_inc8 =>
205
            tmp10_3 <= tmp10_1 + tmp10_2;
206
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
207
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
208
            pavr_alu_v_sel <= pavr_alu_v_sel_inc8;
209
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
210
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
211
         when pavr_alu_opcode_dec8 =>
212
            tmp10_3 <= tmp10_1 + tmp10_2;
213
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
214
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
215
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
216
            pavr_alu_v_sel <= pavr_alu_v_sel_dec8;
217
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
218
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
219
         when pavr_alu_opcode_com8 =>
220
            pavr_alu_out_int(7 downto 0) <= not pavr_alu_op1(7 downto 0);
221
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
222
            pavr_alu_v_sel <= pavr_alu_v_sel_z;
223
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
224
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
225
            pavr_alu_c_sel <= pavr_alu_c_sel_one;
226
         when pavr_alu_opcode_neg8 =>
227
            tmp10_1 <= int_to_std_logic_vector(1, tmp10_1'length);
228
            tmp10_2(8 downto 1) <= pavr_alu_op1(7 downto 0);
229
            tmp10_3 <= tmp10_1 + (not tmp10_2);
230
            pavr_alu_out_int(7 downto 0) <= tmp10_3(8 downto 1);
231
            pavr_alu_h_sel <= pavr_alu_h_sel_neg8;
232
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
233
            pavr_alu_v_sel <= pavr_alu_v_sel_neg8;
234
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
235
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
236
            pavr_alu_c_sel <= pavr_alu_c_sel_neg8;
237
         when pavr_alu_opcode_swap8 =>
238
            pavr_alu_out_int(7 downto 4) <= pavr_alu_op1(3 downto 0);
239
            pavr_alu_out_int(3 downto 0) <= pavr_alu_op1(7 downto 4);
240
         when pavr_alu_opcode_lsr8 =>
241
            pavr_alu_out_int(7) <= '0';
242
            pavr_alu_out_int(6 downto 0) <= pavr_alu_op1(7 downto 1);
243
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
244
            pavr_alu_v_sel <= pavr_alu_v_sel_nxorc;
245
            pavr_alu_n_sel <= pavr_alu_n_sel_z;
246
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
247
            pavr_alu_c_sel <= pavr_alu_c_sel_lsbop1;
248
         when pavr_alu_opcode_asr8 =>
249
            pavr_alu_out_int(7) <= pavr_alu_op1(7);
250
            pavr_alu_out_int(6 downto 0) <= pavr_alu_op1(7 downto 1);
251
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
252
            pavr_alu_v_sel <= pavr_alu_v_sel_nxorc;
253
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
254
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
255
            pavr_alu_c_sel <= pavr_alu_c_sel_lsbop1;
256
         when pavr_alu_opcode_ror8 =>
257
            pavr_alu_out_int(7) <= pavr_alu_flagsin(0);
258
            pavr_alu_out_int(6 downto 0) <= pavr_alu_op1(7 downto 1);
259
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
260
            pavr_alu_v_sel <= pavr_alu_v_sel_nxorc;
261
            pavr_alu_n_sel <= pavr_alu_n_sel_msb8;
262
            pavr_alu_z_sel <= pavr_alu_z_sel_z8;
263
            pavr_alu_c_sel <= pavr_alu_c_sel_lsbop1;
264
         when pavr_alu_opcode_add16 =>
265
            tmp18_3 <= tmp18_1 + tmp18_2;
266
            pavr_alu_out_int(15 downto 0) <= tmp18_3(16 downto 1);
267
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
268
            pavr_alu_v_sel <= pavr_alu_v_sel_add16;
269
            pavr_alu_n_sel <= pavr_alu_n_sel_msb16;
270
            pavr_alu_z_sel <= pavr_alu_z_sel_z16;
271
            pavr_alu_c_sel <= pavr_alu_c_sel_add16;
272
         when pavr_alu_opcode_sub16 =>
273
            tmp18_1(0) <= '1';
274
            tmp18_3 <= tmp18_1 + (not tmp18_2);
275
            pavr_alu_out_int(15 downto 0) <= tmp18_3(16 downto 1);
276
            pavr_alu_s_sel <= pavr_alu_s_sel_nxorv;
277
            pavr_alu_v_sel <= pavr_alu_v_sel_sub16;
278
            pavr_alu_n_sel <= pavr_alu_n_sel_msb16;
279
            pavr_alu_z_sel <= pavr_alu_z_sel_z16;
280
            pavr_alu_c_sel <= pavr_alu_c_sel_add16;
281
         -- Multiplications are not implemented for now.
282
         when pavr_alu_opcode_mul8 =>
283
            null;
284
         when pavr_alu_opcode_muls8 =>
285
            null;
286
         when pavr_alu_opcode_mulsu8 =>
287
            null;
288
         when pavr_alu_opcode_fmul8 =>
289
            null;
290
         when pavr_alu_opcode_fmuls8 =>
291
            null;
292
         when pavr_alu_opcode_fmulsu8 =>
293
            null;
294
         when others =>
295
            null;
296
      end case;
297
   end process alu_out;
298
 
299
 
300
 
301
   -- Select output flags based on the selectors computed in the process above.
302
   alu_flags:
303
   process(pavr_alu_op1, pavr_alu_op2, pavr_alu_out_int, pavr_alu_flagsin, pavr_alu_flagsout_int,
304
           pavr_alu_c_sel, pavr_alu_z_sel, pavr_alu_n_sel, pavr_alu_v_sel, pavr_alu_s_sel, pavr_alu_h_sel,
305
           tmp10_3, tmp18_3)
306
      variable tmp1, tmp2, tmp3, tmp4 : std_logic;
307
   begin
308
      tmp1 := '0';
309
      tmp2 := '0';
310
      tmp3 := '0';
311
      tmp4 := '0';
312
 
313
      -- Default flags out to flags in.
314
      pavr_alu_flagsout_int <= pavr_alu_flagsin;
315
 
316
      -- Build C flag.
317
      case pavr_alu_c_sel is
318
         when pavr_alu_c_sel_same =>
319
            pavr_alu_flagsout_int(0) <= pavr_alu_flagsin(0);
320
         when pavr_alu_c_sel_add8 | pavr_alu_c_sel_sub8 =>
321
            pavr_alu_flagsout_int(0) <= tmp10_3(9);
322
         when pavr_alu_c_sel_one =>
323
            pavr_alu_flagsout_int(0) <= '1';
324
         when pavr_alu_c_sel_neg8 =>
325
            -- Set carry if and only if input != 0 (equivalent to output != 0).
326
            pavr_alu_flagsout_int(0) <= pavr_alu_op1(0);
327
            for i in 1 to 7 loop
328
               pavr_alu_flagsout_int(0) <= pavr_alu_flagsout_int(0) or pavr_alu_op1(i);
329
            end loop;
330
         when pavr_alu_c_sel_lsbop1 =>
331
            pavr_alu_flagsout_int(0) <= pavr_alu_op1(0);
332
         -- When pavr_alu_c_sel_add16 | pavr_alu_c_sel_sub16
333
         when others =>
334
            pavr_alu_flagsout_int(0) <= tmp18_3(17);
335
      end case;
336
 
337
      -- Build Z flag.
338
      case pavr_alu_z_sel is
339
         when pavr_alu_z_sel_same =>
340
            pavr_alu_flagsout_int(1) <= pavr_alu_flagsin(1);
341
         when pavr_alu_z_sel_z8 =>
342
            tmp4 := pavr_alu_out_int(0);
343
            for i in 1 to 7 loop
344
               tmp4 := tmp4 or pavr_alu_out_int(i);
345
            end loop;
346
            pavr_alu_flagsout_int(1) <= not tmp4;
347
         when pavr_alu_z_sel_z8c =>
348
            tmp4 := pavr_alu_out_int(0);
349
            for i in 1 to 7 loop
350
               tmp4 := tmp4 or pavr_alu_out_int(i);
351
            end loop;
352
            pavr_alu_flagsout_int(1) <= (not tmp4) and pavr_alu_flagsin(1);
353
         -- When pavr_alu_z_sel_z16
354
         when others =>
355
            tmp4 := pavr_alu_out_int(0);
356
            for i in 1 to 15 loop
357
               tmp4 := tmp4 or pavr_alu_out_int(i);
358
            end loop;
359
            pavr_alu_flagsout_int(1) <= not tmp4;
360
      end case;
361
 
362
      -- Build N flag.
363
      case pavr_alu_n_sel is
364
         when pavr_alu_n_sel_same =>
365
            pavr_alu_flagsout_int(2) <= pavr_alu_flagsin(2);
366
         when pavr_alu_n_sel_msb8 =>
367
            pavr_alu_flagsout_int(2) <= pavr_alu_out_int(7);
368
         -- When pavr_alu_n_sel_msb16
369
         when others =>
370
            pavr_alu_flagsout_int(2) <= pavr_alu_out_int(15);
371
      end case;
372
 
373
      -- Build V flag.
374
      case pavr_alu_v_sel is
375
         when pavr_alu_v_sel_same =>
376
            pavr_alu_flagsout_int(3) <= pavr_alu_flagsin(3);
377
         when pavr_alu_v_sel_add8 =>
378
            tmp1 := pavr_alu_op1(7);
379
            tmp2 := pavr_alu_op2(7);
380
            tmp3 := pavr_alu_out_int(7);
381
            pavr_alu_flagsout_int(3) <= (tmp1 and tmp2 and (not tmp3)) or ((not tmp1) and (not tmp2) and tmp3);
382
         when pavr_alu_v_sel_sub8 =>
383
            tmp1 := pavr_alu_op1(7);
384
            tmp2 := pavr_alu_op2(7);
385
            tmp3 := pavr_alu_out_int(7);
386
            pavr_alu_flagsout_int(3) <= (tmp1 and (not tmp2) and (not tmp3)) or ((not tmp1) and tmp2 and tmp3);
387
         when pavr_alu_v_sel_z =>
388
            pavr_alu_flagsout_int(3) <= '0';
389
         when pavr_alu_v_sel_inc8 | pavr_alu_v_sel_neg8 =>
390
            pavr_alu_flagsout_int(3) <= not pavr_alu_out_int(0);
391
            for i in 1 to 6 loop
392
               pavr_alu_flagsout_int(3) <= pavr_alu_flagsout_int(3) and (not pavr_alu_out_int(i));
393
            end loop;
394
            pavr_alu_flagsout_int(3) <= pavr_alu_flagsout_int(3) and pavr_alu_out_int(7);
395
         when pavr_alu_v_sel_dec8 =>
396
            pavr_alu_flagsout_int(3) <= pavr_alu_out_int(0);
397
            for i in 1 to 6 loop
398
               pavr_alu_flagsout_int(3) <= pavr_alu_flagsout_int(3) and pavr_alu_out_int(i);
399
            end loop;
400
            pavr_alu_flagsout_int(3) <= pavr_alu_flagsout_int(3) and (not pavr_alu_out_int(7));
401
         when pavr_alu_v_sel_nxorc =>
402
            pavr_alu_flagsout_int(3) <= pavr_alu_flagsout_int(2) xor pavr_alu_flagsout_int(0);
403
         when pavr_alu_v_sel_add16 =>
404
            pavr_alu_flagsout_int(3) <= (not pavr_alu_op1(15)) and pavr_alu_out_int(15);
405
         -- When pavr_alu_v_sel_sub16
406
         when others =>
407
            pavr_alu_flagsout_int(3) <= pavr_alu_op1(15) and (not pavr_alu_out_int(15));
408
      end case;
409
 
410
      -- Build S flag.
411
      case pavr_alu_s_sel is
412
         when pavr_alu_s_sel_same =>
413
            pavr_alu_flagsout_int(4) <= pavr_alu_flagsin(4);
414
         -- When pavr_alu_s_sel_nxorv
415
         when others =>
416
            pavr_alu_flagsout_int(4) <= pavr_alu_flagsout_int(2) xor pavr_alu_flagsout_int(3);
417
      end case;
418
 
419
      tmp1 := pavr_alu_op1(3);
420
      tmp2 := pavr_alu_op2(3);
421
      tmp3 := pavr_alu_out_int(3);
422
      -- Build H flag.
423
      case pavr_alu_h_sel is
424
         when pavr_alu_h_sel_same =>
425
            pavr_alu_flagsout_int(5) <= pavr_alu_flagsin(5);
426
         when pavr_alu_h_sel_add8 =>
427
            pavr_alu_flagsout_int(5) <= (tmp1 and tmp2) or (tmp2 and (not tmp3)) or ((not tmp3) and tmp1);
428
         when pavr_alu_h_sel_sub8 =>
429
            pavr_alu_flagsout_int(5) <= ((not tmp1) and tmp2) or (tmp2 and tmp3) or (tmp3 and (not tmp1));
430
         -- When pavr_alu_h_sel_neg8 =>
431
         when others =>
432
            pavr_alu_flagsout_int(5) <= tmp1 or tmp3;
433
      end case;
434
   end process alu_flags;
435
 
436
 
437
 
438
   -- Zero-level assignments
439
   pavr_alu_out <= pavr_alu_out_int;
440
   pavr_alu_flagsout <= pavr_alu_flagsout_int;
441
 
442
end;
443
-- </File body>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.