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

Subversion Repositories claw

[/] [claw/] [trunk/] [or1200_cpu/] [or1200_alu.v] - Blame information for rev 4

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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