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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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