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

Subversion Repositories mips789

[/] [mips789/] [trunk/] [core/] [EXEC_stage.v] - Blame information for rev 64

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 64 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
`include "mips789_defs.v"
15
 
16
module exec_stage
17
    (
18
    input clk,
19
    input rst,
20
    input spc_cls_i,
21
    input [4:0] alu_func,
22
    input [2:0] dmem_fw_ctl,
23
    input [31:0] ext_i,
24
    input [31:0] fw_alu,
25
    input [31:0] fw_dmem,
26
    input [1:0] muxa_ctl_i,
27
    input [2:0] muxa_fw_ctl,
28
    input [1:0] muxb_ctl_i,
29
    input [2:0] muxb_fw_ctl,
30
    input [31:0] pc_i,
31
    input [31:0] rs_i,
32
    input [31:0] rt_i,
33
    output [31:0] alu_ur_o,
34
    output [31:0] dmem_data_ur_o,
35
    output [31:0] zz_spc_o
36
    );
37
 
38
 
39
    wire [31:0] BUS2332;
40
    wire [31:0] BUS2446;
41
    wire [31:0] BUS468;
42
    wire [31:0] BUS476;
43
 
44
 
45
    mips_alu MIPS_alu
46
            (
47
                .a(BUS476),
48
                .b(BUS468),
49
                .c(alu_ur_o),
50
                .clk(clk),
51
                .ctl(alu_func),
52
                .rst(rst)
53
            );
54
 
55
    add32 add4
56
          (
57
              .d_i(pc_i),
58
              .d_o(BUS2446)
59
          );
60
 
61
 
62
    fwd_mux dmem_fw_mux
63
            (
64
                .dout(dmem_data_ur_o),
65
                .fw_alu(fw_alu),
66
                .fw_ctl(dmem_fw_ctl),
67
                .fw_dmem(fw_dmem),
68
                .din(rt_i)
69
            );
70
 
71
 
72
 
73
    alu_muxa i_alu_muxa
74
             (
75
                 .a_o(BUS476),
76
                 .ctl(muxa_ctl_i),
77
                 .ext(ext_i),
78
                 .fw_alu(fw_alu),
79
                 .fw_ctl(muxa_fw_ctl),
80
                 .fw_mem(fw_dmem),
81
                 .pc(BUS2332),
82
                 .rs(rs_i),
83
                 .spc(zz_spc_o)
84
             );
85
 
86
 
87
 
88
    alu_muxb i_alu_muxb
89
             (
90
                 .b_o(BUS468),
91
                 .ctl(muxb_ctl_i),
92
                 .ext(ext_i),
93
                 .fw_alu(fw_alu),
94
                 .fw_ctl(muxb_fw_ctl),
95
                 .fw_mem(fw_dmem),
96
                 .rt(rt_i)
97
             );
98
 
99
 
100
 
101
    r32_reg pc_nxt
102
            (
103
                .clk(clk),
104
                .r32_i(BUS2446),
105
                .r32_o(BUS2332)
106
            );
107
 
108
 
109
 
110
    r32_reg_cls spc
111
                (
112
                    .clk(clk),
113
                    .cls(spc_cls_i),
114
                    .r32_i(pc_i),
115
                    .r32_o(zz_spc_o)
116
                );
117
 
118
endmodule
119
 
120
module mips_alu(clk,rst,a,b,c,ctl);
121
    input  clk,rst ;
122
    input  [31:0] a,b ;
123
    output [31:0] c ;
124
    input  [4:0]ctl ;
125
 
126
    wire [31:0] mul_div_c;
127
    wire [31:0] alu_c;
128
    wire [31:0] shift_c;
129
 
130
`ifdef USE_MULDIV
131
 
132
    assign c = mul_div_c | alu_c | shift_c ;
133
`else
134
    assign c =   alu_c | shift_c ;
135
`endif
136
 
137
    `ifdef USE_MULDIV
138
 
139
    muldiv_ff muldiv_ff(
140
                  .clk_i(clk),
141
                  .rst_i(rst),//sys signal
142
                  .op_type(ctl),
143
                  .op1(a),
144
                  .op2(b),
145
                  //    .busy_o(busy),
146
                  .res(mul_div_c)
147
              );
148
 
149
   `endif
