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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_alu.v] - Blame information for rev 141

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's ALU                                                ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  ALU                                                         ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - make it smaller and faster                               ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Damjan Lampret, lampret@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46 141 marcus.erl
// $Log: or1200_alu.v,v $
47
// Revision 2.0  2010/06/30 11:00:00  ORSoC
48
// Minor update: 
49
// Defines added, flags are corrected. 
50
//
51
// Revision 1.15  2005/01/07 09:23:39  andreje
52
// l.ff1 and l.cmov instructions added
53
//
54 10 unneback
// Revision 1.14  2004/06/08 18:17:36  lampret
55
// Non-functional changes. Coding style fixes.
56
//
57
// Revision 1.13  2004/05/09 19:49:03  lampret
58
// Added some l.cust5 custom instructions as example
59
//
60
// Revision 1.12  2004/04/05 08:29:57  lampret
61
// Merged branch_qmem into main tree.
62
//
63
// Revision 1.11  2003/04/24 00:16:07  lampret
64
// No functional changes. Added defines to disable implementation of multiplier/MAC
65
//
66
// Revision 1.10  2002/09/08 05:52:16  lampret
67
// Added optional l.div/l.divu insns. By default they are disabled.
68
//
69
// Revision 1.9  2002/09/07 19:16:10  lampret
70
// If SR[CY] implemented with OR1200_IMPL_ADDC enabled, l.add/l.addi also set SR[CY].
71
//
72
// Revision 1.8  2002/09/07 05:42:02  lampret
73
// Added optional SR[CY]. Added define to enable additional (compare) flag modifiers. Defines are OR1200_IMPL_ADDC and OR1200_ADDITIONAL_FLAG_MODIFIERS.
74
//
75
// Revision 1.7  2002/09/03 22:28:21  lampret
76
// As per Taylor Su suggestion all case blocks are full case by default and optionally (OR1200_CASE_DEFAULT) can be disabled to increase clock frequncy.
77
//
78
// Revision 1.6  2002/03/29 16:40:10  lampret
79
// Added a directive to ignore signed division variables that are only used in simulation.
80
//
81
// Revision 1.5  2002/03/29 16:33:59  lampret
82
// Added again just recently removed full_case directive
83
//
84
// Revision 1.4  2002/03/29 15:16:53  lampret
85
// Some of the warnings fixed.
86
//
87
// Revision 1.3  2002/01/28 01:15:59  lampret
88
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
89
//
90
// Revision 1.2  2002/01/14 06:18:22  lampret
91
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
92
//
93
// Revision 1.1  2002/01/03 08:16:15  lampret
94
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
95
//
96
// Revision 1.10  2001/11/12 01:45:40  lampret
97
// Moved flag bit into SR. Changed RF enable from constant enable to dynamic enable for read ports.
98
//
99
// Revision 1.9  2001/10/21 17:57:16  lampret
100
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
101
//
102
// Revision 1.8  2001/10/19 23:28:45  lampret
103
// Fixed some synthesis warnings. Configured with caches and MMUs.
104
//
105
// Revision 1.7  2001/10/14 13:12:09  lampret
106
// MP3 version.
107
//
108
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
109
// no message
110
//
111
// Revision 1.2  2001/08/09 13:39:33  lampret
112
// Major clean-up.
113
//
114
// Revision 1.1  2001/07/20 00:46:03  lampret
115
// Development version of RTL. Libraries are missing.
116
//
117
//
118
 
119
// synopsys translate_off
120
`include "timescale.v"
121
// synopsys translate_on
122
`include "or1200_defines.v"
123
 
124
module or1200_alu(
125
        a, b, mult_mac_result, macrc_op,
126
        alu_op, shrot_op, comp_op,
127
        cust5_op, cust5_limm,
128
        result, flagforw, flag_we,
129
        cyforw, cy_we, carry, flag
130
);
131
 
132
parameter width = `OR1200_OPERAND_WIDTH;
133
 
134
//
135
// I/O
136
//
137
input   [width-1:0]              a;
138
input   [width-1:0]              b;
139
input   [width-1:0]              mult_mac_result;
140
input                           macrc_op;
141
input   [`OR1200_ALUOP_WIDTH-1:0]        alu_op;
142
input   [`OR1200_SHROTOP_WIDTH-1:0]      shrot_op;
143
input   [`OR1200_COMPOP_WIDTH-1:0]       comp_op;
144
input   [4:0]                    cust5_op;
145
input   [5:0]                    cust5_limm;
146
output  [width-1:0]              result;
147
output                          flagforw;
148
output                          flag_we;
149
output                          cyforw;
150
output                          cy_we;
151
input                           carry;
152
input         flag;
153
 
