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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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