150
    shifter_tak mips_shifter(
151
                    .a(b),
152
                    .shift_out(shift_c),
153
                    .shift_func(ctl),
154
                    .shift_amount(a)
155
                );
156
 
157
    alu mips_alu(
158
            .a(a),
159
            .b(b),
160
            .alu_out(alu_c),
161
            .alu_func(ctl)
162
        );
163
 
164
endmodule
165
 
166
module alu_muxa(
167
        input [31:0]spc,
168
        input [31:0]pc,
169
        input [31:0]fw_mem,
170
        input [31:0]rs,
171
        input [31:0]fw_alu,
172
        input [31:0]ext,
173
        input [1:0] ctl,
174
        input [2:0] fw_ctl,
175
        output reg [31:0]a_o
176
    );
177
 
178
    always @(*)
179
    begin
180
        case (ctl)
181
            `MUXA_RS:   a_o = (fw_ctl ==`FW_ALU )?fw_alu:(fw_ctl==`FW_MEM)?fw_mem:rs;
182
            `MUXA_PC:   a_o = pc;
183
            `MUXA_EXT:  a_o = ext;
184
            `MUXA_SPC:  a_o = spc;
185
            default :   a_o = rs;
186
        endcase
187
    end
188
endmodule
189
 
190
module alu_muxb(
191
        input [31:0] rt,
192
        input [31:0]fw_alu,
193
        input [31:0]fw_mem,
194
        input [31:0]ext ,
195
        input [1:0]ctl ,
196
        input [2:0]fw_ctl ,
197
        output reg [31:0] b_o
198
    );
199
    always@(*)
200
    case (ctl)
201
        `MUXB_RT :b_o = (fw_ctl ==`FW_ALU )?fw_alu:(fw_ctl==`FW_MEM)?fw_mem:rt;
202
        `MUXB_EXT :     b_o=ext;
203
        default b_o=rt;
204
    endcase
205
endmodule
206
 
207
 
208
 
209
//This file is based on YACC ->alu.v and  UCORE ->alu.v
210
 
211
module alu (
212
    input [31:0] a,
213
        input [31:0]b,
214
    output reg [31:0] alu_out,
215
    input [4:0]  alu_func
216
        );
217
 
218
    reg [32:0] sum;
219
 
220
    always @(*)
221
    begin
222
        case (alu_func)
223
 
224
            `ALU_PA     : alu_out=a;
225
            `ALU_PB     : alu_out=b;
226
            `ALU_ADD    : alu_out=a+b;
227
            `ALU_SUB  ,
228
            `ALU_SUBU   : alu_out=a + (~b)+1;
229
            `ALU_OR     : alu_out=a | b;
230
            `ALU_AND    : alu_out=a & b;
231
            `ALU_XOR    : alu_out=a ^ b;
232
            `ALU_NOR    : alu_out=~(a | b);
233
            `ALU_SLTU   : alu_out=(a < b)?1:0;
234
            `ALU_SLT :
235
            begin
236
                sum={a[31],a}+~{b[31],b}+33'h0_0000_0001;
237
                alu_out={31'h0000_0000,sum[32]};
238
            end
239
 
240
            /*
241
                                `ALU_SLL:       alu_out = a<<b[4:0];
242
                        `ALU_SRL:   alu_out = a>>b[4:0];
243
                                `ALU_SRA:       alu_out=~(~a>>b[4:0]);
244
                                //the three operations is done in shifter_tak or shift_ff
245
            */
246
 
247
            default : alu_out=32'h0;
248
        endcase
249
    end
250
endmodule
251
 
252
 
253
module shifter_ff(
254
        input [31:0] a,
255
        output reg [31:0] shift_out,
256
        input [4:0] shift_func,//connect to alu_func_ctl
257
        input [31:0] shift_amount//connect to b
258
    );
259
 
260
    always @ (*)
261
    begin
262
        case( shift_func )
263
            `ALU_SLL:   shift_out = a<<shift_amount;
264
            `ALU_SRL:   shift_out = a>>shift_amount;
265
            `ALU_SRA:   shift_out=~(~a>> shift_amount);
266
            default             shift_out='d0;
267
        endcase
268
    end
269
endmodule
270
 
271
 
272
module  shifter_tak(
273
            input [31:0] a,
274
            output reg [31:0] shift_out,
275
            input [4:0] shift_func,//connect to alu_func_ctl
276
            input [31:0] shift_amount//connect to b
277
        );
278
 
279
    always @ (*)
280
    case( shift_func )
281
        `ALU_SLL:
282
        begin
283
            case ( shift_amount[4:0] )
284
                5'b00000: shift_out=a;
285
                5'b00001: shift_out={a[30:0],1'b0};