154
//
155
// Internal wires and regs
156
//
157
reg     [width-1:0]              result;
158
reg     [width-1:0]              shifted_rotated;
159
reg     [width-1:0]              result_cust5;
160
reg                             flagforw;
161
reg                             flagcomp;
162
reg                             flag_we;
163
reg                             cy_we;
164
wire    [width-1:0]              comp_a;
165
wire    [width-1:0]              comp_b;
166
`ifdef OR1200_IMPL_ALU_COMP1
167
wire                            a_eq_b;
168
wire                            a_lt_b;
169
`endif
170
wire    [width-1:0]              result_sum;
171
`ifdef OR1200_IMPL_ADDC
172
wire    [width-1:0]              result_csum;
173
wire                            cy_csum;
174
`endif
175
wire    [width-1:0]              result_and;
176
wire                            cy_sum;
177 141 marcus.erl
`ifdef OR1200_IMPL_SUB
178
wire                            cy_sub;
179
`endif
180 10 unneback
reg                             cyforw;
181
 
182
//
183
// Combinatorial logic
184
//
185
assign comp_a = {a[width-1] ^ comp_op[3] , a[width-2:0]};
186
assign comp_b = {b[width-1] ^ comp_op[3] , b[width-2:0]};
187
`ifdef OR1200_IMPL_ALU_COMP1
188
assign a_eq_b = (comp_a == comp_b);
189
assign a_lt_b = (comp_a < comp_b);
190
`endif
191 141 marcus.erl
`ifdef OR1200_IMPL_SUB
192
assign cy_sub = a < b;
193
`endif
194 10 unneback
assign {cy_sum, result_sum} = a + b;
195
`ifdef OR1200_IMPL_ADDC
196 141 marcus.erl
assign {cy_csum, result_csum} = a + b + {`OR1200_OPERAND_WIDTH'd0, carry};
197 10 unneback
`endif
198
assign result_and = a & b;
199
 
200
//
201
// Simulation check for bad ALU behavior
202
//
203
`ifdef OR1200_WARNINGS
204
// synopsys translate_off
205
always @(result) begin
206
        if (result === 32'bx)
207
                $display("%t: WARNING: 32'bx detected on ALU result bus. Please check !", $time);
208
end
209
// synopsys translate_on
210
`endif
211
 
212
//
213
// Central part of the ALU
214
//
215 141 marcus.erl
always @(alu_op or a or b or result_sum or result_and or macrc_op or shifted_rotated or mult_mac_result or flag or result_cust5 or carry
216
`ifdef OR1200_IMPL_ADDC
217
         or result_csum
218
`endif
219
) begin
220 10 unneback
`ifdef OR1200_CASE_DEFAULT
221
        casex (alu_op)          // synopsys parallel_case
222
`else
223
        casex (alu_op)          // synopsys full_case parallel_case
224
`endif
225 141 marcus.erl
                `OR1200_ALUOP_FF1: begin
226
                        result = a[0] ? 1 : a[1] ? 2 : a[2] ? 3 : a[3] ? 4 : a[4] ? 5 : a[5] ? 6 : a[6] ? 7 : a[7] ? 8 : a[8] ? 9 : a[9] ? 10 : a[10] ? 11 : a[11] ? 12 : a[12] ? 13 : a[13] ? 14 : a[14] ? 15 : a[15] ? 16 : a[16] ? 17 : a[17] ? 18 : a[18] ? 19 : a[19] ? 20 : a[20] ? 21 : a[21] ? 22 : a[22] ? 23 : a[23] ? 24 : a[24] ? 25 : a[25] ? 26 : a[26] ? 27 : a[27] ? 28 : a[28] ? 29 : a[29] ? 30 : a[30] ? 31 : a[31] ? 32 : 0;
227
                end
228 10 unneback
                `OR1200_ALUOP_CUST5 : begin
229
                                result = result_cust5;
230
                end
231
                `OR1200_ALUOP_SHROT : begin
232
                                result = shifted_rotated;
233
                end
234
                `OR1200_ALUOP_ADD : begin
235
                                result = result_sum;
236
                end
237
`ifdef OR1200_IMPL_ADDC
238
                `OR1200_ALUOP_ADDC : begin
239
                                result = result_csum;
240
                end
241
`endif
242 141 marcus.erl
`ifdef OR1200_IMPL_SUB
243 10 unneback
                `OR1200_ALUOP_SUB : begin
244
                                result = a - b;
245
                end
246 141 marcus.erl
`endif
247 10 unneback
                `OR1200_ALUOP_XOR : begin
248
                                result = a ^ b;
249
                end
250
                `OR1200_ALUOP_OR  : begin
251
                                result = a | b;
252
                end
253
                `OR1200_ALUOP_IMM : begin
254
                                result = b;
255
                end
256
                `OR1200_ALUOP_MOVHI : begin
257
                                if (macrc_op) begin
258
                                        result = mult_mac_result;
259
                                end
260
                                else begin
261
                                        result = b << 16;
262
                                end
263
                end
264
`ifdef OR1200_MULT_IMPLEMENTED
265
`ifdef OR1200_IMPL_DIV
266
                `OR1200_ALUOP_DIV,
267
                `OR1200_ALUOP_DIVU,
268
`endif
269
                `OR1200_ALUOP_MUL : begin
270
                                result = mult_mac_result;
271
                end
272
`endif
273 141 marcus.erl
                `OR1200_ALUOP_CMOV: begin
274
                        result = flag ? a : b;
275
                end
276 10 unneback
 
277
`ifdef OR1200_CASE_DEFAULT
278 141 marcus.erl
                default: begin
279 10 unneback
`else
280 141 marcus.erl
                `OR1200_ALUOP_COMP, `OR1200_ALUOP_AND: begin
281 10 unneback
`endif
282 141 marcus.erl
                        result=result_and;
283
                end
284 10 unneback
        endcase
285
end
286
 
287
//
288
// l.cust5 custom instructions
289
//
290
// Examples for move byte, set bit and clear bit
291
//
292
always @(cust5_op or cust5_limm or a or b) begin
293
        casex (cust5_op)                // synopsys parallel_case
294
                5'h1 : begin
295
                        casex (cust5_limm[1:0])
296
                                2'h0: result_cust5 = {a[31:8], b[7:0]};
297
                                2'h1: result_cust5 = {a[31:16], b[7:0], a[7:0]};
298
                                2'h2: result_cust5 = {a[31:24], b[7:0], a[15:0]};
299
                                2'h3: result_cust5 = {b[7:0], a[23:0]};
300
                        endcase
301
                end
302
                5'h2 :
303
                        result_cust5 = a | (1 << cust5_limm);
304
                5'h3 :
305
                        result_cust5 = a & (32'hffffffff ^ (1 << cust5_limm));
306
//
307
// *** Put here new l.cust5 custom instructions ***
308
//
309
                default: begin
310
                        result_cust5 = a;
311
                end
312
        endcase
313
end
314
 
315
//
316
// Generate flag and flag write enable
317
//
318 141 marcus.erl
always @(alu_op or result_sum or result_and or flagcomp
319
`ifdef OR1200_IMPL_ADDC
320
         or result_csum
321
`endif
322
) begin
323 10 unneback
        casex (alu_op)          // synopsys parallel_case
324
`ifdef OR1200_ADDITIONAL_FLAG_MODIFIERS
325
                `OR1200_ALUOP_ADD : begin
326
                        flagforw = (result_sum == 32'h0000_0000);
327
                        flag_we = 1'b1;
328
                end
329
`ifdef OR1200_IMPL_ADDC
330
                `OR1200_ALUOP_ADDC : begin
331
                        flagforw = (result_csum == 32'h0000_0000);
332
                        flag_we = 1'b1;
333
                end
334
`endif
335
                `OR1200_ALUOP_AND: begin
336
                        flagforw = (result_and == 32'h0000_0000);
337
                        flag_we = 1'b1;
338
                end
339
`endif
340
                `OR1200_ALUOP_COMP: begin
341
                        flagforw = flagcomp;
342
                        flag_we = 1'b1;
343
                end
344
                default: begin
345 141 marcus.erl
                        flagforw = flagcomp;
346 10 unneback
                        flag_we = 1'b0;
347
                end
348
        endcase
349
end
350
 
351
//
352
// Generate SR[CY] write enable
353
//
354
always @(alu_op or cy_sum
355 141 marcus.erl
`ifdef OR1200_IMPL_CY
356 10 unneback
`ifdef OR1200_IMPL_ADDC
357
        or cy_csum
358
`endif
359 141 marcus.erl
`ifdef OR1200_IMPL_SUB
360
        or cy_sub
361
`endif
362
`endif
363
) begin
364 10 unneback
        casex (alu_op)          // synopsys parallel_case
365
`ifdef OR1200_IMPL_CY
366
                `OR1200_ALUOP_ADD : begin
367
                        cyforw = cy_sum;
368
                        cy_we = 1'b1;
369
                end
370
`ifdef OR1200_IMPL_ADDC
371
                `OR1200_ALUOP_ADDC: begin
372
                        cyforw = cy_csum;
373
                        cy_we = 1'b1;
374
                end
375
`endif
376 141 marcus.erl
`ifdef OR1200_IMPL_SUB
377
                `OR1200_ALUOP_SUB: begin
378
                        cyforw = cy_sub;
379
                        cy_we = 1'b1;
380
                end
381 10 unneback
`endif
382 141 marcus.erl
`endif
383 10 unneback
                default: begin
384
                        cyforw = 1'b0;
385
                        cy_we = 1'b0;
386
                end
387
        endcase
388
end
389
 
390
//
391
// Shifts and rotation
392
//
393
always @(shrot_op or a or b) begin
394
        case (shrot_op)         // synopsys parallel_case
395
        `OR1200_SHROTOP_SLL :
396
                                shifted_rotated = (a << b[4:0]);
397
                `OR1200_SHROTOP_SRL :
398
                                shifted_rotated = (a >> b[4:0]);
399
 
400
`ifdef OR1200_IMPL_ALU_ROTATE
401
                `OR1200_SHROTOP_ROR :
402
                                shifted_rotated = (a << (6'd32-{1'b0, b[4:0]})) | (a >> b[4:0]);
