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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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