286
                5'b00010: shift_out={a[29:0],2'b0};
287
                5'b00011: shift_out={a[28:0],3'b0};
288
                5'b00100: shift_out={a[27:0],4'b0};
289
                5'b00101: shift_out={a[26:0],5'b0};
290
                5'b00110: shift_out={a[25:0],6'b0};
291
                5'b00111: shift_out={a[24:0],7'b0};
292
                5'b01000: shift_out={a[23:0],8'b0};
293
                5'b01001: shift_out={a[22:0],9'b0};
294
                5'b01010: shift_out={a[21:0],10'b0};
295
                5'b01011: shift_out={a[20:0],11'b0};
296
                5'b01100: shift_out={a[19:0],12'b0};
297
                5'b01101: shift_out={a[18:0],13'b0};
298
                5'b01110: shift_out={a[17:0],14'b0};
299
                5'b01111: shift_out={a[16:0],15'b0};
300
                5'b10000: shift_out={a[15:0],16'b0};
301
                5'b10001: shift_out={a[14:0],17'b0};
302
                5'b10010: shift_out={a[13:0],18'b0};
303
                5'b10011: shift_out={a[12:0],19'b0};
304
                5'b10100: shift_out={a[11:0],20'b0};
305
                5'b10101: shift_out={a[10:0],21'b0};
306
                5'b10110: shift_out={a[9:0],22'b0};
307
                5'b10111: shift_out={a[8:0],23'b0};
308
                5'b11000: shift_out={a[7:0],24'b0};
309
                5'b11001: shift_out={a[6:0],25'b0};
310
                5'b11010: shift_out={a[5:0],26'b0};
311
                5'b11011: shift_out={a[4:0],27'b0};
312
                5'b11100: shift_out={a[3:0],28'b0};
313
                5'b11101: shift_out={a[2:0],29'b0};
314
                5'b11110: shift_out={a[1:0],30'b0};
315
                5'b11111: shift_out={a[0],31'b0};
316
                default shift_out =32'bx;//never in this case
317
            endcase
318
        end
319
        `ALU_SRL :
320
        begin
321
            case (shift_amount[4:0])
322
                5'b00000: shift_out=a;
323
                5'b00001: shift_out={1'b0,a[31:1]};
324
                5'b00010: shift_out={2'b0,a[31:2]};
325
                5'b00011: shift_out={3'b0,a[31:3]};
326
                5'b00100: shift_out={4'b0,a[31:4]};
327
                5'b00101: shift_out={5'b0,a[31:5]};
328
                5'b00110: shift_out={6'b0,a[31:6]};
329
                5'b00111: shift_out={7'b0,a[31:7]};
330
                5'b01000: shift_out={8'b0,a[31:8]};
331
                5'b01001: shift_out={9'b0,a[31:9]};
332
                5'b01010: shift_out={10'b0,a[31:10]};
333
                5'b01011: shift_out={11'b0,a[31:11]};
334
                5'b01100: shift_out={12'b0,a[31:12]};
335
                5'b01101: shift_out={13'b0,a[31:13]};
336
                5'b01110: shift_out={14'b0,a[31:14]};
337
                5'b01111: shift_out={15'b0,a[31:15]};
338
                5'b10000: shift_out={16'b0,a[31:16]};
339
                5'b10001: shift_out={17'b0,a[31:17]};
340
                5'b10010: shift_out={18'b0,a[31:18]};
341
                5'b10011: shift_out={19'b0,a[31:19]};
342
                5'b10100: shift_out={20'b0,a[31:20]};
343
                5'b10101: shift_out={21'b0,a[31:21]};
344
                5'b10110: shift_out={22'b0,a[31:22]};
345
                5'b10111: shift_out={23'b0,a[31:23]};
346
                5'b11000: shift_out={24'b0,a[31:24]};
347
                5'b11001: shift_out={25'b0,a[31:25]};
348
                5'b11010: shift_out={26'b0,a[31:26]};
349
                5'b11011: shift_out={27'b0,a[31:27]};
350
                5'b11100: shift_out={28'b0,a[31:28]};
351
                5'b11101: shift_out={29'b0,a[31:29]};
352
                5'b11110: shift_out={30'b0,a[31:30]};
353
                5'b11111: shift_out={31'b0,a[31:31]};
354
                default : shift_out = 32'bx;//never in this case
355
            endcase
356
        end
357
        `ALU_SRA:
358
        begin// SHIFT_RIGHT_SIGNED
359
            case ( shift_amount[4:0])
360
                5'b00000: shift_out=a;
361
                5'b00001: shift_out={a[31],a[31:1]};
362
                5'b00010: shift_out={{2{a[31]}},a[31:2]};
363
                5'b00011: shift_out={{3{a[31]}},a[31:3]};
364
                5'b00100: shift_out={{4{a[31]}},a[31:4]};
365
                5'b00101: shift_out={{5{a[31]}},a[31:5]};
366
                5'b00110: shift_out={{6{a[31]}},a[31:6]};
367
                5'b00111: shift_out={{7{a[31]}},a[31:7]};
368
                5'b01000: shift_out={{8{a[31]}},a[31:8]};
369
                5'b01001: shift_out={{9{a[31]}},a[31:9]};
370
                5'b01010: shift_out={{10{a[31]}},a[31:10]};
371
                5'b01011: shift_out={{11{a[31]}},a[31:11]};
372
                5'b01100: shift_out={{12{a[31]}},a[31:12]};
373
                5'b01101: shift_out={{13{a[31]}},a[31:13]};
374
                5'b01110: shift_out={{14{a[31]}},a[31:14]};
375
                5'b01111: shift_out={{15{a[31]}},a[31:15]};
376
                5'b10000: shift_out={{16{a[31]}},a[31:16]};
377
                5'b10001: shift_out={{17{a[31]}},a[31:17]};
378
                5'b10010: shift_out={{18{a[31]}},a[31:18]};
379
                5'b10011: shift_out={{19{a[31]}},a[31:19]};
380
                5'b10100: shift_out={{20{a[31]}},a[31:20]};
381
                5'b10101: shift_out={{21{a[31]}},a[31:21]};
382
                5'b10110: shift_out={{22{a[31]}},a[31:22]};
383
                5'b10111: shift_out={{23{a[31]}},a[31:23]};
384
                5'b11000: shift_out={{24{a[31]}},a[31:24]};
385
                5'b11001: shift_out={{25{a[31]}},a[31:25]};
386
                5'b11010: shift_out={{26{a[31]}},a[31:26]};
387
                5'b11011: shift_out={{27{a[31]}},a[31:27]};
388
                5'b11100: shift_out={{28{a[31]}},a[31:28]};
389
                5'b11101: shift_out={{29{a[31]}},a[31:29]};
390
                5'b11110: shift_out={{30{a[31]}},a[31:30]};
391
                5'b11111: shift_out={{31{a[31]}},a[31:31]};
392
                default shift_out=32'bx;//never in this case
393
            endcase
394
        end
395
        default                 shift_out='d0;
396
    endcase
397
endmodule
398
 
399
module muldiv(ready,rst,op1,op2,clk,dout,func);
400
    input         clk,rst;
401
    wire       sign;
402
    input [4:0] func ;
403
    input [31:0] op2, op1;
404
    output [31:0] dout;
405
    output        ready;
406
    reg [31:0]    quotient, quotient_temp;