403
`endif
404
                default:
405
                                shifted_rotated = ({32{a[31]}} << (6'd32-{1'b0, b[4:0]})) | a >> b[4:0];
406
        endcase
407
end
408
 
409
//
410
// First type of compare implementation
411
//
412
`ifdef OR1200_IMPL_ALU_COMP1
413
always @(comp_op or a_eq_b or a_lt_b) begin
414
        case(comp_op[2:0])       // synopsys parallel_case
415
                `OR1200_COP_SFEQ:
416
                        flagcomp = a_eq_b;
417
                `OR1200_COP_SFNE:
418
                        flagcomp = ~a_eq_b;
419
                `OR1200_COP_SFGT:
420
                        flagcomp = ~(a_eq_b | a_lt_b);
421
                `OR1200_COP_SFGE:
422
                        flagcomp = ~a_lt_b;
423
                `OR1200_COP_SFLT:
424
                        flagcomp = a_lt_b;
425
                `OR1200_COP_SFLE:
426
                        flagcomp = a_eq_b | a_lt_b;
427
                default:
428
                        flagcomp = 1'b0;
429
        endcase
430
end
431
`endif
432
 
433
//
434
// Second type of compare implementation
435
//
436
`ifdef OR1200_IMPL_ALU_COMP2
437
always @(comp_op or comp_a or comp_b) begin
438
        case(comp_op[2:0])       // synopsys parallel_case
439
                `OR1200_COP_SFEQ:
440
                        flagcomp = (comp_a == comp_b);
441
                `OR1200_COP_SFNE:
442
                        flagcomp = (comp_a != comp_b);
443
                `OR1200_COP_SFGT:
444
                        flagcomp = (comp_a > comp_b);
445
                `OR1200_COP_SFGE:
446
                        flagcomp = (comp_a >= comp_b);
447
                `OR1200_COP_SFLT:
448
                        flagcomp = (comp_a < comp_b);
449
                `OR1200_COP_SFLE:
450
                        flagcomp = (comp_a <= comp_b);
451
                default:
452
                        flagcomp = 1'b0;
453
        endcase
454
end
455
`endif
456
 
457
endmodule

powered by: WebSVN 2.1.0

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