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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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