407
    reg [63:0]    dividend_copy, divider_copy, diff;
408
    reg           negative_output;
409
 
410
    reg [63:0]    product, product_temp;
411
 
412
    reg [31:0]    multiplier_copy;
413
    reg [63:0]    multiplicand_copy;
414
 
415
    reg [6:0]     mul_bit,div_bit;
416
    wire          ready = ((mul_bit==0)&&(div_bit==0));
417
 
418
    wire  [31:0]  dividend, divider;
419
 
420
    wire [31:0]  remainder;
421
    wire [31:0] multiplier,multiplicand;
422
 
423
    reg [31:0] hi,lo;
424
 
425
    assign dout = (func==`ALU_MFHI)?hi:(func==`ALU_MFLO)?lo:0;
426
 
427
    assign  remainder = (!negative_output) ?
428
            dividend_copy[31:0] :
429
            ~dividend_copy[31:0] + 1'b1;
430
 
431
    assign multiplier=op2;
432
    assign multiplicand=op1;
433
    assign dividend=op1;
434
    assign  divider = op2;
435
    assign sign = ((func==`ALU_MULT)||(func==`ALU_DIV));
436
 
437
    initial
438
    begin
439
        hi=0;
440
        lo=0;
441
    end
442
    always @( posedge clk /*or negedge rst */)
443
        if (~rst)
444
        begin
445
            mul_bit=0;
446
            div_bit=0;
447
            /*
448
            hi=0;
449
            lo=0;
450
            */
451
            negative_output = 0;
452
        end
453
        else
454
        begin
455
            if((ready)&&((func==`ALU_MULT)||(func==`ALU_MULTTU)))
456
            begin
457
                mul_bit               = 33;
458
                product           = 0;
459
                product_temp      = 0;
460
                multiplicand_copy = (!sign || !multiplicand[31]) ?
