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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel_26/] [or1200/] [rtl/] [verilog/] [or1200_alu.v] - Blame information for rev 1035

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

powered by: WebSVN 2.1.0

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