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

Subversion Repositories or1k

[/] [or1k/] [branches/] [branch_speed_opt/] [or1200/] [rtl/] [verilog/] [or1200_alu.v] - Blame information for rev 794

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

powered by: WebSVN 2.1.0

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