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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_alu.v] - Blame information for rev 1284

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

Line No. Rev Author Line
1 504 lampret
//////////////////////////////////////////////////////////////////////
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
// $Log: not supported by cvs2svn $
47 1284 lampret
// Revision 1.12  2004/04/05 08:29:57  lampret
48
// Merged branch_qmem into main tree.
49
//
50 1267 lampret
// Revision 1.11  2003/04/24 00:16:07  lampret
51
// No functional changes. Added defines to disable implementation of multiplier/MAC
52
//
53 1159 lampret
// Revision 1.10  2002/09/08 05:52:16  lampret
54
// Added optional l.div/l.divu insns. By default they are disabled.
55
//
56 1035 lampret
// Revision 1.9  2002/09/07 19:16:10  lampret
57
// If SR[CY] implemented with OR1200_IMPL_ADDC enabled, l.add/l.addi also set SR[CY].
58
//
59 1033 lampret
// Revision 1.8  2002/09/07 05:42:02  lampret
60
// Added optional SR[CY]. Added define to enable additional (compare) flag modifiers. Defines are OR1200_IMPL_ADDC and OR1200_ADDITIONAL_FLAG_MODIFIERS.
61
//
62 1032 lampret
// Revision 1.7  2002/09/03 22:28:21  lampret
63
// 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.
64
//
65 1022 lampret
// Revision 1.6  2002/03/29 16:40:10  lampret
66
// Added a directive to ignore signed division variables that are only used in simulation.
67
//
68 795 lampret
// Revision 1.5  2002/03/29 16:33:59  lampret
69
// Added again just recently removed full_case directive
70
//
71 794 lampret
// Revision 1.4  2002/03/29 15:16:53  lampret
72
// Some of the warnings fixed.
73
//
74 788 lampret
// Revision 1.3  2002/01/28 01:15:59  lampret
75
// 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.
76
//
77 617 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
78
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
79
//
80 562 lampret
// Revision 1.1  2002/01/03 08:16:15  lampret
81
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
82
//
83 504 lampret
// Revision 1.10  2001/11/12 01:45:40  lampret
84
// Moved flag bit into SR. Changed RF enable from constant enable to dynamic enable for read ports.
85
//
86
// Revision 1.9  2001/10/21 17:57:16  lampret
87
// 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.
88
//
89
// Revision 1.8  2001/10/19 23:28:45  lampret
90
// Fixed some synthesis warnings. Configured with caches and MMUs.
91
//
92
// Revision 1.7  2001/10/14 13:12:09  lampret
93
// MP3 version.
94
//
95
// Revision 1.1.1.1  2001/10/06 10:18:35  igorm
96
// no message
97
//
98
// Revision 1.2  2001/08/09 13:39:33  lampret
99
// Major clean-up.
100
//
101
// Revision 1.1  2001/07/20 00:46:03  lampret
102
// Development version of RTL. Libraries are missing.
103
//
104
//
105
 
106
// synopsys translate_off
107
`include "timescale.v"
108
// synopsys translate_on
109
`include "or1200_defines.v"
110
 
111
module or1200_alu(
112
        a, b, mult_mac_result, macrc_op,
113
        alu_op, shrot_op, comp_op,
114 1284 lampret
        cust5_op, cust5_limm,
115 1032 lampret
        result, flagforw, flag_we,
116
        cyforw, cy_we, carry
117 504 lampret
);
118
 
119
parameter width = `OR1200_OPERAND_WIDTH;
120
 
121
//
122
// I/O
123
//
124
input   [width-1:0]              a;
125
input   [width-1:0]              b;
126
input   [width-1:0]              mult_mac_result;
127
input                           macrc_op;
128
input   [`OR1200_ALUOP_WIDTH-1:0]        alu_op;
129
input   [`OR1200_SHROTOP_WIDTH-1:0]      shrot_op;
130
input   [`OR1200_COMPOP_WIDTH-1:0]       comp_op;
131 1284 lampret
input   [4:0]                    cust5_op;
132
input   [5:0]                    cust5_limm;
133 504 lampret
output  [width-1:0]              result;
134
output                          flagforw;
135
output                          flag_we;
136 1032 lampret
output                          cyforw;
137
output                          cy_we;
138
input                           carry;
139 504 lampret
 
