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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [common/] [FT64_alu.v] - Blame information for rev 50

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_alu.v
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//
23
// ============================================================================
24
//
25
`include "FT64_defines.vh"
26
 
27
module FT64_alu(rst, clk, ld, abort, instr, a, b, c, pc, tgt, tgt2, ven, vm, sbl, sbu,
28
    csr, o, ob, done, idle, excen, exc, thrd, ptrmask, state, mem, shift48);
29
parameter DBW = 64;
30
parameter BIG = 1'b1;
31
parameter SUP_VECTOR = 1;
32
parameter TRUE = 1'b1;
33
parameter FALSE = 1'b0;
34
parameter PTR = 20'hFFF01;
35
input rst;
36
input clk;
37
input ld;
38
input abort;
39
input [47:0] instr;
40
input [63:0] a;
41
input [63:0] b;
42
input [63:0] c;
43
input [31:0] pc;
44
input [11:0] tgt;
45
input [7:0] tgt2;
46
input [5:0] ven;
47
input [15:0] vm;
48
input [31:0] sbl;
49
input [31:0] sbu;
50
input [63:0] csr;
51
output reg [63:0] o;
52
output reg [63:0] ob;
53
output reg done;
54
output reg idle;
55
input [4:0] excen;
56
output reg [8:0] exc;
57
input thrd;
58
input [63:0] ptrmask;
59
input [1:0] state;
60
input mem;
61
input shift48;
62
 
63
integer n;
64
 
65
reg adrDone, adrIdle;
66
reg [63:0] addro;
67
reg [63:0] addr8;
68
 
69
wire [7:0] a8 = a[7:0];
70
wire [15:0] a16 = a[15:0];
71
wire [31:0] a32 = a[31:0];
72
wire [7:0] b8 = b[7:0];
73
wire [15:0] b16 = b[15:0];
74
wire [31:0] b32 = b[31:0];
75
wire [63:0] orb = instr[6] ? {34'd0,b[29:0]} : {50'd0,b[13:0]};
76
wire [63:0] andb = b;//((instr[6]==1'b1) ? {34'h3FFFFFFFF,b[29:0]} : {50'h3FFFFFFFFFFFF,b[13:0]});
77
 
78
wire [21:0] qimm = instr[39:18];
79
wire [63:0] imm = {{45{instr[39]}},instr[39:21]};
80
wire [DBW-1:0] divq, rem;
81
wire divByZero;
82
wire [15:0] prod8;
83
wire [31:0] prod16;
84
wire [63:0] prod32;
85
wire [DBW*2-1:0] prod;
86
wire mult_done8, mult_idle8, div_done8, div_idle8;
87
wire mult_done16, mult_idle16, div_done16, div_idle16;
88
wire mult_done32, mult_idle32, div_done32, div_idle32;
89
wire mult_done, mult_idle, div_done, div_idle;
90
wire aslo;
91
wire [6:0] clzo,cloo,cpopo;
92
wire [63:0] shftho;
93
reg [34:0] addr9;
94
 
95
function IsMul;
96
input [47:0] isn;
97
case(isn[`INSTRUCTION_OP])
98
`IVECTOR:
99 50 robfinch
  case(isn[`INSTRUCTION_S2])
100
  `VMUL,`VMULS:   IsMul = TRUE;
101
  default:    IsMul = FALSE;
102
  endcase
103
`R2:
104
  case(isn[`INSTRUCTION_S2])
105
  `MULU,`MULSU,`MUL: IsMul = TRUE;
106
  `MULUH,`MULSUH,`MULH: IsMul = TRUE;
107
  default:    IsMul = FALSE;
108
  endcase
109
`MULUI,`MULI:  IsMul = TRUE;
110 48 robfinch
default:    IsMul = FALSE;
111
endcase
112
endfunction
113
 
114
function IsDivmod;
115
input [47:0] isn;
116
case(isn[`INSTRUCTION_OP])
117
`IVECTOR:
118 50 robfinch
  case(isn[`INSTRUCTION_S2])
119
  `VDIV,`VDIVS:   IsDivmod = TRUE;
120
  default:    IsDivmod = FALSE;
121
  endcase
122
`R2:
123
  case(isn[`INSTRUCTION_S2])
124
  `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
125
  `MODU,`MODSU,`MOD: IsDivmod = TRUE;
126
  default:    IsDivmod = FALSE;
127
  endcase
128 48 robfinch
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
129
default:    IsDivmod = FALSE;
130
endcase
131
endfunction
132
 
133
function IsSgn;
134
input [47:0] isn;
135
case(isn[`INSTRUCTION_OP])
136
`IVECTOR:
137
    case(isn[`INSTRUCTION_S2])
138
    `VMUL,`VMULS,`VDIV,`VDIVS:    IsSgn = TRUE;
139
    default:    IsSgn = FALSE;
140
    endcase
141 50 robfinch
`R2:
142
  case(isn[`INSTRUCTION_S2])
143
  `MUL,`DIV,`MOD,`MULH:   IsSgn = TRUE;
144
  default:    IsSgn = FALSE;
145
  endcase
146 48 robfinch
`MULI,`DIVI,`MODI:    IsSgn = TRUE;
147
default:    IsSgn = FALSE;
148
endcase
149
endfunction
150
 
151
function IsSgnus;
152
input [47:0] isn;
153
case(isn[`INSTRUCTION_OP])
154 50 robfinch
`R2:
155
  case(isn[`INSTRUCTION_S2])
156
  `MULSU,`MULSUH,`DIVSU,`MODSU:   IsSgnus = TRUE;
157
  default:    IsSgnus = FALSE;
158
  endcase
159 48 robfinch
default:    IsSgnus = FALSE;
160
endcase
161
endfunction
162
 
163
function IsShiftAndOp;
164
input [47:0] isn;
165
IsShiftAndOp = FALSE;
166
endfunction
167
 
