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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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