140
//
141
// Internal wires and regs
142
//
143
reg     [width-1:0]              result;
144
reg     [width-1:0]              shifted_rotated;
145 1284 lampret
reg     [width-1:0]              result_cust5;
146 504 lampret
reg                             flagforw;
147 617 lampret
reg                             flagcomp;
148 504 lampret
reg                             flag_we;
149 1032 lampret
reg                             cy_we;
150 504 lampret
wire    [width-1:0]              comp_a;
151
wire    [width-1:0]              comp_b;
152
`ifdef OR1200_IMPL_ALU_COMP1
153
wire                            a_eq_b;
154
wire                            a_lt_b;
155
`endif
156 617 lampret
wire    [width-1:0]              result_sum;
157 1032 lampret
`ifdef OR1200_IMPL_ADDC
158
wire    [width-1:0]              result_csum;
159 1033 lampret
wire                            cy_csum;
160 1032 lampret
`endif
161 617 lampret
wire    [width-1:0]              result_and;
162 1033 lampret
wire                            cy_sum;
163
reg                             cyforw;
164 504 lampret
 
165
//
166
// Combinatorial logic
167
//
168
assign comp_a = {a[width-1] ^ comp_op[3] , a[width-2:0]};
169
assign comp_b = {b[width-1] ^ comp_op[3] , b[width-2:0]};
170
`ifdef OR1200_IMPL_ALU_COMP1
171
assign a_eq_b = (comp_a == comp_b);
172
assign a_lt_b = (comp_a < comp_b);
173
`endif
174 1033 lampret
assign {cy_sum, result_sum} = a + b;
175 1032 lampret
`ifdef OR1200_IMPL_ADDC
176 1033 lampret
assign {cy_csum, result_csum} = a + b + carry;
177 1032 lampret
`endif
178 617 lampret
assign result_and = a & b;
179 504 lampret
 
180
//
181
// Simulation check for bad ALU behavior
182
//
183
`ifdef OR1200_WARNINGS
184
// synopsys translate_off
185
always @(result) begin
186
        if (result === 32'bx)
187
                $display("%t: WARNING: 32'bx detected on ALU result bus. Please check !", $time);
188
end
189
// synopsys translate_on
190
`endif
191
 
192
//
193
// Central part of the ALU
194
//
195 617 lampret
always @(alu_op or a or b or result_sum or result_and or macrc_op or shifted_rotated or mult_mac_result) begin
196 1022 lampret
`ifdef OR1200_CASE_DEFAULT
197
        casex (alu_op)          // synopsys parallel_case
198
`else
199
        casex (alu_op)          // synopsys full_case parallel_case
200
`endif
201 1284 lampret
                `OR1200_ALUOP_CUST5 : begin
202
                                result = result_cust5;
203
                end
204 504 lampret
                `OR1200_ALUOP_SHROT : begin
205
                                result = shifted_rotated;
206
                end
207
                `OR1200_ALUOP_ADD : begin
208 617 lampret
                                result = result_sum;
209 504 lampret
                end
210 1032 lampret
`ifdef OR1200_IMPL_ADDC
211
                `OR1200_ALUOP_ADDC : begin
212
                                result = result_csum;
213
                end
214
`endif
215 504 lampret
                `OR1200_ALUOP_SUB : begin
216
                                result = a - b;
217
                end
218
                `OR1200_ALUOP_XOR : begin
219
                                result = a ^ b;
220
                end
221
                `OR1200_ALUOP_OR  : begin
222
                                result = a | b;
223
                end
224
                `OR1200_ALUOP_IMM : begin
225
                                result = b;
226
                end
227
                `OR1200_ALUOP_MOVHI : begin