168
wire [2:0] sz =
169
    instr[`INSTRUCTION_OP]==`IVECTOR ? 2'd3 :
170
    instr[`INSTRUCTION_S2]==`R1 ? instr[18:16] : instr[23:21];
171
 
172
wire [63:0] bfout,shfto;
173
wire [63:0] shftob;
174
wire [63:0] shftco;
175
 
176
FT64_bitfield #(DBW) ubf1
177
(
178
    .inst(instr),
179
    .a(a),
180
    .b(b),
181
    .c(c),
182
    .o(bfout),
183
    .masko()
184
);
185
 
186
FT64_multiplier #(DBW) umult1
187
(
188
        .rst(rst),
189
        .clk(clk),
190
        .ld(ld && IsMul(instr)),
191
        .abort(abort),
192
        .sgn(IsSgn(instr)),
193
        .sgnus(IsSgnus(instr)),
194
        .a(a),
195
        .b(b),
196
        .o(prod),
197
        .done(mult_done),
198
        .idle(mult_idle)
199
);
200
 
201
FT64_divider #(DBW) udiv1
202
(
203
        .rst(rst),
204
        .clk(clk),
205
        .ld(ld && IsDivmod(instr)),
206
        .abort(abort),
207
        .sgn(IsSgn(instr)),
208
        .sgnus(IsSgnus(instr)),
209
        .a(a),
210
        .b(b),
211
        .qo(divq),
212
        .ro(rem),
213
        .dvByZr(divByZero),
214
        .done(div_done),
215
        .idle(div_idle)
216
);
217
 
218
wire [5:0] bshift = instr[31:26]==`SHIFTR ? b : {instr[30],instr[17:13]};
219
 
220
FT64_shift ushft1
221
(
222
    .instr(instr),
223
    .a(a),
224
    .b(bshift),
225
    .res(shfto),
226
    .ov(aslo)
227
);
228
 
229
FT64_shifth ushfthL
230
(
231
    .instr(instr),
232
    .a(a[31:0]),
233
    .b(bshift),
234
    .res(shftho[31:0]),
235
    .ov()
236
);
237
 
238
FT64_shifth ushfthH
239
(
240
    .instr(instr),
241
    .a(a[63:32]),
242
    .b(b[63:32]),
243
    .res(shftho[63:32]),
244
    .ov()
245
);
246
 
247
FT64_shiftc ushftc0
248
(
249
    .instr(instr),
250
    .a(a[15:0]),
251
    .b(bshift),
252
    .res(shftco[15:0]),
253
    .ov()
254
);
255
 
256
FT64_shiftc ushftc1
257
(
258
    .instr(instr),
259
    .a(a[31:16]),
260
    .b(b[31:16]),
261
    .res(shftco[31:16]),
262
    .ov()
263
);
264
 
265
FT64_shiftc ushftc2
266
(
267
    .instr(instr),
268
    .a(a[47:32]),
269
    .b(b[47:32]),
270
    .res(shftco[47:32]),
271
    .ov()
272
);
273
 
274
FT64_shiftc ushftc3
275
(
276
    .instr(instr),
277
    .a(a[63:48]),
278
    .b(b[63:48]),
279
    .res(shftco[63:48]),
280
    .ov()
281
);
282
 
283
FT64_shiftb ushftb0
284
(
285
    .instr(instr),
286
    .a(a[7:0]),
287
    .b(bshift),
288
    .res(shftob[7:0]),
289
    .ov()
290
);
291
 
292
FT64_shiftb ushftb1
293
(
294
    .instr(instr),
295
    .a(a[15:8]),
296
    .b(b[15:8]),
297
    .res(shftob[15:8]),
298
    .ov()
299
);
300
 
301
FT64_shiftb ushftb2
302
(
303
    .instr(instr),
304
    .a(a[23:16]),
305
    .b(b[23:16]),
306
    .res(shftob[23:16]),
307
    .ov()
308
);
309
 
310
FT64_shiftb ushftb3
311
(
312
    .instr(instr),
313
    .a(a[31:24]),
314
    .b(b[31:24]),
315
    .res(shftob[31:24]),
316
    .ov()
317
);
318
 
319
FT64_shiftb ushftb4
320
(
321
    .instr(instr),
322
    .a(a[39:32]),
323
    .b(b[39:32]),
324
    .res(shftob[39:32]),
325
    .ov()
326
);
327
 
328
FT64_shiftb ushftb5
329
(
330
    .instr(instr),
331
    .a(a[47:40]),
332
    .b(b[47:40]),
333
    .res(shftob[47:40]),
334
    .ov()
335
);
336
 
337
FT64_shiftb ushftb6
338
(
339
    .instr(instr),
340
    .a(a[55:48]),
341
    .b(b[55:48]),
342
    .res(shftob[55:48]),
343
    .ov()
344
);
345
 
346
FT64_shiftb ushftb7
347
(
348
    .instr(instr),
349
    .a(a[63:56]),
350
    .b(b[63:56]),
351
    .res(shftob[63:56]),
352
    .ov()
353
);
354
 
355
cntlz64 uclz1
356
(
357
        .i(sz==2'd0 ? {56'hFFFFFFFFFFFFFF,a[7:0]} :
358
           sz==2'd1 ? {48'hFFFFFFFFFFFF,a[15:0]} :
359
           sz==2'd2 ? {32'hFFFFFFFF,a[31:0]} : a),
360
        .o(clzo)
361
);
362
 
363
cntlo64 uclo1
364
(
365
        .i(sz==2'd0 ? a[7:0] : sz==2'd1 ? a[15:0] : sz==2'd2 ? a[31:0] : a),
366
        .o(cloo)
367
);
368
 
369
cntpop64 ucpop1
370
(
371
        .i(sz==2'd0 ? a[7:0] : sz==2'd1 ? a[15:0] : sz==2'd2 ? a[31:0] : a),
372
        .o(cpopo)
373
);
374
 
375
wire [7:0] bcdaddo,bcdsubo;
376
wire [15:0] bcdmulo;
377
BCDAdd ubcd1 (1'b0,a,b,bcdaddo);
378
BCDSub ubcd2 (1'b0,a,b,bcdsubo);
379
BCDMul2 ubcd3 (a,b,bcdmulo);
380
 
381
wire [7:0] s8 = a[7:0] + b[7:0];
382
wire [15:0] s16 = a[15:0] + b[15:0];
383
wire [31:0] s32 = a[31:0] + b[31:0];
384
wire [7:0] d8 = a[7:0] - b[7:0];
385
wire [15:0] d16 = a[15:0] - b[15:0];
386
wire [31:0] d32 = a[31:0] - b[31:0];
387
wire [63:0] and64 = a & b;
388
wire [63:0] or64 = a | b;
389
wire [63:0] xor64 = a ^ b;
390
wire [63:0] redor64 = {63'd0,|a};
391
wire [63:0] redor32 = {63'd0,|a[31:0]};
392
wire [63:0] redor16 = {63'd0,|a[15:0]};
393
wire [63:0] redor8 = {63'd0,|a[7:0]};
394
wire [63:0] zxb10 = {54'd0,b[9:0]};
395
wire [63:0] sxb10 = {{54{b[9]}},b[9:0]};
396
wire [63:0] zxb26 = {38'd0,instr[47:32],instr[27:18]};
397
wire [63:0] sxb26 = {{38{instr[47]}},instr[47:32],instr[27:18]};
398
reg [15:0] mask;
399
wire [4:0] cpopom;
400
wire signed [63:0] as = a;
401
wire signed [63:0] bs = b;
402
wire signed [63:0] cs = c;
403
 
404
always @*
405
for (n = 0; n < 16; n = n + 1)
406
    if (n <= ven)
407
        mask[n] = 1'b1;
408
    else
409
        mask[n] = 1'b0;
410
 
411
cntpop16 ucpop2
412
(
413
        .i(vm & mask),
414
        .o(cpopom)
415
);
416
 
417
wire [5:0] lsto, fsto;
418
ffz24 uffo1
419
(
420
    .i(~{8'h00,a[15:0]}),
421
    .o(lsto)
422
);
423
 
424
flz24 uflo1
425
(
426
    .i(~{8'h00,a[15:0]}),
427
    .o(fsto)
428
);
429
 
430
wire [DBW-1:0] bmmo;
431
FT64_BMM ubmm1
432
(
433
        .op(1'b0),
434
        .a(a),
435
        .b(b),
436
        .o(bmmo)
437
);
438
 
439
always @*
440
begin
441
case(instr[`INSTRUCTION_OP])
442
`IVECTOR:
443
    if (SUP_VECTOR)
444
    case(instr[`INSTRUCTION_S2])