461
                                  { 32'd0, multiplicand } :
462
                                  { 32'd0, ~multiplicand + 1'b1};
463
                multiplier_copy   = (!sign || !multiplier[31]) ?multiplier :~multiplier + 1'b1;
464
 
465
                negative_output = sign &&
466
                                ((multiplier[31] && !multiplicand[31])
467
                                 ||(!multiplier[31] && multiplicand[31]));
468
            end
469
            if ( mul_bit > 1 )
470
            begin
471
 
472
                if( multiplier_copy[0] == 1'b1 )
473
                    product_temp = product_temp +multiplicand_copy;
474
 
475
 
476
                product = (!negative_output) ?
477
                        product_temp :
478
                        ~product_temp + 1'b1;
479
 
480
                multiplier_copy = multiplier_copy >> 1;
481
                multiplicand_copy = multiplicand_copy << 1;
482
                mul_bit = mul_bit - 1'b1;
483
            end
484
            else if (mul_bit == 1)
485
            begin
486
                hi =  product[63:32];
487
                lo =  product[31:0];
488
                mul_bit=0;
489
            end
490
 
491
            if((ready)&&((func==`ALU_DIV)||(func==`ALU_DIVU)))
492
            begin
493
                div_bit = 33;
494
                quotient = 0;
495
                quotient_temp = 0;
496
                dividend_copy = (!sign || !dividend[31]) ?
497
                              {32'd0,dividend} :
498
                              {32'd0,~dividend + 1'b1};
499
 
500
                divider_copy = (!sign || !divider[31]) ?
501
                             {1'b0,divider,31'd0} :
502
                             {1'b0,~divider + 1'b1,31'd0};
503
 
504
                negative_output = sign &&
505
                                ((divider[31] && !dividend[31])
506
                                 ||(!divider[31] && dividend[31]));
507
            end
508
            else if (div_bit > 1)
509
            begin
510
                diff = dividend_copy - divider_copy;
511
                quotient_temp = quotient_temp << 1;
512
                if( !diff[63] )
513
                begin
514
                    dividend_copy = diff;
515
                    quotient_temp[0] = 1'd1;
516
                end
517
                quotient = (!negative_output) ?quotient_temp :~quotient_temp + 1'b1;
518
                divider_copy = divider_copy >> 1;
519
                div_bit = div_bit - 1'b1;
520
            end
521
            else if (div_bit == 1)
522
            begin
523
                lo =  quotient;
524
                hi =  remainder;
525
                div_bit=0;
526
            end
527
        end
528
 
529
endmodule
530
 
531
//creatied by Zhangfeifei
532
//modified by Liwei
533
module muldiv_ff
534
    (        clk_i,rst_i,
535
             op_type,op1,op2,
536
             rdy,res
537
 
538
    );
539
 
540
    parameter  OP_MULT  = `ALU_MULT;
541
    parameter  OP_MULTU = `ALU_MULTU;
542
    parameter  OP_DIV   = `ALU_DIV;
543
    parameter  OP_DIVU  = `ALU_DIVU;
544
    parameter  OP_MFHI  = `ALU_MFHI;
545
    parameter  OP_MFLO  = `ALU_MFLO;
546
    parameter  OP_MTHI  = `ALU_MTHI;
547
    parameter  OP_MTLO  = `ALU_MTLO;
548
    parameter  OP_NONE  = `ALU_NOP;
549
 
550
    input         clk_i;
551
    input         rst_i;
552
    input  [4:0]  op_type;
553
    input  [31:0] op1;
554
    input  [31:0] op2;
555
    output [31:0] res;
556
    output        rdy;
557
 
558
    reg           rdy;
559
    reg    [64:0] hilo;
560
    reg    [32:0] op2_reged;
561
    reg    [5:0]  count;
562
    reg           op1_sign_reged;
563
    reg           op2_sign_reged;
564
    reg           sub_or_yn;
565
 
566
    wire   [32:0] nop2_reged;
567
    assign nop2_reged = ~op2_reged +1;
568
 
569
    reg           sign;
570
    reg           mul;
571
    reg           start;
572
 
573
    assign res = (op_type == OP_MFLO )?hilo[31:0]:((op_type == OP_MFHI))?hilo[63:32]:0;//op_type == OP_MFHI or other
574
 
575
    reg           overflow;
576
    reg           finish;
577
    reg           add1;  //if the quotient will add 1 at the end of the divide operation
578
    reg           addop2; //if the remainder will add op2 at the end of the divide operation
579
    reg           addnop2;//if the remainder will add ~op2+1 at the end of the divide operation
580
 
581
 
582
    always @( posedge clk_i  /*or negedge rst_i*/)
583
    begin
584
        if(~rst_i)
585
        begin
586
            count          = 6'bx;
587
            hilo           = 65'b0;
588
            op2_reged      = 33'bx;
589
            op1_sign_reged = 1'bx;
590
            op2_sign_reged = 1'bx;
591
            sub_or_yn      = 1'bx;
592
            rdy            = 1'b1;
593
            start          = 1'bx;
594
            sign           = 1'bx;
595
            mul            = 1'bx;
596
            finish         = 1'bx;
597
            add1           = 1'bx;
598
            addop2         = 1'bx;
599
            addnop2        = 1'bx;
600
        end
601
        else begin
602
 
603
            if(op_type == OP_MTHI || op_type == OP_MTLO)
604
            begin
605
                if(op_type == OP_MTHI) hilo[64:32] = {1'b0,op1};
606
                if(op_type == OP_MTLO) hilo[31:0]  = op1;
607
                rdy = 1;
608
            end
609
            else if(rdy)
610
            begin
611
                start = (op_type == OP_MULT) || (op_type == OP_MULTU) || (op_type == OP_DIV)  || (op_type == OP_DIVU);
612
                mul   = (op_type == OP_MULT) || (op_type == OP_MULTU);
613
                sign  = (op_type == OP_MULT) || (op_type == OP_DIV);
614
 
615
                if(start)
616
                begin:START_SECTION
617
                    reg [32:0] over;
618
 
619
                    op2_reged       = {sign        ?op2[31]      :1'b0 ,op2};
620
                    hilo            = {~mul && sign?{33{op1[31]}}:33'b0,op1};
621
                    count           = 6'b000000;
622
                    rdy             = 0;
623
                    op1_sign_reged  = sign?op1[31]:0;
624
                    op2_sign_reged  = sign?op2[31]:0;
625
                    sub_or_yn       = 0;
626
 
627
                    over            = ~op2_reged + {op1[31],op1};
628
                    overflow        = sign && ~mul ? op1_sign_reged && op2_sign_reged && ~over[32] : 0;
629
 
630
                    finish          = 0;
631
                end
632
            end
633
            else if(start)
634
            begin
635
                if(overflow)
636
                begin
637
                    hilo[63:0] = {hilo[31:0],32'b0};
638
                    rdy        = 1;
639
                end
640
                else if(!count[5])
641
                begin
642
                    if(mul)
643
                    begin
644
                        if(sign)
645
                        begin
646
                            case({hilo[0],sub_or_yn})
647
                                2'b10:hilo[64:32] = hilo[64:32] + nop2_reged;
648
                                2'b01:hilo[64:32] = hilo[64:32] + op2_reged;
649
                                default:;
650
                            endcase
651
                            {hilo[63:0],sub_or_yn} = hilo[64:0];
652
                        end
653
                        else begin
654
                            if(hilo[0]) hilo[64:32] = hilo[64:32] + op2_reged;
655
                            hilo      = {1'b0,hilo[64:1]};
656
                        end
657
                    end
658
                    else begin
659
                        sub_or_yn  = hilo[64]== op2_sign_reged;
660
                        hilo[64:1] = hilo[63:0];
661
 
662
                        hilo[64:32] = sub_or_yn ? hilo[64:32] + nop2_reged : hilo[64:32] + op2_reged;
663
 
664
                        hilo[0]    = hilo[64]== op2_sign_reged;
665
                    end
666
 
667
                    count        = count + 1'b1;
668
                end
669
                else begin
670
                    if(finish)
671
                    begin
672
                        if(add1)   hilo[31:0]  = hilo[31:0] + 1;
673
                        case({addop2,addnop2})
674
                            2'b10:   hilo[64:32] = hilo[64:32] + op2_reged;
675
                            2'b01:   hilo[64:32] = hilo[64:32] + nop2_reged;
676
                            default: ;
677
                        endcase
678
                        rdy = 1;
679
                    end
680
                    else begin
681
                        {add1,addop2,addnop2} = 3'b000;
682
                        finish                = 1;
683
 
684
                        if(~mul)
685
                        begin:LAST_CYCLE_DEAL_SECTION
686
                            reg eqz,eqop2,eqnop2;
687
                            eqz    = hilo[64:32] == 0;
688
                            eqop2  = hilo[64:32] == op2_reged;
689
                            eqnop2 = hilo[64:32] == nop2_reged;
690
                            casex({op1_sign_reged,op2_sign_reged,eqz,eqop2,eqnop2})
691
                                5'b101xx : {add1,addop2,addnop2} = 3'b000;
692
                                5'b100x1 : {add1,addop2,addnop2} = 3'b010;
693
                                5'b111xx : {add1,addop2,addnop2} = 3'b100;
694
                                5'b1101x : {add1,addop2,addnop2} = 3'b101;
695
                                default :
696
                                begin:LAST_CYCLE_DEAL_SECTION_DEFAULT
697
 
698
                                    reg op1s_eq_op2s,op1s_eq_h64;
699
                                    op1s_eq_op2s = op1_sign_reged == op2_sign_reged;
700
                                    op1s_eq_h64  = op1_sign_reged == hilo[64];
701
 
702
                                    add1 = ~op1s_eq_op2s;
703
                                    case({op1s_eq_op2s,op1s_eq_h64})//synthesis parallel_case
704
                                        2'b00:   {addop2,addnop2} = 2'b01;
705
                                        2'b10:   {addop2,addnop2} = 2'b10;
706
                                        default: {addop2,addnop2} = 2'b00;
707
                                    endcase
708
                                end
709
                            endcase
710
                        end
711
                    end
712
                end
713
            end
714
        end
715
    end
716
endmodule
717
 
718
 

powered by: WebSVN 2.1.0

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