228
                                if (macrc_op) begin
229
                                        result = mult_mac_result;
230
                                end
231
                                else begin
232
                                        result = b << 16;
233
                                end
234
                end
235 1159 lampret
`ifdef OR1200_MULT_IMPLEMENTED
236 1035 lampret
`ifdef OR1200_IMPL_DIV
237
                `OR1200_ALUOP_DIV,
238
                `OR1200_ALUOP_DIVU,
239
`endif
240 504 lampret
                `OR1200_ALUOP_MUL : begin
241
                                result = mult_mac_result;
242
                end
243 1159 lampret
`endif
244 1022 lampret
`ifdef OR1200_CASE_DEFAULT
245
                default: begin
246
`else
247
                `OR1200_ALUOP_COMP, `OR1200_ALUOP_AND
248
`endif
249 617 lampret
                                result = result_and;
250
                end
251
        endcase
252
end
253
 
254
//
255 1284 lampret
// l.cust5 custom instructions
256
//
257
// Examples for move byte, set bit and clear bit
258
//
259
always @(cust5_op or cust5_limm or a or b) begin
260
        casex (cust5_op)                // synopsys parallel_case
261
                5'h1 : begin
262
                        case (cust5_limm)
263
                                2'h0: result_cust5 = {a[31:8], b[7:0]};
264
                                2'h1: result_cust5 = {a[31:16], b[7:0], a[7:0]};
265
                                2'h2: result_cust5 = {a[31:24], b[7:0], a[15:0]};
266
                                2'h3: result_cust5 = {b[7:0], a[23:0]};
267
                        endcase
268
                end
269
                5'h2 :
270
                        result_cust5 = a | (1 << cust5_limm);
271
                5'h3 :