445
    `VABS:         o[63:0] = a[63] ? -a : a;
446
    `VSIGN:        o[63:0] = a[63] ? 64'hFFFFFFFFFFFFFFFF : a==64'd0 ? 64'd0 : 64'd1;
447
    `VMxx:
448
        case(instr[25:23])
449
            `VMAND:        o[63:0] = and64;
450
            `VMOR:         o[63:0] = or64;
451
            `VMXOR:        o[63:0] = xor64;
452
            `VMXNOR:       o[63:0] = ~(xor64);
453
            `VMPOP:        o[63:0] = {57'd0,cpopo};
454
            `VMFILL:       for (n = 0; n < 64; n = n + 1)
455
                               o[n] = (n < a);
456
                               // Change the following when VL > 16
457
            `VMFIRST:      o[63:0] = fsto==5'd31 ? 64'd64 : fsto;
458
            `VMLAST:       o[63:0] = lsto==5'd31 ? 64'd64 : lsto;
459
                endcase
460
    `VADD,`VADDS:  o[63:0] = vm[ven] ? a + b : c;
461
    `VSUB,`VSUBS:  o[63:0] = vm[ven] ? a - b : c;
462
    `VMUL,`VMULS:  o[63:0] = vm[ven] ? prod[DBW-1:0] : c;
463
    `VDIV,`VDIVS:  o[63:0] = BIG ? (vm[ven] ? divq : c) : 64'hCCCCCCCCCCCCCCCC;
464
    `VAND,`VANDS:  o[63:0] = vm[ven] ? a & b : c;
465
    `VOR,`VORS:    o[63:0] = vm[ven] ? a | b : c;
466
    `VXOR,`VXORS:  o[63:0] = vm[ven] ? a ^ b : c;
467
    `VCNTPOP:      o[63:0] = {57'd0,cpopo};
468
    `VSHLV:        o[63:0] = a;   // no masking here
469
    `VSHRV:        o[63:0] = a;
470
    `VCMPRSS:      o[63:0] = a;
471
    `VCIDX:        o[63:0] = a * ven;
472
    `VSCAN:        o[63:0] = a * (cpopom==0 ? 0 : cpopom-1);
473
    `VSxx,`VSxxS,
474
    `VSxxb,`VSxxSb:
475
        case({instr[26],instr[20:19]})
476
        `VSEQ:     begin
477
                       o[63:0] = c;
478
                       o[ven] = vm[ven] ? a==b : c[ven];
479
                   end
480
        `VSNE:     begin
481
                       o[63:0] = c;
482
                       o[ven] = vm[ven] ? a!=b : c[ven];
483
                   end
484
        `VSLT:      begin
485
                         o[63:0] = c;
486
                         o[ven] = vm[ven] ? $signed(a) < $signed(b) : c[ven];
487
                    end
488
        `VSGE:      begin
489
                         o[63:0] = c;
490
                         o[ven] = vm[ven] ? $signed(a) >= $signed(b) : c[ven];
491
                    end
492
        `VSLE:      begin
493
                          o[63:0] = c;
494
                          o[ven] = vm[ven] ? $signed(a) <= $signed(b) : c[ven];
495
                    end
496
        `VSGT:      begin
497
                         o[63:0] = c;
498
                         o[ven] = vm[ven] ? $signed(a) > $signed(b) : c[ven];
499
                    end
500
        default:        o[63:0] = 64'hCCCCCCCCCCCCCCCC;
501
        endcase
502
    `VSxxU,`VSxxSU,
503
    `VSxxUb,`VSxxSUb:
504
        case({instr[26],instr[20:19]})
505
        `VSEQ:     begin
506
                       o[63:0] = c;
507
                       o[ven] = vm[ven] ? a==b : c[ven];
508
                   end
509
        `VSNE:     begin
510
                       o[63:0] = c;
511
                       o[ven] = vm[ven] ? a!=b : c[ven];
512
                   end
513
        `VSLT:      begin
514
                         o[63:0] = c;
515
                         o[ven] = vm[ven] ? a < b : c[ven];
516
                    end
517
        `VSGE:      begin
518
                         o[63:0] = c;
519
                         o[ven] = vm[ven] ? a >= b : c[ven];
520
                    end
521
        `VSLE:      begin
522
                          o[63:0] = c;
523
                          o[ven] = vm[ven] ? a <= b : c[ven];
524
                    end
525
        `VSGT:      begin
526
                         o[63:0] = c;
527
                         o[ven] = vm[ven] ? a > b : c[ven];
528
                    end
529
        default:        o[63:0] = 64'hCCCCCCCCCCCCCCCC;
530
        endcase
531
    `VBITS2V:   o[63:0] = vm[ven] ? a[ven] : c;
532
    `V2BITS:    begin
533
                o[63:0] = b;
534
                o[ven] = vm[ven] ? a[0] : b[ven];
535
                end
536
    `VSHL,`VSHR,`VASR:  o[63:0] = BIG ? shfto : 64'hCCCCCCCCCCCCCCCC;
537
    `VXCHG:     o[63:0] = vm[ven] ? b : a;
538
    default:    o[63:0] = 64'hCCCCCCCCCCCCCCCC;
539
    endcase
540
    else
541
        o[63:0] <= 64'hCCCCCCCCCCCCCCCC;
542
`R2:
543
        if (instr[6])
544
                case(instr[47:42])
545
                `SHIFTR:
546
                        begin
547
                        case(instr[35:33])
548
                        `ASL,`ASR,`ROL,`ROR:
549
                                case(instr[32:30])      // size
550
                                3'd0:   addr8 = {{56{shftob[7]}},shftob[7:0]};
551
                                3'd1:   addr8 = {{48{shftob[15]}},shftco[15:0]};
552
                                3'd2:   addr8 = {{32{shftho[31]}},shftho[31:0]};
553
                                3'd3,3'd7:      addr8 = shfto;
554
                                3'd4:   addr8 = shftob;
555
                                3'd5:   addr8 = shftco;
556
                                3'd6:   addr8 = shftho;
557
                                endcase
558
                        `SHL,`SHR:
559
                                case(instr[32:30])      // size
560
                                3'd0:   addr8 = {56'd0,shftob[7:0]};
561
                                3'd1:   addr8 = {48'd0,shftco[15:0]};
562
                                3'd2:   addr8 = {32'd0,shftho[31:0]};
563
                                3'd3,3'd7:      addr8 = shfto;
564
                                3'd4:   addr8 = shftob;
565
                                3'd5:   addr8 = shftco;
566
                                3'd6:   addr8 = shftho;
567
                                endcase
568
                        default:        o[63:0] = 64'hDCDCDCDCDCDCDCDC;
569
                        endcase
570
                        case(instr[35:33])
571
                        `ASL,`ASR,`SHL,`SHR,`ROL,`ROR:
572
                                o[63:0] = addr9;
573
                        default:        o[63:0] = 64'hDCDCDCDCDCDCDCDC;
574
                        endcase
575
                        end
576
                `MIN:
577
                        case(instr[30:28])
578
                        3'd3:
579
                                if (as < bs && as < cs)
580
                                        o[63:0] = as;
581
                                else if (bs < cs)
582
                                        o[63:0] = bs;
583
                                else
584
                                        o[63:0] = cs;
585
                        endcase
586
                endcase
587
        else
588
            case(instr[`INSTRUCTION_S2])
589
            `BCD:
590
                case(instr[`INSTRUCTION_S1])
591
                `BCDADD:    o[63:0] = BIG ? bcdaddo :  64'hCCCCCCCCCCCCCCCC;
592
                `BCDSUB:    o[63:0] = BIG ? bcdsubo :  64'hCCCCCCCCCCCCCCCC;
593
                `BCDMUL:    o[63:0] = BIG ? bcdmulo :  64'hCCCCCCCCCCCCCCCC;
594
                default:    o[63:0] = 64'hDEADDEADDEADDEAD;
595
                endcase
596
            `MOV:       begin
597
                        o[63:0] = a;
598
                        end
599
            `VMOV:              o[63:0] = a;
600
            `R1:
601
                case(instr[`INSTRUCTION_S1])
602
                `CNTLZ:     o[63:0] = BIG ? {57'd0,clzo} : 64'hCCCCCCCCCCCCCCCC;
603
                `CNTLO:     o[63:0] = BIG ? {57'd0,cloo} : 64'hCCCCCCCCCCCCCCCC;
604
                `CNTPOP:    o[63:0] = BIG ? {57'd0,cpopo} : 64'hCCCCCCCCCCCCCCCC;
605
                `ABS:       case(sz)
606
                            2'd0:   o[63:0] = BIG ? (a[7] ? -a[7:0] : a[7:0]) : 64'hCCCCCCCCCCCCCCCC;
607
                            2'd1:   o[63:0] = BIG ? (a[15] ? -a[15:0] : a[15:0]) : 64'hCCCCCCCCCCCCCCCC;
608
                            2'd2:   o[63:0] = BIG ? (a[31] ? -a[31:0] : a[31:0]) : 64'hCCCCCCCCCCCCCCCC;
609
                            2'd3:   o[63:0] = BIG ? (a[63] ? -a : a) : 64'hCCCCCCCCCCCCCCCC;
610
                            endcase
611
                `NOT:   case(sz)
612
                        2'd0:   o[63:0] = ~|a[7:0];
613
                        2'd1:   o[63:0] = ~|a[15:0];
614
                        2'd2:   o[63:0] = ~|a[31:0];
615
                        2'd3:   o[63:0] = ~|a[63:0];
616
                        endcase
617
                `REDOR: case(sz)
618
                        2'd0:   o[63:0] = redor8;
619
                        2'd1:   o[63:0] = redor16;
620
                        2'd2:   o[63:0] = redor32;
621
                        2'd3:   o[63:0] = redor64;
622
                        endcase
623
                `ZXH:           o[63:0] = {32'd0,a[31:0]};
624
                `ZXC:           o[63:0] = {48'd0,a[15:0]};
625
                `ZXB:           o[63:0] = {56'd0,a[7:0]};
626
                `SXH:           o[63:0] = {{32{a[31]}},a[31:0]};
627
                `SXC:           o[63:0] = {{48{a[15]}},a[15:0]};
628
                `SXB:           o[63:0] = {{56{a[7]}},a[7:0]};
629
//              5'h1C:          o[63:0] = tmem[a[9:0]];
630
                default:    o = 64'hDEADDEADDEADDEAD;
631
                endcase
632
            `BMM:               o[63:0] = BIG ? bmmo : 64'hCCCCCCCCCCCCCCCC;
633
            `SHIFT31,
634
            `SHIFT63,
635
            `SHIFTR:
636
                begin
637
                        if (instr[25:23]==`SHL)
638
                                o[63:0] = shfto;
639
                        else
640
                                o[63:0] = BIG ? shfto : 64'hCCCCCCCCCCCCCCCC;
641
                        $display("BIG=%d",BIG);
642
                        if(!BIG)
643
                                $stop;
644
                end
645
            `ADD:   case(sz)
646
                        3'd0,3'd4:
647
                                begin
648
                                        o[7:0] = a[7:0] + b[7:0];
649
                                        o[15:8] = a[15:8] + b[15:8];
650
                                        o[23:16] = a[23:16] + b[23:16];
651
                                        o[31:24] = a[31:24] + b[31:24];
652
                                        o[39:32] = a[39:32] + b[39:32];
653
                                        o[47:40] = a[47:40] + b[47:40];
654
                                        o[55:48] = a[55:48] + b[55:48];
655
                                        o[63:56] = a[63:56] + b[63:56];
656
                                end
657
                        3'd1,3'd5:
658
                                begin
659
                                        o[15:0] = a[15:0] + b[15:0];
660
                                        o[31:16] = a[31:16] + b[31:16];
661
                                        o[47:32] = a[47:32] + b[47:32];
662
                                        o[63:48] = a[63:48] + b[63:48];
663
                                end
664
                        3'd2,3'd6:
665
                                begin
666
                                        o[31:0] = a[31:0] + b[31:0];
667
                                        o[63:32] = a[63:32] + b[63:32];
668
                                end
669
                    3'd3,3'd7:
670
                        begin
671
                                o[63:0] = a + b;
672
                        end
673
                    endcase
674
            `SUB:   case(sz)
675
                        3'd0,3'd4:
676
                                begin
677
                                        o[7:0] = a[7:0] - b[7:0];
678
                                        o[15:8] = a[15:8] - b[15:8];
679
                                        o[23:16] = a[23:16] - b[23:16];
680
                                        o[31:24] = a[31:24] - b[31:24];
681
                                        o[39:32] = a[39:32] - b[39:32];
682
                                        o[47:40] = a[47:40] - b[47:40];
683
                                        o[55:48] = a[55:48] - b[55:48];
684
                                        o[63:56] = a[63:56] - b[63:56];
685
                                end
686
                        3'd1,3'd5:
687
                                begin
688
                                        o[15:0] = a[15:0] - b[15:0];
689
                                        o[31:16] = a[31:16] - b[31:16];
690
                                        o[47:32] = a[47:32] - b[47:32];
691
                                        o[63:48] = a[63:48] - b[63:48];
692
                                end
693
                        3'd2,3'd6:
694
                                begin
695
                                        o[31:0] = a[31:0] - b[31:0];
696
                                        o[63:32] = a[63:32] - b[63:32];
697
                                end
698
                    3'd3,3'd7:
699
                        begin
700
                                o[63:0] = a - b;
701
                        end
702
                    endcase
703
            `SLT:   tskSlt(instr,instr[25:23],a,b,o);
704
            `SLTU:  tskSltu(instr,instr[25:23],a,b,o);
705
            `SLE:   tskSle(instr,instr[25:23],a,b,o);
706
            `SLEU:  tskSleu(instr,instr[25:23],a,b,o);
707
            `AND:   o[63:0] = and64;
708
            `OR:    o[63:0] = or64;
709
            `XOR:   o[63:0] = xor64;
710
            `NAND:  o[63:0] = ~and64;
711
            `NOR:   o[63:0] = ~or64;
712
            `XNOR:  o[63:0] = ~xor64;
713
            `SEI:       o[63:0] = a | instr[21:16];
714
            `RTI:       o[63:0] = a | instr[21:16];
715
            `CMOVEZ:    begin
716
                                o[63:0] = (a==64'd0) ? b : c;
717
                                end
718
            `CMOVNZ:    if (instr[41])
719
                                        o[63:0] = (a!=64'd0) ? b : {{48{instr[38]}},instr[38:28],instr[22:18]};
720
                                else
721
                                        o[63:0] = (a!=64'd0) ? b : c;
722
            `MUX:       for (n = 0; n < 64; n = n + 1)
723
                            o[n] <= a[n] ? b[n] : c[n];
724 50 robfinch
            `MULU:      o[63:0] = prod[DBW-1:0];
725
            `MULSU:     o[63:0] = prod[DBW-1:0];
726
            `MUL:       o[63:0] = prod[DBW-1:0];
727
            `DIVU:   o[63:0] = BIG ? divq : 64'hCCCCCCCCCCCCCCCC;
728
            `DIVSU:  o[63:0] = BIG ? divq : 64'hCCCCCCCCCCCCCCCC;
729
            `DIV:    o[63:0] = BIG ? divq : 64'hCCCCCCCCCCCCCCCC;
730
            `MODU:   o[63:0] = BIG ? rem : 64'hCCCCCCCCCCCCCCCC;
731
            `MODSU:  o[63:0] = BIG ? rem : 64'hCCCCCCCCCCCCCCCC;
732
            `MOD:    o[63:0] = BIG ? rem : 64'hCCCCCCCCCCCCCCCC;
733 48 robfinch
                        `LEAX:
734
                                        begin
735
                                        o[63:0] = BIG ? a + (b << instr[22:21]) : 64'hCCCCCCCCEEEEEEEE;
736
                                        o[63:44] = PTR;
737
                                        end
738
            `MIN:       case(sz)
739
                                3'd0,3'd4:
740
                                        begin
741
                                        o[7:0] = BIG ? ($signed(a[7:0]) < $signed(b[7:0]) ? a[7:0] : b[7:0]) : 8'hCC;
742
                                        o[15:8] = BIG ? ($signed(a[15:8]) < $signed(b[15:8]) ? a[15:8] : b[15:8]) : 64'hCCCCCCCCCCCCCCCC;
743
                                        o[23:16] = BIG ? ($signed(a[23:16]) < $signed(b[23:16]) ? a[23:16] : b[23:16]) : 64'hCCCCCCCCCCCCCCCC;
744
                                        o[31:24] = BIG ? ($signed(a[31:24]) < $signed(b[31:24]) ? a[31:24] : b[31:24]) : 64'hCCCCCCCCCCCCCCCC;
745
                                        o[39:32] = BIG ? ($signed(a[39:32]) < $signed(b[39:32]) ? a[39:32] : b[39:32]) : 64'hCCCCCCCCCCCCCCCC;
746
                                        o[47:40] = BIG ? ($signed(a[47:40]) < $signed(b[47:40]) ? a[47:40] : b[47:40]) : 64'hCCCCCCCCCCCCCCCC;
747
                                        o[55:48] = BIG ? ($signed(a[55:48]) < $signed(b[55:48]) ? a[55:48] : b[55:48]) : 64'hCCCCCCCCCCCCCCCC;
748
                                        o[63:56] = BIG ? ($signed(a[63:56]) < $signed(b[63:56]) ? a[63:56] : b[63:56]) : 64'hCCCCCCCCCCCCCCCC;
749
                                        end
750
                                3'd1,3'd5:
751
                                        begin
752
                                        o[15:0] = BIG ? ($signed(a[15:0]) < $signed(b[15:0]) ? a[15:0] : b[15:0]) : 64'hCCCCCCCCCCCCCCCC;
753
                                        o[32:16] = BIG ? ($signed(a[32:16]) < $signed(b[32:16]) ? a[32:16] : b[32:16]) : 64'hCCCCCCCCCCCCCCCC;
754
                                        o[47:32] = BIG ? ($signed(a[47:32]) < $signed(b[47:32]) ? a[47:32] : b[47:32]) : 64'hCCCCCCCCCCCCCCCC;
755
                                        o[63:48] = BIG ? ($signed(a[63:48]) < $signed(b[63:48]) ? a[63:48] : b[63:48]) : 64'hCCCCCCCCCCCCCCCC;
756
                                        end
757
                                3'd2,3'd6:
758
                                        begin
759
                                        o[31:0] = BIG ? ($signed(a[31:0]) < $signed(b[31:0]) ? a[31:0] : b[31:0]) : 64'hCCCCCCCCCCCCCCCC;
760
                                        o[63:32] = BIG ? ($signed(a[63:32]) < $signed(b[63:32]) ? a[63:32] : b[63:32]) : 64'hCCCCCCCCCCCCCCCC;
761
                                        end
762
                                        3'd3,3'd7:
763
                                                begin
764
                                        o[63:0] = BIG ? ($signed(a) < $signed(b) ? a : b) : 64'hCCCCCCCCCCCCCCCC;
765
                                        end
766
                                endcase
767
            `MAX:       case(sz)
768
                                3'd0,3'd4:
769
                                        begin
770
                                        o[7:0] = BIG ? ($signed(a[7:0]) > $signed(b[7:0]) ? a[7:0] : b[7:0]) : 64'hCCCCCCCCCCCCCCCC;
771
                                        o[15:8] = BIG ? ($signed(a[15:8]) > $signed(b[15:8]) ? a[15:8] : b[15:8]) : 64'hCCCCCCCCCCCCCCCC;
772
                                        o[23:16] = BIG ? ($signed(a[23:16]) > $signed(b[23:16]) ? a[23:16] : b[23:16]) : 64'hCCCCCCCCCCCCCCCC;
773
                                        o[31:24] = BIG ? ($signed(a[31:24]) > $signed(b[31:24]) ? a[31:24] : b[31:24]) : 64'hCCCCCCCCCCCCCCCC;
774
                                        o[39:32] = BIG ? ($signed(a[39:32]) > $signed(b[39:32]) ? a[39:32] : b[39:32]) : 64'hCCCCCCCCCCCCCCCC;
775
                                        o[47:40] = BIG ? ($signed(a[47:40]) > $signed(b[47:40]) ? a[47:40] : b[47:40]) : 64'hCCCCCCCCCCCCCCCC;
776
                                        o[55:48] = BIG ? ($signed(a[55:48]) > $signed(b[55:48]) ? a[55:48] : b[55:48]) : 64'hCCCCCCCCCCCCCCCC;
777
                                        o[63:56] = BIG ? ($signed(a[63:56]) > $signed(b[63:56]) ? a[63:56] : b[63:56]) : 64'hCCCCCCCCCCCCCCCC;
778
                                        end
779
                                3'd1,3'd5:
780
                                        begin
781
                                        o[15:0] = BIG ? ($signed(a[15:0]) > $signed(b[15:0]) ? a[15:0] : b[15:0]) : 64'hCCCCCCCCCCCCCCCC;
782
                                        o[32:16] = BIG ? ($signed(a[32:16]) > $signed(b[32:16]) ? a[32:16] : b[32:16]) : 64'hCCCCCCCCCCCCCCCC;
783
                                        o[47:32] = BIG ? ($signed(a[47:32]) > $signed(b[47:32]) ? a[47:32] : b[47:32]) : 64'hCCCCCCCCCCCCCCCC;
784
                                        o[63:48] = BIG ? ($signed(a[63:48]) > $signed(b[63:48]) ? a[63:48] : b[63:48]) : 64'hCCCCCCCCCCCCCCCC;
785
                                        end
786
                                3'd2,3'd6:
787
                                        begin
788
                                        o[31:0] = BIG ? ($signed(a[31:0]) > $signed(b[31:0]) ? a[31:0] : b[31:0]) : 64'hCCCCCCCCCCCCCCCC;
789
                                        o[63:32] = BIG ? ($signed(a[63:32]) > $signed(b[63:32]) ? a[63:32] : b[63:32]) : 64'hCCCCCCCCCCCCCCCC;
790
                                        end
791
                                        3'd3,3'd7:
792
                                                begin
793
                                        o[63:0] = BIG ? ($signed(a) > $signed(b) ? a : b) : 64'hCCCCCCCCCCCCCCCC;
794
                                        end
795
                                endcase
796
            `MAJ:               o = (a & b) | (a & c) | (b & c);
797
            `CHK:       o[63:0] = (a >= b && a < c);
798
            /*
799
            `RTOP:              case(c[5:0])
800
                                `RTADD: o = a + b;
801
                                `RTSUB: o = a - b;
802
                                `RTAND: o = and64;
803
                                `RTOR:  o = or64;
804
                                `RTXOR: o = xor64;
805
                                `RTNAND:        o = ~and64;
806
                                `RTNOR: o = ~or64;
807
                                `RTXNOR:        o = ~xor64;
808
                                `RTSLT: o = as < bs;
809
                                `RTSGE: o = as >= bs;
810
                                `RTSLE: o = as <= bs;
811
                                `RTSGT: o = as > bs;
812
                                `RTSEQ: o = as==bs;
813
                                `RTSNE: o = as!=bs;
814
                                endcase
815
            */
816
            default:    o[63:0] = 64'hDEADDEADDEADDEAD;
817
            endcase
818
`MEMNDX:
819
        if (instr[7:6]==2'b00)
820
                case(instr[`INSTRUCTION_S2])
821
                `LVX,
822
    `LBX,`LBUX,`LCX,`LCUX,
823
    `LHX,`LHUX,`LWX,`LWRX,`SBX,`SCX,`SHX,`SWX,`SWCX:
824
                                if (BIG) begin
825
                                        o[63:0] = a + (b << instr[24:23]);
826
                                end
827
                                else
828
                                        o[63:0] = 64'hCCCCCCCCEEEEEEEE;
829
    `LVX,`SVX:  if (BIG) begin
830
                                o[63:0] = a + (b << 2'd3);
831
                        end
832
                        else
833
                                o[63:0] = 64'hCCCCCCCCCCCCCCCC;
834
    `LVWS,`SVWS:
835
                        if (BIG) begin
836
                                o[63:0] = a + ({b * ven,3'b000});
837
                        end
838
                        else
839
                                o[63:0] = 64'hCCCCCCCCCCCCCCCC;
840
                endcase
841
        else
842
                o[63:0] = 64'hDEADDEADDEADDEAD;
843
`AUIPC:
844
        begin
845
                if (instr[7:6]==2'b01)
846
                        o[63:0] = pc + {instr[47:13],30'd0};
847
                else
848
                        o[63:0] = pc + {{15{instr[31]}},instr[31:13],30'd0};
849
                o[29:0] = 30'd0;
850
//              o[63:44] = PTR;
851
        end
852
`LUI:
853
        begin
854
                if (instr[7:6]==2'b01)
855
                        o[63:0] = {instr[47:13],30'd0};
856
                else
857
                        o[63:0] = {{15{instr[31]}},instr[31:13],30'd0};
858
        end
859
`ADDI:  o[63:0] = a + b;
860
`SLTI:  o[63:0] = $signed(a) < $signed(b);
861
`SLTUI: o[63:0] = a < b;
862
`SGTI:  o[63:0] = $signed(a) > $signed(b);
863
`SGTUI: o[63:0] = a > b;
864
`ANDI:  o[63:0] = a & andb;
865
`ORI:           o[63:0] = a | orb;
866
`XORI:  o[63:0] = a ^ orb;
867
`XNORI: o[63:0] = ~(a ^ orb);
868
`MULUI:         o[63:0] = prod[DBW-1:0];
869
`MULI:          o[63:0] = prod[DBW-1:0];
870
`DIVUI:         o[63:0] = BIG ? divq : 64'hCCCCCCCCCCCCCCCC;
871
`DIVI:          o[63:0] = BIG ? divq : 64'hCCCCCCCCCCCCCCCC;
872
`MODI:          o[63:0] = BIG ? rem : 64'hCCCCCCCCCCCCCCCC;
873
`LB,`LBU,`SB:   o[63:0] = a + b;
874
`Lx,`LxU,`Sx:
875
                        begin
876
                                o[63:0] = a + b;
877
                                casez(b[2:0])
878
                                3'b100: o[2:0] = 3'd0;   // LW / SW
879
                                3'b?10: o[1:0] = 2'd0;   // LH / LHU / SH
880
                                3'b??1: o[0] = 1'd0;             // LC / LCU / SC
881
                                endcase
882
                        end
883
`LWR,`SWC,`CAS:
884
                        begin
885
                                o[63:0] = a + b;
886
                        end
887
`LVx:           begin
888
                                o[63:0] = a + (instr[6] ? sxb26 : sxb10);
889
                        end
890
`LV,`SV:    begin
891
                                o[63:0] = a + b + {ven,3'b0};
892
                        end
893
`CSRRW:     case(instr[27:18])
894
                        10'h044: o[63:0] = BIG ? csr | {thrd,24'h0} : 64'hDDDDDDDDDDDDDDDD;
895
                        default:        o[63:0] = BIG ? csr : 64'hDDDDDDDDDDDDDDDD;
896
                        endcase
897
`BITFIELD:  o[63:0] = BIG ? bfout : 64'hCCCCCCCCCCCCCCCC;
898
default:    o[63:0] = 64'hDEADDEADDEADDEAD;
899
endcase
900
end
901
 
902
always @(posedge clk)
903
        if (ld)
904
                adrDone <= FALSE;
905
        else if (mem|shift48)
906
                adrDone <= TRUE;
907
 
908
always @(posedge clk)
909
case(instr[`INSTRUCTION_OP])
910
`R2:
911
        if (instr[`INSTRUCTION_L2]==2'b01)
912
                case(instr[47:42])
913
                `ADD,`SUB,
914
                `AND,`OR,`XOR,`NAND,`NOR,`XNOR,
915
                `SHIFTR:
916
                        case(instr[41:36])
917
                        `R1:
918
                                case(instr[22:18])
919
                                `COM:   addro[63:0] = ~addr8;
920
                                `NOT:   addro[63:0] = ~|addr8;
921
                                `NEG:   addro[63:0] = -addr8;
922
                                default:        addro[63:0] = 64'hDCDCDCDCDCDCDCDC;
923
                                endcase
924
                        `ADD:   addro[63:0] = addr8 + c;
925
                        `SUB:   addro[63:0] = addr8 - c;
926
                        `AND:   addro[63:0] = addr8 & c;
927
                        `OR:    addro[63:0] = addr8 | c;
928
                        `XOR:   addro[63:0] = addr8 ^ c;
929
                        default:        addro[63:0] = 64'hDCDCDCDCDCDCDCDC;
930
                        endcase
931
                default:        addro[63:0] = 64'hDCDCDCDCDCDCDCDC;
932
                endcase
933
        else
934
           addro = 64'hCCCCCCCCCCCCCCCE;
935
default:        addro = 64'hCCCCCCCCCCCCCCCE;
936
endcase
937
 
938
reg sao_done, sao_idle;
939
 
940
// Generate done signal
941
always @*
942
if (rst)
943
        done <= TRUE;
944
else begin
945
        if (IsMul(instr))
946
                done <= mult_done;
947
        else if (IsDivmod(instr) & BIG)
948
                done <= div_done;
949
        else if (IsShiftAndOp(instr) & BIG)
950
                done <= sao_done;
951
        else if (shift48)
952
                done <= adrDone;
953
        else
954
                done <= TRUE;
955
end
956
 
957
// Generate idle signal
958
always @*
959
if (rst)
960
        idle <= TRUE;
961
else begin
962
        if (IsMul(instr))
963
                idle <= mult_idle;
964
        else if (IsDivmod(instr) & BIG)
965
                idle <= div_idle;
966
        else if (IsShiftAndOp(instr) & BIG)
967
                idle <= sao_idle;
968
        else if (shift48)
969
                idle <= adrIdle;
970
        else
971
                idle <= TRUE;
972
end
973
 
974
function fnOverflow;
975
input op;   // 0 = add, 1=sub
976
input a;
977
input b;
978
input s;
979
fnOverflow = (op ^ s ^ b) & (~op ^ a ^ b);
980
endfunction
981
 
982
always @*
983
begin
984
if ((tgt[4:0]==5'd31 || tgt[4:0]==5'd30) && (o[31:0] < sbl || o[31:0] > sbu))
985
    exc <= `FLT_STK;
986
else
987
case(instr[`INSTRUCTION_OP])
988
`R2:
989
    case(instr[`INSTRUCTION_S2])
990
    `ADD:   exc <= (fnOverflow(0,a[63],b[63],o[63]) & excen[0] & instr[24]) ? `FLT_OFL : `FLT_NONE;
991
    `SUB:   exc <= (fnOverflow(1,a[63],b[63],o[63]) & excen[1] & instr[24]) ? `FLT_OFL : `FLT_NONE;
992
    `ASL,`ASLI:     exc <= (BIG & aslo & excen[2]) ? `FLT_OFL : `FLT_NONE;
993
    `MUL,`MULSU:    exc <= prod[63] ? (prod[127:64] != 64'hFFFFFFFFFFFFFFFF && excen[3] ? `FLT_OFL : `FLT_NONE ):
994
                           (prod[127:64] != 64'd0 && excen[3] ? `FLT_OFL : `FLT_NONE);
995
    `MULU:      exc <= prod[127:64] != 64'd0 && excen[3] ? `FLT_OFL : `FLT_NONE;
996 50 robfinch
    `DIV,`DIVSU,`DIVU: exc <= BIG && excen[4] & divByZero ? `FLT_DBZ : `FLT_NONE;
997
    `MOD,`MODSU,`MODU: exc <= BIG && excen[4] & divByZero ? `FLT_DBZ : `FLT_NONE;
998 48 robfinch
    default:    exc <= `FLT_NONE;
999
    endcase
1000
`MULI:    exc <= prod[63] ? (prod[127:64] != 64'hFFFFFFFFFFFFFFFF & excen[3] ? `FLT_OFL : `FLT_NONE):
1001
                                    (prod[127:64] != 64'd0 & excen[3] ? `FLT_OFL : `FLT_NONE);
1002
`DIVI: exc <= BIG & excen[4] & divByZero & instr[27] ? `FLT_DBZ : `FLT_NONE;
1003
`MODI: exc <= BIG & excen[4] & divByZero & instr[27] ? `FLT_DBZ : `FLT_NONE;
1004
default:    exc <= `FLT_NONE;
1005
endcase
1006
end
1007
 
1008
reg [63:0] aa, bb;
1009
 
1010
always @(posedge clk)
1011
begin
1012
        aa <= shfto;
1013
        bb <= c;
1014
end
1015
 
1016
task tskSlt;
1017
input [47:0] instr;
1018
input [2:0] sz;
1019
input [63:0] a;
1020
input [63:0] b;
1021
output [63:0] o;
1022
begin
1023
        case(sz[2:0])
1024
  3'd0:   o[63:0] = $signed(a[7:0]) < $signed(b[7:0]);
1025
  3'd1:   o[63:0] = $signed(a[15:0]) < $signed(b[15:0]);
1026
  3'd2:   o[63:0] = $signed(a[31:0]) < $signed(b[31:0]);
1027
  3'd3:   o[63:0] = $signed(a) < $signed(b);
1028
  3'd4:         o[63:0] = {
1029
                                                        7'h0,$signed(a[7:0]) < $signed(b[7:0]),
1030
                                                        7'h0,$signed(a[15:8]) < $signed(b[15:8]),
1031
                                                        7'h0,$signed(a[23:16]) < $signed(b[23:16]),
1032
                                                        7'h0,$signed(a[31:24]) < $signed(b[31:24]),
1033
                                                        7'h0,$signed(a[39:32]) < $signed(b[39:32]),
1034
                                                        7'h0,$signed(a[47:40]) < $signed(b[47:40]),
1035
                                                        7'h0,$signed(a[55:48]) < $signed(b[55:48]),
1036
                                                        7'h0,$signed(a[63:56]) < $signed(b[63:56])
1037
                                                        };
1038
  3'd5:         o[63:0] = {
1039
                                                        15'h0,$signed(a[15:0]) < $signed(b[15:0]),
1040
                                                        15'h0,$signed(a[31:16]) < $signed(b[31:16]),
1041
                                                        15'h0,$signed(a[47:32]) < $signed(b[47:32]),
1042
                                                        15'h0,$signed(a[63:48]) < $signed(b[63:48])
1043
                                                        };
1044
  3'd6:         o[63:0] = {
1045
                                                        31'h0,$signed(a[31:0]) < $signed(b[31:0]),
1046
                                                        31'h0,$signed(a[63:32]) < $signed(b[63:32])
1047
                                                        };
1048
        3'd7:           o[63:0] = $signed(a[63:0]) < $signed(b[63:0]);
1049
  endcase
1050
end
1051
endtask
1052
 
1053
task tskSle;
1054
input [47:0] instr;
1055
input [2:0] sz;
1056
input [63:0] a;
1057
input [63:0] b;
1058
output [63:0] o;
1059
begin
1060
        case(sz[2:0])
1061
  3'd0:   o[63:0] = $signed(a[7:0]) <= $signed(b[7:0]);
1062
  3'd1:   o[63:0] = $signed(a[15:0]) <= $signed(b[15:0]);
1063
  3'd2:   o[63:0] = $signed(a[31:0]) <= $signed(b[31:0]);
1064
  3'd3:   o[63:0] = $signed(a) <= $signed(b);
1065
  3'd4:         o[63:0] = {
1066
                                                        7'h0,$signed(a[7:0]) <= $signed(b[7:0]),
1067
                                                        7'h0,$signed(a[15:8]) <= $signed(b[15:8]),
1068
                                                        7'h0,$signed(a[23:16]) <= $signed(b[23:16]),
1069
                                                        7'h0,$signed(a[31:24]) <= $signed(b[31:24]),
1070
                                                        7'h0,$signed(a[39:32]) <= $signed(b[39:32]),
1071
                                                        7'h0,$signed(a[47:40]) <= $signed(b[47:40]),
1072
                                                        7'h0,$signed(a[55:48]) <= $signed(b[55:48]),
1073
                                                        7'h0,$signed(a[63:56]) <= $signed(b[63:56])
1074
                                                        };
1075
  3'd5:         o[63:0] = {
1076
                                                        15'h0,$signed(a[15:0]) <= $signed(b[15:0]),
1077
                                                        15'h0,$signed(a[31:16]) <= $signed(b[31:16]),
1078
                                                        15'h0,$signed(a[47:32]) <= $signed(b[47:32]),
1079
                                                        15'h0,$signed(a[63:48]) <= $signed(b[63:48])
1080
                                                        };
1081
  3'd6:         o[63:0] = {
1082
                                                        31'h0,$signed(a[31:0]) <= $signed(b[31:0]),
1083
                                                        31'h0,$signed(a[63:32]) <= $signed(b[63:32])
1084
                                                        };
1085
        3'd7:           o[63:0] = $signed(a[63:0]) <= $signed(b[63:0]);
1086
  endcase
1087
end
1088
endtask
1089
 
1090
task tskSltu;
1091
input [47:0] instr;
1092
input [2:0] sz;
1093
input [63:0] a;
1094
input [63:0] b;
1095
output [63:0] o;
1096
begin
1097
        case(sz[2:0])
1098
  3'd0:   o[63:0] = (a[7:0]) < (b[7:0]);
1099
  3'd1:   o[63:0] = (a[15:0]) < (b[15:0]);
1100
  3'd2:   o[63:0] = (a[31:0]) < (b[31:0]);
1101
  3'd3:   o[63:0] = (a) < (b);
1102
  3'd4:         o[63:0] = {
1103
                                                        7'h0,(a[7:0]) < (b[7:0]),
1104
                                                        7'h0,(a[15:8]) < (b[15:8]),
1105
                                                        7'h0,(a[23:16]) < (b[23:16]),
1106
                                                        7'h0,(a[31:24]) < (b[31:24]),
1107
                                                        7'h0,(a[39:32]) < (b[39:32]),
1108
                                                        7'h0,(a[47:40]) < (b[47:40]),
1109
                                                        7'h0,(a[55:48]) < (b[55:48]),
1110
                                                        7'h0,(a[63:56]) < (b[63:56])
1111
                                                        };
1112
  3'd5:         o[63:0] = {
1113
                                                        15'h0,(a[15:0]) < (b[15:0]),
1114
                                                        15'h0,(a[31:16]) < (b[31:16]),
1115
                                                        15'h0,(a[47:32]) < (b[47:32]),
1116
                                                        15'h0,(a[63:48]) < (b[63:48])
1117
                                                        };
1118
  3'd6:         o[63:0] = {
1119
                                                        31'h0,(a[31:0]) < (b[31:0]),
1120
                                                        31'h0,(a[63:32]) < (b[63:32])
1121
                                                        };
1122
        3'd7:           o[63:0] = (a[63:0]) < (b[63:0]);
1123
  endcase
1124
end
1125
endtask
1126
 
1127
task tskSleu;
1128
input [47:0] instr;
1129
input [2:0] sz;
1130
input [63:0] a;
1131
input [63:0] b;
1132
output [63:0] o;
1133
begin
1134
        case(sz[2:0])
1135
  3'd0:   o[63:0] = (a[7:0]) <= (b[7:0]);
1136
  3'd1:   o[63:0] = (a[15:0]) <= (b[15:0]);
1137
  3'd2:   o[63:0] = (a[31:0]) <= (b[31:0]);
1138
  3'd3:   o[63:0] = (a) <= (b);
1139
  3'd4:         o[63:0] = {
1140
                                                        7'h0,(a[7:0]) <= (b[7:0]),
1141
                                                        7'h0,(a[15:8]) <= (b[15:8]),
1142
                                                        7'h0,(a[23:16]) <= (b[23:16]),
1143
                                                        7'h0,(a[31:24]) <= (b[31:24]),
1144
                                                        7'h0,(a[39:32]) <= (b[39:32]),
1145
                                                        7'h0,(a[47:40]) <= (b[47:40]),
1146
                                                        7'h0,(a[55:48]) <= (b[55:48]),
1147
                                                        7'h0,(a[63:56]) <= (b[63:56])
1148
                                                        };
1149
  3'd5:         o[63:0] = {
1150
                                                        15'h0,(a[15:0]) <= (b[15:0]),
1151
                                                        15'h0,(a[31:16]) <= (b[31:16]),
1152
                                                        15'h0,(a[47:32]) <= (b[47:32]),
1153
                                                        15'h0,(a[63:48]) <= (b[63:48])
1154
                                                        };
1155
  3'd6:         o[63:0] = {
1156
                                                        31'h0,(a[31:0]) <= (b[31:0]),
1157
                                                        31'h0,(a[63:32]) <= (b[63:32])
1158
                                                        };
1159
        3'd7:           o[63:0] = (a[63:0]) <= (b[63:0]);
1160
  endcase
1161
end
1162
endtask
1163
 
1164
endmodule

powered by: WebSVN 2.1.0

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