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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [or1200/] [or1200_alu.v] - Blame information for rev 435

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 350 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's ALU                                                ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/project,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
// $Log: or1200_alu.v,v $
45
// Revision 2.0  2010/06/30 11:00:00  ORSoC
46
// Minor update: 
47
// Defines added, flags are corrected. 
48
 
49
// synopsys translate_off
50
`include "timescale.v"
51
// synopsys translate_on
52
`include "or1200_defines.v"
53
 
54
module or1200_alu(
55
        a, b, mult_mac_result, macrc_op,
56 403 julius
        alu_op, alu_op2, shrot_op, comp_op,
57 350 julius
        cust5_op, cust5_limm,
58
        result, flagforw, flag_we,
59
        cyforw, cy_we, carry, flag
60
);
61
 
62
parameter width = `OR1200_OPERAND_WIDTH;
63
 
64
//
65
// I/O
66
//
67
input   [width-1:0]              a;
68
input   [width-1:0]              b;
69
input   [width-1:0]              mult_mac_result;
70
input                           macrc_op;
71
input   [`OR1200_ALUOP_WIDTH-1:0]        alu_op;
72 403 julius
input   [`OR1200_ALUOP2_WIDTH-1:0]       alu_op2;
73 350 julius
input   [`OR1200_SHROTOP_WIDTH-1:0]      shrot_op;
74
input   [`OR1200_COMPOP_WIDTH-1:0]       comp_op;
75
input   [4:0]                    cust5_op;
76
input   [5:0]                    cust5_limm;
77
output  [width-1:0]              result;
78
output                          flagforw;
79
output                          flag_we;
80
output                          cyforw;
81
output                          cy_we;
82
input                           carry;
83
input         flag;
84
 
85
//
86
// Internal wires and regs
87
//
88
reg     [width-1:0]              result;
89
reg     [width-1:0]              shifted_rotated;
90
reg     [width-1:0]              result_cust5;
91
reg                             flagforw;
92
reg                             flagcomp;
93
reg                             flag_we;
94
reg                             cy_we;
95
wire    [width-1:0]              comp_a;
96
wire    [width-1:0]              comp_b;
97
`ifdef OR1200_IMPL_ALU_COMP1
98
wire                            a_eq_b;
99
wire                            a_lt_b;
100
`endif
101
wire    [width-1:0]              result_sum;
102
`ifdef OR1200_IMPL_ADDC
103
wire    [width-1:0]              result_csum;
104
wire                            cy_csum;
105
`endif
106
wire    [width-1:0]              result_and;
107
wire                            cy_sum;
108
`ifdef OR1200_IMPL_SUB
109
wire                            cy_sub;
110
`endif
111
reg                             cyforw;
112
 
113
//
114
// Combinatorial logic
115
//
116
assign comp_a = {a[width-1] ^ comp_op[3] , a[width-2:0]};
117
assign comp_b = {b[width-1] ^ comp_op[3] , b[width-2:0]};
118
`ifdef OR1200_IMPL_ALU_COMP1
119
assign a_eq_b = (comp_a == comp_b);
120
assign a_lt_b = (comp_a < comp_b);
121
`endif
122
`ifdef OR1200_IMPL_SUB
123
assign cy_sub = a < b;
124
`endif
125
assign {cy_sum, result_sum} = a + b;
126
`ifdef OR1200_IMPL_ADDC
127
assign {cy_csum, result_csum} = a + b + {`OR1200_OPERAND_WIDTH'd0, carry};
128
`endif
129
assign result_and = a & b;
130
 
131
//
132
// Simulation check for bad ALU behavior
133
//
134
`ifdef OR1200_WARNINGS
135
// synopsys translate_off
136
always @(result) begin
137
        if (result === 32'bx)
138
                $display("%t: WARNING: 32'bx detected on ALU result bus. Please check !", $time);
139
end
140
// synopsys translate_on
141
`endif
142
 
143
//
144
// Central part of the ALU
145
//
146 403 julius
always @(alu_op or alu_op2 or a or b or result_sum or result_and or macrc_op
147
         or shifted_rotated or mult_mac_result or flag or result_cust5 or carry
148 350 julius
`ifdef OR1200_IMPL_ADDC
149
         or result_csum
150
`endif
151
) begin
152
`ifdef OR1200_CASE_DEFAULT
153 363 julius
        casez (alu_op)          // synopsys parallel_case
154 350 julius
`else
155 363 julius
        casez (alu_op)          // synopsys full_case parallel_case
156 350 julius
`endif
157 403 julius
`ifdef OR1200_IMPL_ALU_FFL1
158
                `OR1200_ALUOP_FFL1: begin
159
`ifdef OR1200_CASE_DEFAULT
160
                   casez (alu_op2) // synopsys parallel_case
161
`else
162
                   casez (alu_op2) // synopsys full_case parallel_case
163
`endif
164
                     0: begin // FF1
165 350 julius
                        result = a[0] ? 1 : a[1] ? 2 : a[2] ? 3 : a[3] ? 4 : a[4] ? 5 : a[5] ? 6 : a[6] ? 7 : a[7] ? 8 : a[8] ? 9 : a[9] ? 10 : a[10] ? 11 : a[11] ? 12 : a[12] ? 13 : a[13] ? 14 : a[14] ? 15 : a[15] ? 16 : a[16] ? 17 : a[17] ? 18 : a[18] ? 19 : a[19] ? 20 : a[20] ? 21 : a[21] ? 22 : a[22] ? 23 : a[23] ? 24 : a[24] ? 25 : a[25] ? 26 : a[26] ? 27 : a[27] ? 28 : a[28] ? 29 : a[29] ? 30 : a[30] ? 31 : a[31] ? 32 : 0;
166 403 julius
                     end
167
                     default: begin // FL1
168
                        result = a[31] ? 32 : a[30] ? 31 : a[29] ? 30 : a[28] ? 29 : a[27] ? 28 : a[26] ? 27 : a[25] ? 26 : a[24] ? 25 : a[23] ? 24 : a[22] ? 23 : a[21] ? 22 : a[20] ? 21 : a[19] ? 20 : a[18] ? 19 : a[17] ? 18 : a[16] ? 17 : a[15] ? 16 : a[14] ? 15 : a[13] ? 14 : a[12] ? 13 : a[11] ? 12 : a[10] ? 11 : a[9] ? 10 : a[8] ? 9 : a[7] ? 8 : a[6] ? 7 : a[5] ? 6 : a[4] ? 5 : a[3] ? 4 : a[2] ? 3 : a[1] ? 2 : a[0] ? 1 : 0 ;
169
                     end
170
                   endcase // casez (alu_op2)
171
                end // case: `OR1200_ALUOP_FFL1
172
`endif
173 350 julius
                `OR1200_ALUOP_CUST5 : begin
174
                                result = result_cust5;
175
                end
176
                `OR1200_ALUOP_SHROT : begin
177
                                result = shifted_rotated;
178
                end
179
                `OR1200_ALUOP_ADD : begin
180
                                result = result_sum;
181
                end
182
`ifdef OR1200_IMPL_ADDC
183
                `OR1200_ALUOP_ADDC : begin
184
                                result = result_csum;
185
                end
186
`endif
187
`ifdef OR1200_IMPL_SUB
188
                `OR1200_ALUOP_SUB : begin
189
                                result = a - b;
190
                end
191
`endif
192
                `OR1200_ALUOP_XOR : begin
193
                                result = a ^ b;
194
                end
195
                `OR1200_ALUOP_OR  : begin
196
                                result = a | b;
197
                end
198
                `OR1200_ALUOP_MOVHI : begin
199
                                if (macrc_op) begin
200
                                        result = mult_mac_result;
201
                                end
202
                                else begin
203
                                        result = b << 16;
204
                                end
205
                end
206
`ifdef OR1200_MULT_IMPLEMENTED
207
`ifdef OR1200_DIV_IMPLEMENTED
208
                `OR1200_ALUOP_DIV,
209
                `OR1200_ALUOP_DIVU,
210
`endif
211 435 julius
                `OR1200_ALUOP_MUL,
212
                `OR1200_ALUOP_MULU : begin
213 350 julius
                                result = mult_mac_result;
214
                end
215
`endif
216
                `OR1200_ALUOP_CMOV: begin
217
                        result = flag ? a : b;
218
                end
219
 
220
`ifdef OR1200_CASE_DEFAULT
221
                default: begin
222
`else
223
                `OR1200_ALUOP_COMP, `OR1200_ALUOP_AND: begin
224
`endif
225
                        result=result_and;
226
                end
227
        endcase
228
end
229
 
230
//
231
// l.cust5 custom instructions
232
//
233
// Examples for move byte, set bit and clear bit
234
//
235
always @(cust5_op or cust5_limm or a or b) begin
236 363 julius
        casez (cust5_op)                // synopsys parallel_case
237 350 julius
                5'h1 : begin
238 363 julius
                        casez (cust5_limm[1:0])
239 350 julius
                                2'h0: result_cust5 = {a[31:8], b[7:0]};
240
                                2'h1: result_cust5 = {a[31:16], b[7:0], a[7:0]};
241
                                2'h2: result_cust5 = {a[31:24], b[7:0], a[15:0]};
242
                                2'h3: result_cust5 = {b[7:0], a[23:0]};
243
                        endcase
244
                end
245
                5'h2 :
246
                        result_cust5 = a | (1 << cust5_limm);
247
                5'h3 :
248
                        result_cust5 = a & (32'hffffffff ^ (1 << cust5_limm));
249
//
250
// *** Put here new l.cust5 custom instructions ***
251
//
252
                default: begin
253
                        result_cust5 = a;
254
                end
255
        endcase
256
end
257
 
258
//
259
// Generate flag and flag write enable
260
//
261
always @(alu_op or result_sum or result_and or flagcomp
262
`ifdef OR1200_IMPL_ADDC
263
         or result_csum
264
`endif
265
) begin
266 363 julius
        casez (alu_op)          // synopsys parallel_case
267 350 julius
`ifdef OR1200_ADDITIONAL_FLAG_MODIFIERS
268
                `OR1200_ALUOP_ADD : begin
269
                        flagforw = (result_sum == 32'h0000_0000);
270
                        flag_we = 1'b1;
271
                end
272
`ifdef OR1200_IMPL_ADDC
273
                `OR1200_ALUOP_ADDC : begin
274
                        flagforw = (result_csum == 32'h0000_0000);
275
                        flag_we = 1'b1;
276
                end
277
`endif
278
                `OR1200_ALUOP_AND: begin
279
                        flagforw = (result_and == 32'h0000_0000);
280
                        flag_we = 1'b1;
281
                end
282
`endif
283
                `OR1200_ALUOP_COMP: begin
284
                        flagforw = flagcomp;
285
                        flag_we = 1'b1;
286
                end
287
                default: begin
288
                        flagforw = flagcomp;
289
                        flag_we = 1'b0;
290
                end
291
        endcase
292
end
293
 
294
//
295
// Generate SR[CY] write enable
296
//
297
always @(alu_op or cy_sum
298
`ifdef OR1200_IMPL_CY
299
`ifdef OR1200_IMPL_ADDC
300
        or cy_csum
301
`endif
302
`ifdef OR1200_IMPL_SUB
303
        or cy_sub
304
`endif
305
`endif
306
) begin
307 363 julius
        casez (alu_op)          // synopsys parallel_case
308 350 julius
`ifdef OR1200_IMPL_CY
309
                `OR1200_ALUOP_ADD : begin
310
                        cyforw = cy_sum;
311
                        cy_we = 1'b1;
312
                end
313
`ifdef OR1200_IMPL_ADDC
314
                `OR1200_ALUOP_ADDC: begin
315
                        cyforw = cy_csum;
316
                        cy_we = 1'b1;
317
                end
318
`endif
319
`ifdef OR1200_IMPL_SUB
320
                `OR1200_ALUOP_SUB: begin
321
                        cyforw = cy_sub;
322
                        cy_we = 1'b1;
323
                end
324
`endif
325
`endif
326
                default: begin
327
                        cyforw = 1'b0;
328
                        cy_we = 1'b0;
329
                end
330
        endcase
331
end
332
 
333
//
334
// Shifts and rotation
335
//
336
always @(shrot_op or a or b) begin
337
        case (shrot_op)         // synopsys parallel_case
338
        `OR1200_SHROTOP_SLL :
339
                                shifted_rotated = (a << b[4:0]);
340
                `OR1200_SHROTOP_SRL :
341
                                shifted_rotated = (a >> b[4:0]);
342
 
343
`ifdef OR1200_IMPL_ALU_ROTATE
344
                `OR1200_SHROTOP_ROR :
345
                                shifted_rotated = (a << (6'd32-{1'b0, b[4:0]})) | (a >> b[4:0]);
346
`endif
347
                default:
348
                                shifted_rotated = ({32{a[31]}} << (6'd32-{1'b0, b[4:0]})) | a >> b[4:0];
349
        endcase
350
end
351
 
352
//
353
// First type of compare implementation
354
//
355
`ifdef OR1200_IMPL_ALU_COMP1
356
always @(comp_op or a_eq_b or a_lt_b) begin
357
        case(comp_op[2:0])       // synopsys parallel_case
358
                `OR1200_COP_SFEQ:
359
                        flagcomp = a_eq_b;
360
                `OR1200_COP_SFNE:
361
                        flagcomp = ~a_eq_b;
362
                `OR1200_COP_SFGT:
363
                        flagcomp = ~(a_eq_b | a_lt_b);
364
                `OR1200_COP_SFGE:
365
                        flagcomp = ~a_lt_b;
366
                `OR1200_COP_SFLT:
367
                        flagcomp = a_lt_b;
368
                `OR1200_COP_SFLE:
369
                        flagcomp = a_eq_b | a_lt_b;
370
                default:
371
                        flagcomp = 1'b0;
372
        endcase
373
end
374
`endif
375
 
376
//
377
// Second type of compare implementation
378
//
379
`ifdef OR1200_IMPL_ALU_COMP2
380
always @(comp_op or comp_a or comp_b) begin
381
        case(comp_op[2:0])       // synopsys parallel_case
382
                `OR1200_COP_SFEQ:
383
                        flagcomp = (comp_a == comp_b);
384
                `OR1200_COP_SFNE:
385
                        flagcomp = (comp_a != comp_b);
386
                `OR1200_COP_SFGT:
387
                        flagcomp = (comp_a > comp_b);
388
                `OR1200_COP_SFGE:
389
                        flagcomp = (comp_a >= comp_b);
390
                `OR1200_COP_SFLT:
391
                        flagcomp = (comp_a < comp_b);
392
                `OR1200_COP_SFLE:
393
                        flagcomp = (comp_a <= comp_b);
394
                default:
395
                        flagcomp = 1'b0;
396
        endcase
397
end
398
`endif
399
 
400
endmodule

powered by: WebSVN 2.1.0

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