272
                        result_cust5 = a & (32'hffffffff ^ (1 << cust5_limm));
273
//
274
// *** Put here new l.cust5 custom instructions ***
275
//
276
                default: begin
277
                        result_cust5 = a;
278
                end
279
        endcase
280
end
281
 
282
//
283 617 lampret
// Generate flag and flag write enable
284
//
285
always @(alu_op or result_sum or result_and or flagcomp) begin
286 788 lampret
        casex (alu_op)          // synopsys parallel_case
287 1032 lampret
`ifdef OR1200_ADDITIONAL_FLAG_MODIFIERS
288 617 lampret
                `OR1200_ALUOP_ADD : begin
289
                        flagforw = (result_sum == 32'h0000_0000);
290 1032 lampret
                        flag_we = 1'b1;
291 617 lampret
                end
292 1032 lampret
`ifdef OR1200_IMPL_ADDC
293
                `OR1200_ALUOP_ADDC : begin
294
                        flagforw = (result_csum == 32'h0000_0000);
295
                        flag_we = 1'b1;
296
                end
297
`endif
298 617 lampret
                `OR1200_ALUOP_AND: begin
299
                        flagforw = (result_and == 32'h0000_0000);
300 1032 lampret
                        flag_we = 1'b1;
301 617 lampret
                end
302 1032 lampret
`endif
303 504 lampret
                `OR1200_ALUOP_COMP: begin
304 617 lampret
                        flagforw = flagcomp;
305
                        flag_we = 1'b1;
306 504 lampret
                end
307 617 lampret
                default: begin
308
                        flagforw = 1'b0;
309
                        flag_we = 1'b0;
310 504 lampret
                end
311
        endcase
312
end
313
 
314
//
315 1032 lampret
// Generate SR[CY] write enable
316
//
317 1035 lampret
always @(alu_op or cy_sum
318
`ifdef OR1200_IMPL_ADDC
319
        or cy_csum
320
`endif
321
        ) begin
322 1032 lampret
        casex (alu_op)          // synopsys parallel_case
323 1267 lampret
`ifdef OR1200_IMPL_CY
324 1033 lampret
                `OR1200_ALUOP_ADD : begin
325
                        cyforw = cy_sum;
326 1032 lampret
                        cy_we = 1'b1;
327
                end
328 1267 lampret
`ifdef OR1200_IMPL_ADDC
329 1033 lampret
                `OR1200_ALUOP_ADDC: begin
330
                        cyforw = cy_csum;
331
                        cy_we = 1'b1;
332
                end
333 1032 lampret
`endif
334 1267 lampret
`endif
335 1032 lampret
                default: begin
336 1033 lampret
                        cyforw = 1'b0;
337 1032 lampret
                        cy_we = 1'b0;
338
                end
339
        endcase
340
end
341
 
342
//
343 504 lampret
// Shifts and rotation
344
//
345
always @(shrot_op or a or b) begin
346
        case (shrot_op)         // synopsys parallel_case
347 562 lampret
        `OR1200_SHROTOP_SLL :
348 504 lampret
                                shifted_rotated = (a << b[4:0]);
349
                `OR1200_SHROTOP_SRL :
350
                                shifted_rotated = (a >> b[4:0]);
351 562 lampret
 
352 504 lampret
`ifdef OR1200_IMPL_ALU_ROTATE
353
                `OR1200_SHROTOP_ROR :
354
                                shifted_rotated = (a << (6'd32-{1'b0, b[4:0]})) | (a >> b[4:0]);
355
`endif
356
                default:
357
                                shifted_rotated = ({32{a[31]}} << (6'd32-{1'b0, b[4:0]})) | a >> b[4:0];
358
        endcase
359
end
360
 
361
//
362
// First type of compare implementation
363
//
364
`ifdef OR1200_IMPL_ALU_COMP1
365
always @(comp_op or a_eq_b or a_lt_b) begin
366 788 lampret
        case(comp_op[2:0])       // synopsys parallel_case
367 504 lampret
                `OR1200_COP_SFEQ:
368 617 lampret
                        flagcomp = a_eq_b;
369 504 lampret
                `OR1200_COP_SFNE:
370 617 lampret
                        flagcomp = ~a_eq_b;
371 504 lampret
                `OR1200_COP_SFGT:
372 617 lampret
                        flagcomp = ~(a_eq_b | a_lt_b);
373 504 lampret
                `OR1200_COP_SFGE:
374 617 lampret
                        flagcomp = ~a_lt_b;
375 504 lampret
                `OR1200_COP_SFLT:
376 617 lampret
                        flagcomp = a_lt_b;
377 504 lampret
                `OR1200_COP_SFLE:
378 617 lampret
                        flagcomp = a_eq_b | a_lt_b;
379 504 lampret
                default:
380 617 lampret
                        flagcomp = 1'b0;
381 504 lampret
        endcase
382
end
383
`endif
384
 
385
//
386
// Second type of compare implementation
387
//
388
`ifdef OR1200_IMPL_ALU_COMP2
389
always @(comp_op or comp_a or comp_b) begin
390 788 lampret
        case(comp_op[2:0])       // synopsys parallel_case
391 504 lampret
                `OR1200_COP_SFEQ:
392 617 lampret
                        flagcomp = (comp_a == comp_b);
393 504 lampret
                `OR1200_COP_SFNE:
394 617 lampret
                        flagcomp = (comp_a != comp_b);
395 504 lampret
                `OR1200_COP_SFGT:
396 617 lampret
                        flagcomp = (comp_a > comp_b);
397 504 lampret
                `OR1200_COP_SFGE:
398 617 lampret
                        flagcomp = (comp_a >= comp_b);
399 504 lampret
                `OR1200_COP_SFLT:
400 617 lampret
                        flagcomp = (comp_a < comp_b);
401 504 lampret
                `OR1200_COP_SFLE:
402 617 lampret
                        flagcomp = (comp_a <= comp_b);
403 504 lampret
                default:
404 617 lampret
                        flagcomp = 1'b0;
405 504 lampret
        endcase
406
end
407
`endif
408
 
409
endmodule

powered by: WebSVN 2.1.0

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