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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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