-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage2.v
1365 lines (1299 loc) · 54.6 KB
/
stage2.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*-----------------------------------------------------------------------------
* Title : stage2
* Project : EMAX6
*-----------------------------------------------------------------------------
* File : stage2.v
* Author : Nakashima
* <nakashim@is.naist.jp>
* Yamano
* <yamano.ryusuke.yo7@is.naist.jp>
* Kikutani
* <kikutani.yuma.kw3@is.naist.jp>
* Created : 10.20.2017
* Last modified : 10.20.2017
*-----------------------------------------------------------------------------
* Description : exeの演算処理とfpuのbooth encoder & wallace tree
*-----------------------------------------------------------------------------
* Copyright (c) 2016 by NAIST This model is the confidential and
* proprietary property of NAIST and the possession or use of this
* file requires a written license from NAIST.
*-----------------------------------------------------------------------------
* Modification history :
* 10.20.2017 : created
*-----------------------------------------------------------------------------
*/
`timescale 1ns/1ns
`include "common.vh"
/* stage2 */
module stage2
(
input wire ACLK,
input wire RSTN,
input wire UNIRSTN,
input wire [`CONF_BITS-1:0] conf0,
input wire [`CONF_BITS-1:0] conf1,
input wire [`CONF_BITS-1:0] conf2,
input wire [`CONF_BITS-1:0] conf3,
input wire lmea0sfma,
input wire lmea0strq,
input wire [1:0] lmea0strqcol, /* ea0.strq_col番号 4サイクルに分けて実行 */
input wire exec,
input wire fold,
input wire one_shot2,
input wire [1:0] forstat2,
input wire [`CEX_DATA_BITS-1:0] cx0,
input wire [`CEX_DATA_BITS-1:0] cx1,
input wire [`CEX_DATA_BITS-1:0] cx2,
input wire [`CEX_DATA_BITS-1:0] cx3,
input wire [`REG_DATA_BITS-1:0] tx0i,
input wire [`REG_DATA_BITS-1:0] tx1i,
input wire [`REG_DATA_BITS-1:0] tx2i,
input wire [`REG_DATA_BITS-1:0] tx3i,
input wire [`REG_DATA_BITS-1:0] ex1,
input wire [`REG_DATA_BITS-1:0] ex2t,
input wire [`REG_DATA_BITS-1:0] ex3,
input wire [`EXE_WORD_BITS-1:0] mexmr0d,//★MEX
input wire [`EXE_WORD_BITS-1:0] mexmr1d,//★MEX
output reg stage3_exec,
output reg stage3_fold,
output reg [1:0] stage_forstat,
output reg [1:0] cxd,
output reg [`REG_DATA_BITS-1:0] tx0,
output reg [`REG_DATA_BITS-1:0] tx1,
output reg [`REG_DATA_BITS-1:0] tx2,
output reg [`REG_DATA_BITS-1:0] tx3,
output reg [5:0] opo,
output wire [`REG_DATA_BITS-1:0] ex2d,
output reg [`REG_DATA_BITS-1:0] ex4o,
output reg [5:0] ex5o,
output reg unit1_arbrk,
`ifdef ENABLE_FPU
output wire h_ex1_d_s,
output wire [8:0] h_ex1_d_exp,
output wire [24+`PEXT:0] h_ex1_d_csa_s, //■■■
output wire [24+`PEXT:0] h_ex1_d_csa_c, //■■■
output wire h_ex1_d_zero,
output wire h_ex1_d_inf,
output wire h_ex1_d_nan,
output wire h_fadd_s1_s,
output wire [8:0] h_fadd_s1_exp,
output wire [24+`PEXT:0] h_fadd_s1_frac, //■■■
output wire h_fadd_s1_zero,
output wire h_fadd_s1_inf,
output wire h_fadd_s1_nan,
output wire l_ex1_d_s,
output wire [8:0] l_ex1_d_exp,
output wire [24+`PEXT:0] l_ex1_d_csa_s, //■■■
output wire [24+`PEXT:0] l_ex1_d_csa_c, //■■■
output wire l_ex1_d_zero,
output wire l_ex1_d_inf,
output wire l_ex1_d_nan,
output wire l_fadd_s1_s,
output wire [8:0] l_fadd_s1_exp,
output wire [24+`PEXT:0] l_fadd_s1_frac, //■■■
output wire l_fadd_s1_zero,
output wire l_fadd_s1_inf,
output wire l_fadd_s1_nan,
`endif
`ifdef ENABLE_SPU
output reg [7:0] ex2passr1,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc0,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc0,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc1,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc1,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc2,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc2,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc3,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc3,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc4,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc4,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc5,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc5,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc6,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc6,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmapc7,
output wire [`SPU_DATA_LOG2-1:0] ex2d_sfmanc7,
`endif
input wire [`EXRING_ADDR_BITS-1:0] ea0b,
input wire [`REG_DATA_BITS-1:0] ea0o,
input wire [`EXRING_ADDR_BITS-1:0] ea1b,
input wire [`REG_DATA_BITS-1:0] ea1o,
output reg [`EXRING_ADDR_BITS-1:0] ea0d,
output reg [`EXRING_ADDR_BITS-1:0] ea0dofs,//★MEX
output reg [`EXRING_ADDR_BITS-1:0] ea1d,
output reg [`EXRING_ADDR_BITS-1:0] ea1dofs //★MEX
);
// synopsys template
reg [1:0] cycle;
wire [1:0] cyclep3;
assign cyclep3 = cycle + 2'h3;
always @(posedge ACLK or negedge RSTN) begin
if (~RSTN) begin
cycle <= 2'h0;
end
else begin
cycle <= cycle + 2'h1;
end
end
wire [`CONF_BITS-1:0] conf = (cycle==2'h0)?conf3:(cycle==2'h1)?conf0:(cycle==2'h2)?conf1:conf2;
wire [1:0] k = (lmea0sfma|lmea0strq) ? lmea0strqcol : cyclep3;
wire [`CONF_BITS-1:0] confk = (k==2'd0)?conf0:(k==2'd1)?conf1:(k==2'd2)?conf2:conf3;
wire [1:0] j = cyclep3;
wire op_nf1 = (`conf1_op1 != `OP_FOR);
wire [`CEX_DATA_BITS-1:0] cexs;
wire [`REG_DATA_BITS-1:0] ex2 = ((`conf_op1 == `OP_FOR && (j == 2'd1) && !stage_forstat[0])||((`conf_init & 2'd2) && one_shot2 && !(forstat2 & 2'd1))) ? {(`REG_DATA_BITS){1'b0}} : ex2t;
wire [`REG_DATA_BITS-1:0] ex4 = (`conf_e2is==0) ? `conf_e2imm :
(`conf_e2is==1) ? ex2t : ex3;
wire [5:0] ex5 = (`conf_e3is==0) ? `conf_e3imm : ex3[5:0];
wire [1:0] brk;
wire [`EXRING_ADDR_BITS-1:0] ea0mexd;//★MEX
wire [`EXRING_ADDR_BITS-1:0] ea0md; //★MEX
wire [`EXRING_ADDR_BITS-1:0] ea1mexd;//★MEX
wire [`EXRING_ADDR_BITS-1:0] ea1md; //★MEX
always @(posedge ACLK or negedge RSTN) begin
if (~RSTN|~UNIRSTN) begin
cxd <= {(2){1'b0}};
tx0 <= {(`REG_DATA_BITS){1'b0}};
tx1 <= {(`REG_DATA_BITS){1'b0}};
tx2 <= {(`REG_DATA_BITS){1'b0}};
tx3 <= {(`REG_DATA_BITS){1'b0}};
opo <= 6'd0;
`ifdef ENABLE_SPU
ex2passr1 <= 8'd0;
`endif
ex4o <= {(`REG_DATA_BITS){1'b0}};
ex5o <= 6'd0;
unit1_arbrk <= 1'b0;
stage_forstat <= {(2){1'b0}};
ea0d <= {(`EXRING_ADDR_BITS){1'b0}};
ea0dofs <= {(`EXRING_ADDR_BITS){1'b0}};//★MEX
ea1d <= {(`EXRING_ADDR_BITS){1'b0}};
ea1dofs <= {(`EXRING_ADDR_BITS){1'b0}};//★MEX
stage3_exec <= 1'b0;
stage3_fold <= 1'b0;
end
else begin
opo <= conf[12:7];
`ifdef ENABLE_SPU
ex2passr1 <= ex1[7:0];
`endif
ex4o <= ex4;
ex5o <= ex5;
if (exec || fold) begin
cxd <= cexs;
tx0 <= tx0i;
tx1 <= tx1i;
tx2 <= tx2i;
tx3 <= tx3i;
ea0d <= ea0mexd;//★MEX
ea0dofs <= ea0md; //★MEX
ea1d <= ea1mexd;//★MEX
ea1dofs <= ea1md; //★MEX
if ((cycle&2'd3) == 2'd0) begin
unit1_arbrk <= 1'b0;
end
else if (`conf_op1 == `OP_WHILE) begin
unit1_arbrk <= brk[0];
end
else if (`conf_op1 == `OP_FOR) begin
if (j == 2'd0) begin
unit1_arbrk <= {op_nf1,brk[0]} == 2'd3;
stage_forstat <= {op_nf1,brk[0]};
end
else if (j == 2'd1) begin
unit1_arbrk <= {brk[0],stage_forstat[0]} == 2'd3;
stage_forstat <= {brk[0],stage_forstat[0]};
end
end
end
if (exec)
stage3_exec <= 1'b1;
else
stage3_exec <= 1'b0;
if (fold)
stage3_fold <= 1'b1;
else
stage3_fold <= 1'b0;
end
end
cex cex
(
.c0 (cx0 ),
.c1 (cx1 ),
.c2 (cx2 ),
.c3 (cx3 ),
.patt (`conf_cex_tab ),
.cexd (cexs )
);
wire mex0_enable = (!one_shot2 || (`conf_mex0init && (forstat2 & 2'd1))) ? 1'b0 : 1'b1; //★MEX
wire mex1_enable = (!one_shot2 || (`conf_mex1init && (forstat2 & 2'd1))) ? 1'b0 : 1'b1; //★MEX
mex mex //★MEX
(
.mex1op (`conf_mex1op ),
.mex1en (mex1_enable ),
.ea1b (ea1b ),
.mex1dist (`conf_mex1dist ),
.mex0op (`conf_mex0op ),
.mex0en (mex0_enable ),
.ea0b (ea0b ),
.mex0dist (`conf_mex0dist ),
.mexlimit (`conf_mexlimit ),
.mexmr1 (mexmr1d ),
.mexmr0 (mexmr0d ),
.mex1d (ea1mexd ),
.mex0d (ea0mexd )
);
eam eam0 //★MEX
(
.eao (ea0o ),
.eamsk (`confk_ea0msk ),
.eamd (ea0md )
);
eam eam1 //★MEX
(
.eao (ea1o ),
.eamsk (`conf_ea1msk ),
.eamd (ea1md )
);
function [`REG_DATA_BITS-1:0] ex_exp;
input [`REG_DATA_BITS-1:0] ex;
input [2:0] exp;
begin
case (exp)
//`EXP_H3210: begin
default: begin
ex_exp = ex;
end
`EXP_H1010: begin
ex_exp = {ex[31:0], ex[31:0]};
end
`EXP_H3232: begin
ex_exp = {ex[63:32], ex[63:32]};
end
`EXP_B7632: begin
// s1 = (s1t>>8&64'h00FF0000_00FF0000) | (s1t>>16&64'h000000FF_000000FF);
ex_exp = {8'h00, ex[63:56], 8'h00, ex[55:48], 8'h00, ex[31:24], 8'h00, ex[23:16]};
end
`EXP_B5410: begin
// s1 = (s1t<<8&64'h00FF0000_00FF0000) | (s1t &64'h000000FF_000000FF);
ex_exp = {8'h00, ex[47:40], 8'h00, ex[39:32], 8'h00, ex[15:8], 8'h00, ex[7:0]};
end
endcase
end
endfunction
wire [5:0] iop = `conf_op1;
wire [`REG_DATA_BITS-1:0] iex1 = ex_exp(ex1, `conf_ex1exp);
wire [`REG_DATA_BITS-1:0] iex2 = ex_exp(ex2, `conf_ex2exp);
wire [`REG_DATA_BITS-1:0] iex3 = ex_exp(ex3, `conf_ex3exp);
// pipelined exe
exe1 exe1h
(
.ACLK (ACLK ),
.RSTN (RSTN&UNIRSTN ),
.hi_lo (1'b1 ),
.op (iop ),
.ex1 (iex1[63:32] ),
.ex2 (iex2[63:32] ),
.ex3 (iex3[63:32] ),
.ex2d (ex2d[63:32] ),
.brk (brk[1] )
);
exe1 exe1l
(
.ACLK (ACLK ),
.RSTN (RSTN&UNIRSTN ),
.hi_lo (1'b0 ),
.op (iop ),
.ex1 (iex1[31: 0] ),
.ex2 (iex2[31: 0] ),
.ex3 (iex3[31: 0] ),
.ex2d (ex2d[31: 0] ),
.brk (brk[0] )
);
`ifdef ENABLE_FPU
/*-------------- 32bit floating point operator ----------------------------------*/
/* op=3->0:fma3 (ex1 + ex2 * ex3) */
/* op=3->1:fms3 (ex1 - ex2 * ex3) */
/* op=2->2:fadd (ex1 + ex2 * 1.0) */
/* op=1->3:fmul (0.0 + ex2 * ex3) */
wire [1:0] fop = (`conf_op1==`OP_FMA || `conf_op1==`OP_CFMA) ? 2'h0: //★MEX
(`conf_op1==`OP_FMS) ? 2'h1:
(`conf_op1==`OP_FAD) ? 2'h2:
/* `OP_FML */ 2'h3;
wire [`REG_DATA_BITS-1:0] fex1 = (`conf_op1==`OP_FML) ? 0:iex1;
wire [`REG_DATA_BITS-1:0] fex2 = (`conf_op1==`OP_FML) ? iex1:iex2;
wire [`REG_DATA_BITS-1:0] fex3 = (`conf_op1==`OP_FMA || `conf_op1==`OP_CFMA) ? iex3: //★MEX
(`conf_op1==`OP_FMS) ? iex3:
(`conf_op1==`OP_FML) ? iex2:
/* `OP_FAD */ 64'h3F8000003F800000;
wire cfma_force0 = `conf_op1==`OP_CFMA && //★MEX
((fex2[`REG_DATA_BITS-1:`EXE_WORD_BITS] == {(`EXE_WORD_BITS){1'b1}}) //★MEX
||(fex2[`REG_DATA_BITS-1:`EXE_WORD_BITS] != fex3[`REG_DATA_BITS-1:`EXE_WORD_BITS])); //★MEX
fpu1 fpu1h
(
.ACLK (ACLK ),
.RSTN (RSTN&UNIRSTN ),
.op (fop ),
.ex1 (fex1[63:32] ),
.ex2 (fex2[63:32] ),
.ex3 (fex3[63:32] ),
.force0 (1'b0 ),
.ex1_d_s (h_ex1_d_s ),
.ex1_d_exp (h_ex1_d_exp ),
.ex1_d_csa_s (h_ex1_d_csa_s ),
.ex1_d_csa_c (h_ex1_d_csa_c ),
.ex1_d_zero (h_ex1_d_zero ),
.ex1_d_inf (h_ex1_d_inf ),
.ex1_d_nan (h_ex1_d_nan ),
.fadd_s1_s (h_fadd_s1_s ),
.fadd_s1_exp (h_fadd_s1_exp ),
.fadd_s1_frac (h_fadd_s1_frac ),
.fadd_s1_zero (h_fadd_s1_zero ),
.fadd_s1_inf (h_fadd_s1_inf ),
.fadd_s1_nan (h_fadd_s1_nan )
);
fpu1 fpu1l
(
.ACLK (ACLK ),
.RSTN (RSTN&UNIRSTN ),
.op (fop ),
.ex1 (fex1[31: 0] ),
.ex2 (fex2[31: 0] ),
.ex3 (fex3[31: 0] ),
.force0 (cfma_force0 ),
.ex1_d_s (l_ex1_d_s ),
.ex1_d_exp (l_ex1_d_exp ),
.ex1_d_csa_s (l_ex1_d_csa_s ),
.ex1_d_csa_c (l_ex1_d_csa_c ),
.ex1_d_zero (l_ex1_d_zero ),
.ex1_d_inf (l_ex1_d_inf ),
.ex1_d_nan (l_ex1_d_nan ),
.fadd_s1_s (l_fadd_s1_s ),
.fadd_s1_exp (l_fadd_s1_exp ),
.fadd_s1_frac (l_fadd_s1_frac ),
.fadd_s1_zero (l_fadd_s1_zero ),
.fadd_s1_inf (l_fadd_s1_inf ),
.fadd_s1_nan (l_fadd_s1_nan )
);
`endif
`ifdef ENABLE_SPU
/*-------------- Spiking operator ex1 <- ex1 + ex2 * ex3 */
spu1 spu1
(
.ACLK (ACLK ),
.RSTN (RSTN&UNIRSTN ),
.exec (exec ),
.fold (fold ),
.ex2 (ex2[`REG_DATA_BITS-1:0] ),
.ex3 (ex3[`REG_DATA_BITS-1:0] ),
.sfmapc0 (ex2d_sfmapc0[`SPU_DATA_LOG2-1:0]),
.sfmanc0 (ex2d_sfmanc0[`SPU_DATA_LOG2-1:0]),
.sfmapc1 (ex2d_sfmapc1[`SPU_DATA_LOG2-1:0]),
.sfmanc1 (ex2d_sfmanc1[`SPU_DATA_LOG2-1:0]),
.sfmapc2 (ex2d_sfmapc2[`SPU_DATA_LOG2-1:0]),
.sfmanc2 (ex2d_sfmanc2[`SPU_DATA_LOG2-1:0]),
.sfmapc3 (ex2d_sfmapc3[`SPU_DATA_LOG2-1:0]),
.sfmanc3 (ex2d_sfmanc3[`SPU_DATA_LOG2-1:0]),
.sfmapc4 (ex2d_sfmapc4[`SPU_DATA_LOG2-1:0]),
.sfmanc4 (ex2d_sfmanc4[`SPU_DATA_LOG2-1:0]),
.sfmapc5 (ex2d_sfmapc5[`SPU_DATA_LOG2-1:0]),
.sfmanc5 (ex2d_sfmanc5[`SPU_DATA_LOG2-1:0]),
.sfmapc6 (ex2d_sfmapc6[`SPU_DATA_LOG2-1:0]),
.sfmanc6 (ex2d_sfmanc6[`SPU_DATA_LOG2-1:0]),
.sfmapc7 (ex2d_sfmapc7[`SPU_DATA_LOG2-1:0]),
.sfmanc7 (ex2d_sfmanc7[`SPU_DATA_LOG2-1:0])
);
`endif
endmodule
module exe1
(
input wire ACLK,
input wire RSTN,
input wire hi_lo,
input wire [5:0] op,
input wire [`EXE_WORD_BITS-1:0] ex1,
input wire [`EXE_WORD_BITS-1:0] ex2,
input wire [`EXE_WORD_BITS-1:0] ex3,
output wire [`EXE_WORD_BITS-1:0] ex2d,
output wire brk
);
function [7:0] func_ad;
input [7:0] a;
input [7:0] b;
begin
if (a>b) begin
func_ad = a-b;
end
else begin
func_ad = b-a;
end
end
endfunction
function [`EXE_WORD_BITS-1:0] addsub3;
input op;
input [`EXE_WORD_BITS-1:0] s1;
input [`EXE_WORD_BITS-1:0] s2;
input [`EXE_WORD_BITS-1:0] s3;
reg [`EXE_WORD_BITS-1:0] m0;
reg [`EXE_WORD_BITS-1:0] d0;
begin
m0 = s2 + s3;
case (op)
0: begin
d0 = s1 + m0;
end
default:begin
d0 = s1 - m0;
end
endcase
addsub3 = {d0};
end
endfunction
function [15:0] saturate00;
input [19:0] s;
begin
saturate00 = (s>20'h0FFFF)?16'h0000:s[15:0];
end
endfunction
function [15:0] saturateff;
input [19:0] s;
begin
saturateff = (s>20'h0FFFF)?16'hFFFF:s[15:0];
end
endfunction
function [`EXE_WORD_BITS-1:0] func_mmin2;
input [`EXE_WORD_BITS-1:0] s1;
input [`EXE_WORD_BITS-1:0] s2;
reg [7:0] mmin2_drv_byte3, mmin2_drv_byte2, mmin2_drv_byte1, mmin2_drv_byte0;
begin
mmin2_drv_byte3 = (s1[31:24]<s2[31:24]) ? s1[31:24] : s2[31:24];
mmin2_drv_byte2 = (s1[23:16]<s2[23:16]) ? s1[23:16] : s2[23:16];
mmin2_drv_byte1 = (s1[15: 8]<s2[15: 8]) ? s1[15: 8] : s2[15: 8];
mmin2_drv_byte0 = (s1[ 7: 0]<s2[ 7: 0]) ? s1[ 7: 0] : s2[ 7: 0];
func_mmin2 = {mmin2_drv_byte3, mmin2_drv_byte2, mmin2_drv_byte1, mmin2_drv_byte0};
end
endfunction
function [`EXE_WORD_BITS-1:0] func_mmax2;
input [`EXE_WORD_BITS-1:0] s1;
input [`EXE_WORD_BITS-1:0] s2;
reg [7:0] mmax2_drv_byte3, mmax2_drv_byte2, mmax2_drv_byte1, mmax2_drv_byte0;
begin
mmax2_drv_byte3 = (s1[31:24]>s2[31:24]) ? s1[31:24] : s2[31:24];
mmax2_drv_byte2 = (s1[23:16]>s2[23:16]) ? s1[23:16] : s2[23:16];
mmax2_drv_byte1 = (s1[15: 8]>s2[15: 8]) ? s1[15: 8] : s2[15: 8];
mmax2_drv_byte0 = (s1[ 7: 0]>s2[ 7: 0]) ? s1[ 7: 0] : s2[ 7: 0];
func_mmax2 = {mmax2_drv_byte3, mmax2_drv_byte2, mmax2_drv_byte1, mmax2_drv_byte0};
end
endfunction
function [`EXE_WORD_BITS-1:0] func_mmid3;
input [`EXE_WORD_BITS-1:0] s1; // s1 < s2
input [`EXE_WORD_BITS-1:0] s2; // s1 < s2
input [`EXE_WORD_BITS-1:0] s3; // unknown
reg [7:0] mmid3_drv_byte3, mmid3_drv_byte2, mmid3_drv_byte1, mmid3_drv_byte0;
begin
mmid3_drv_byte3 = (s3[31:24]<s1[31:24]) ? s1[31:24] : (s3[31:24]<s2[31:24]) ? s3[31:24] : s2[31:24];
mmid3_drv_byte2 = (s3[23:16]<s1[23:16]) ? s1[23:16] : (s3[23:16]<s2[23:16]) ? s3[23:16] : s2[23:16];
mmid3_drv_byte1 = (s3[15: 8]<s1[15: 8]) ? s1[15: 8] : (s3[15: 8]<s2[15: 8]) ? s3[15: 8] : s2[15: 8];
mmid3_drv_byte0 = (s3[ 7: 0]<s1[ 7: 0]) ? s1[ 7: 0] : (s3[ 7: 0]<s2[ 7: 0]) ? s3[ 7: 0] : s2[ 7: 0];
func_mmid3 = {mmid3_drv_byte3, mmid3_drv_byte2, mmid3_drv_byte1, mmid3_drv_byte0};
end
endfunction
function [`EXE_WORD_BITS-1+1:0] ex1_internal;
input hi_lo;
input [5:0] op;
input [`EXE_WORD_BITS-1:0] s1;
input [`EXE_WORD_BITS-1:0] s2;
input [`EXE_WORD_BITS-1:0] s3;
reg [`EXE_WORD_BITS-1:0] t1;
reg [`EXE_WORD_BITS-1:0] t2;
reg [`EXE_WORD_BITS-1:0] d;
reg brk;
begin
case (op)
//`OP_NOP1: begin
default: begin
t1 = 32'd0;
t2 = 32'd0;
d = s1;
brk = 1'b0;
end
`OP_WHILE, `OP_FOR: begin
t1 = 32'd0;
t2 = 32'd0;
d = s1 + s2; //addsub3(0, s1, s2, {(`EXE_WORD_BITS){1'b0}});
brk = (d=={(`EXE_WORD_BITS){1'b0}}) ? 1'b1 : 1'b0;
end
`OP_ADD3: begin
t1 = 32'd0;
t2 = 32'd0;
d = s1 + s2 + s3; //addsub3(0, s1, s2, s3);
brk = 1'b0;
end
`OP_SUB3: begin
t1 = 32'd0;
t2 = 32'd0;
d = s1 - (s2 + s3); //addsub3(1, s1, s2, s3);
brk = 1'b0;
end
`OP_ADD: begin
t1 = 32'd0;
t2 = 32'd0;
d = s1 + s2; //addsub3(0, s1, s2, {(`EXE_WORD_BITS){1'b0}});
brk = 1'b0;
end
`OP_SUB: begin
t1 = 32'd0;
t2 = 32'd0;
d = s1 - s2; //addsub3(1, s1, s2, {(`EXE_WORD_BITS){1'b0}});
brk = 1'b0;
end
`OP_CMP_EQ: begin
t1 = 32'd0;
t2 = 32'd0;
d = {{(`EXE_WORD_BITS-1){1'b0}},(s1 == s2)};
brk = 1'b0;
end
`OP_CMP_NE: begin
t1 = 32'd0;
t2 = 32'd0;
d = {{(`EXE_WORD_BITS-1){1'b0}},(s1 != s2)};
brk = 1'b0;
end
`OP_CMP_LT: begin
t1 = 32'd0;
t2 = 32'd0;
d = {{(`EXE_WORD_BITS-1){1'b0}},(s1 < s2)};
brk = 1'b0;
end
`OP_CMP_LE: begin
t1 = 32'd0;
t2 = 32'd0;
d = {{(`EXE_WORD_BITS-1){1'b0}},(s1 <= s2)};
brk = 1'b0;
end
`OP_CMP_GT: begin
t1 = 32'd0;
t2 = 32'd0;
d = {{(`EXE_WORD_BITS-1){1'b0}},(s1 > s2)};
brk = 1'b0;
end
`OP_CMP_GE: begin
t1 = 32'd0;
t2 = 32'd0;
d = {{(`EXE_WORD_BITS-1){1'b0}},(s1 >= s2)};
brk = 1'b0;
end
`OP_CMOV: begin
t1 = 32'd0;
t2 = 32'd0;
d = (s1[0]) ? s2 : s3;
brk = 1'b0;
end
// `OP_CCAT: begin
// t1 = 32'd0;
// t2 = 32'd0;
// d = s2;
// brk = 1'b0;
// end
`ifdef ENABLE_MEDIA
`OP_MAUH3: begin
t1[31:18] = 14'd0;
t2[31:18] = 14'd0;
t1[17: 0] = {2'b00,s1[31:16]}+{2'b00,s2[31:16]}+{2'b00,s3[31:16]};
t2[17: 0] = {2'b00,s1[15: 0]}+{2'b00,s2[15: 0]}+{2'b00,s3[15: 0]};
d = {saturateff(t1[19:0]),saturateff(t2[19:0])};
brk = 1'b0;
end
`OP_MAUH: begin
t1[31:17] = 15'd0;
t2[31:17] = 15'd0;
t1[16: 0] = {1'b0,s1[31:16]}+{1'b0,s2[31:16]};
t2[16: 0] = {1'b0,s1[15: 0]}+{1'b0,s2[15: 0]};
d = {saturateff(t1[19:0]),saturateff(t2[19:0])};
brk = 1'b0;
end
`OP_MSUH3: begin
t1[31:18] = 14'd0;
t2[31:18] = 14'd0;
t1[17: 0] = {2'b00,s1[31:16]}-({2'b00,s2[31:16]}+{2'b00,s3[31:16]});
t2[17: 0] = {2'b00,s1[15: 0]}-({2'b00,s2[15: 0]}+{2'b00,s3[15: 0]});
d = {saturate00(t1[19:0]),saturate00(t2[19:0])};
brk = 1'b0;
end
`OP_MSUH: begin
t1[31:17] = 15'd0;
t2[31:17] = 15'd0;
t1[16: 0] = {1'b0,s1[31:16]}-{1'b0,s2[31:16]};
t2[16: 0] = {1'b0,s1[15: 0]}-{1'b0,s2[15: 0]};
d = {saturate00(t1[19:0]),saturate00(t2[19:0])};
brk = 1'b0;
end
`OP_MLUH: begin
t1[31:20] = 12'd0;
t2[31:20] = 12'd0;
t1[19: 0] = s1[26:16]*s2[8:0];
t2[19: 0] = s1[10: 0]*s2[8:0];
d = {saturateff(t1[19:0]),saturateff(t2[19:0])};
brk = 1'b0;
end
`OP_MMRG: begin
t1 = 32'd0;
t2 = 32'd0;
d = {s1[7:0],s2[7:0],s3[7:0],8'd0};
brk = 1'b0;
end
`OP_MSSAD: begin
t1[31:17] = 15'd0;
t2[31:17] = 15'd0;
t1[16: 0] = {1'b0,s1[31:16]}+({9'h000,func_ad(s2[31:24],s3[31:24])}+{9'h000,func_ad(s2[23:16],s3[23:16])});
t2[16: 0] = {1'b0,s1[15: 0]}+({9'h000,func_ad(s2[15: 8],s3[15: 8])}+{9'h000,func_ad(s2[ 7: 0],s3[ 7: 0])});
d = {saturateff(t1[19:0]),saturateff(t2[19:0])};
brk = 1'b0;
end
`OP_MSAD: begin
t1[31:9] = 23'd0;
t2[31:9] = 23'd0;
t1[8:0] = {1'b0,func_ad(s1[31:24],s2[31:24])}+{1'b0,func_ad(s1[23:16],s2[23:16])};
t2[8:0] = {1'b0,func_ad(s1[15: 8],s2[15: 8])}+{1'b0,func_ad(s1[ 7: 0],s2[ 7: 0])};
d = {t1[15:0],t2[15:0]};
brk = 1'b0;
end
`OP_MINL3: begin
t1 = 32'd0;
t2 = 32'd0;
if (s3[31:16]<s3[15:0]) d = {s1[31:16],s3[31:16]};
else d = {s2[31:16],s3[15: 0]};
brk = 1'b0;
end
`OP_MINL: begin
t1 = 32'd0;
t2 = 32'd0;
if (s1[15:0]<s2[15:0]) d = s1;
else d = s2;
brk = 1'b0;
end
`OP_MH2BW: begin
t1 = 32'd0;
t2 = 32'd0;
d = {((s1[31:16]<16'h100)?s1[23:16]:8'hFF),((s1[15:0]<16'h100)?s1[7:0]:8'hFF),
((s2[31:16]<16'h100)?s2[23:16]:8'hFF),((s2[15:0]<16'h100)?s2[7:0]:8'hFF)};
brk = 1'b0;
end
`OP_MCAS: begin
t1 = 32'd0;
t2 = 32'd0;
d = (s1[15:0]<s2[15:0])?32'd0:32'h000000ff;
brk = 1'b0;
end
`OP_MMID3: begin
t1 = 32'd0;
t2 = 32'd0;
d = func_mmid3(func_mmin2(s1,s2),func_mmax2(s1,s2),s3);
brk = 1'b0;
end
`OP_MMAX3: begin
t1 = 32'd0;
t2 = 32'd0;
d = func_mmax2(func_mmax2(s1,s2),s3);
brk = 1'b0;
end
`OP_MMAX: begin
t1 = 32'd0;
t2 = 32'd0;
d = func_mmax2(s1,s2);
brk = 1'b0;
end
`OP_MMIN3: begin
t1 = 32'd0;
t2 = 32'd0;
d = func_mmin2(func_mmin2(s1,s2),s3);
brk = 1'b0;
end
`OP_MMIN: begin
t1 = 32'd0;
t2 = 32'd0;
d = func_mmin2(s1,s2);
brk = 1'b0;
end
`endif
`ifdef ENABLE_CRYPTO
`OP_MAJ: begin /* (((x) & (y))^((x) & (z))^((y) & (z))) */
/* ex1_outd = (r1&0xffffffff00000000LL) | (((r1 & r2)^(r1 & r3)^(r2 & r3))&0xffffffffLL) */
t1 = 32'd0;
t2 = 32'd0;
if (hi_lo) d = s1;
else d = (s1 & s2)^(s1 & s3)^(s2 & s3);
brk = 1'b0;
end
`OP_CH: begin /* (((x) & (y))^(~(x) & (z))) */
/* ex1_outd = (r1&0xffffffff00000000LL) | (((r1 & r2)^(~r1 & r3))&0xffffffffLL) */
t1 = 32'd0;
t2 = 32'd0;
if (hi_lo) d = s1;
else d = (s1 & s2)^(~s1 & s3);
brk = 1'b0;
end
`endif
endcase
ex1_internal = {d, brk};
end
endfunction
wire [`EXE_WORD_BITS-1:0] ex2dt;
assign {ex2dt, brk} = ex1_internal(hi_lo, op, ex1, ex2, ex3);
wire [`EXE_WORD_BITS-1:0] r_ex2d = ex2dt;
nbit_register #(`EXE_WORD_BITS) ex2d_r(.ACLK(ACLK), .RSTN(RSTN), .d(r_ex2d), .q(ex2d)); //slice 1
endmodule
`ifdef ENABLE_FPU
module fpu1
(
input wire ACLK,
input wire RSTN,
input wire [1:0] op,
input wire [31:0] ex1,
input wire [31:0] ex2,
input wire [31:0] ex3,
input wire force0,
output wire ex1_d_s,
output wire [8:0] ex1_d_exp,
output wire [24+`PEXT:0] ex1_d_csa_s, //■■■
output wire [24+`PEXT:0] ex1_d_csa_c, //■■■
output wire ex1_d_zero,
output wire ex1_d_inf,
output wire ex1_d_nan,
output wire fadd_s1_s,
output wire [8:0] fadd_s1_exp,
output wire [24+`PEXT:0] fadd_s1_frac, //■■■
output wire fadd_s1_zero,
output wire fadd_s1_inf,
output wire fadd_s1_nan
);
wire const_one = 1'b1;
wire s1_s = (op==2'd3)? 1'b0:ex1[31];
wire [7:0] s1_exp = (op==2'd3)? 8'd0:ex1[30:23];
wire [23:0] s1_frac = (op==2'd3)? 24'd0:(~(|s1_exp))?{1'b0,ex1[22:0]}:{1'b1,ex1[22:0]};
wire s1_zero = (op==2'd3)? 1'b1: (~(|s1_exp)) & (~(|ex1[22:0]));
wire s1_inf = (op==2'd3)? 1'b0: ( &s1_exp ) & (~(|ex1[22:0]));
wire s1_nan = (op==2'd3)? 1'b0: ( &s1_exp ) & ( |ex1[22:0] );
wire s2_s = (op==2'd1)?~ex2[31]:ex2[31];
wire [7:0] s2_exp = ex2[30:23];
wire [23:0] s2_frac = (~(|s2_exp))?{1'b0,ex2[22:0]}:{1'b1,ex2[22:0]};
wire s2_zero = (~(|s2_exp)) & (~(|ex2[22:0]));
wire s2_inf = ( &s2_exp ) & (~(|ex2[22:0]));
wire s2_nan = ( &s2_exp ) & ( |ex2[22:0] );
wire s3_s = (op==2'd2)? 1'b0 :ex3[31];
wire [7:0] s3_exp = (op==2'd2)? 8'd127 :ex3[30:23];
wire [23:0] s3_frac = (op==2'd2)? 24'h80_0000:(~(|s3_exp))?{1'b0,ex3[22:0]}:{1'b1,ex3[22:0]};
wire s3_zero = (op==2'd2)? 1'b0 :(~(|s3_exp)) & (~(|ex3[22:0]));
wire s3_inf = (op==2'd2)? 1'b0 :( &s3_exp ) & (~(|ex3[22:0]));
wire s3_nan = (op==2'd2)? 1'b0 :( &s3_exp ) & ( |ex3[22:0] );
wire [47:0] booth_s;
wire [47:0] booth_c;
bit24_booth_wallace bw_impl (.ai(s2_frac), .bi(s3_frac), .so(booth_s), .co(booth_c));
wire r_ex1_d_s = force0 ? 1'b0 : (s2_s ^ s3_s); //★WEX
wire [8:0] r_ex1_d_exp = force0 ? 9'd0 : ({1'b0,s2_exp} + {1'b0,s3_exp} < 9'd127 ? 9'd0 : //★WEX
{1'b0,s2_exp} + {1'b0,s3_exp} - 9'd127); //★WEX
wire [24+`PEXT:0] r_ex1_d_csa_s = force0 ? {(24+`PEXT+1){1'b0}} : booth_s[47:23-`PEXT]; /* sum ここで丸め誤差が出る (FMAの限界) */ //■■■ //★WEX
wire [24+`PEXT:0] r_ex1_d_csa_c = force0 ? {(24+`PEXT+1){1'b0}} : booth_c[47:23-`PEXT]; /* carry ここで丸め誤差が出る (FMAの限界) */ //■■■ //★WEX
wire r_ex1_d_zero = force0 ? 1'b1 : ((s2_zero && !s3_inf && !s3_nan) || (s3_zero && !s2_inf && !s2_nan)); //★WEX
wire r_ex1_d_inf = force0 ? 1'b0 : ((s2_inf && !s3_zero && !s3_nan) || (s3_inf && !s2_zero && !s2_nan)); //★WEX
wire r_ex1_d_nan = force0 ? 1'b0 : (s2_nan || s3_nan || (s2_inf && s3_zero) || (s3_inf && s2_zero)); //★WEX
nbit_register #(1) ex1_d_s_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_ex1_d_s ), .q(ex1_d_s )); //slice 1
nbit_register #(9) ex1_d_exp_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_ex1_d_exp ), .q(ex1_d_exp )); //slice 1
nbit_register #(25+`PEXT) ex1_d_csa_s_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_ex1_d_csa_s), .q(ex1_d_csa_s )); //slice 1 //■■■
nbit_register #(25+`PEXT) ex1_d_csa_c_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_ex1_d_csa_c), .q(ex1_d_csa_c )); //slice 1 //■■■
nbit_register #(1) ex1_d_zero_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_ex1_d_zero ), .q(ex1_d_zero )); //slice 1
nbit_register #(1) ex1_d_inf_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_ex1_d_inf ), .q(ex1_d_inf )); //slice 1
nbit_register #(1) ex1_d_nan_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_ex1_d_nan ), .q(ex1_d_nan )); //slice 1
wire r_fadd_s1_s = s1_s;
wire [8:0] r_fadd_s1_exp = (8'd0<s1_exp&&s1_exp<8'd255)?{1'b0,(s1_exp-8'd1)}:{1'b0,s1_exp};
wire [24+`PEXT:0] r_fadd_s1_frac = (8'd0<s1_exp&&s1_exp<8'd255)?{s1_frac,{(`PEXT+1){1'b0}}}:{1'b0,s1_frac,{(`PEXT){1'b0}}}; //■■■
wire r_fadd_s1_zero = s1_zero;
wire r_fadd_s1_inf = s1_inf;
wire r_fadd_s1_nan = s1_nan;
nbit_register #(1) fadd_s1_s_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_fadd_s1_s ), .q(fadd_s1_s )); //slice 1
nbit_register #(9) fadd_s1_exp_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_fadd_s1_exp ), .q(fadd_s1_exp )); //slice 1
nbit_register #(25+`PEXT) fadd_s1_frac_r(.ACLK(ACLK), .RSTN(RSTN), .d(r_fadd_s1_frac), .q(fadd_s1_frac)); //slice 1 //■■■
nbit_register #(1) fadd_s1_zero_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_fadd_s1_zero), .q(fadd_s1_zero)); //slice 1
nbit_register #(1) fadd_s1_inf_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_fadd_s1_inf ), .q(fadd_s1_inf )); //slice 1
nbit_register #(1) fadd_s1_nan_r (.ACLK(ACLK), .RSTN(RSTN), .d(r_fadd_s1_nan ), .q(fadd_s1_nan )); //slice 1
endmodule
`endif
`ifdef ENABLE_SPU
module spu1
(
input wire ACLK,
input wire RSTN,
input wire exec,
input wire fold,
input wire [`REG_DATA_BITS-1:0] ex2,
input wire [`REG_DATA_BITS-1:0] ex3,
output wire [`SPU_DATA_LOG2-1:0] sfmapc0,
output wire [`SPU_DATA_LOG2-1:0] sfmanc0,
output wire [`SPU_DATA_LOG2-1:0] sfmapc1,
output wire [`SPU_DATA_LOG2-1:0] sfmanc1,
output wire [`SPU_DATA_LOG2-1:0] sfmapc2,
output wire [`SPU_DATA_LOG2-1:0] sfmanc2,
output wire [`SPU_DATA_LOG2-1:0] sfmapc3,
output wire [`SPU_DATA_LOG2-1:0] sfmanc3,
output wire [`SPU_DATA_LOG2-1:0] sfmapc4,
output wire [`SPU_DATA_LOG2-1:0] sfmanc4,
output wire [`SPU_DATA_LOG2-1:0] sfmapc5,
output wire [`SPU_DATA_LOG2-1:0] sfmanc5,
output wire [`SPU_DATA_LOG2-1:0] sfmapc6,
output wire [`SPU_DATA_LOG2-1:0] sfmanc6,
output wire [`SPU_DATA_LOG2-1:0] sfmapc7,
output wire [`SPU_DATA_LOG2-1:0] sfmanc7
);
//Ull urand(int no)
// static Ull urand_seed[8]
// = {0xc3c3c3c3a5a5a5a5LL, 0x123456789abcdef0LL, 0xe1e1e1e1d4d4d4d4LL, 0x8888777766665555LL,
// 0x8787878796969696LL, 0xfedcba9876543210LL, 0x5a5a5a5a3c3c3c3cLL, 0xbbbbccccddddeeeeLL};
// Ull retval = urand_seed[no];
// urand_seed[no] ^= (urand_seed[no]<<29);
// urand_seed[no] ^= (urand_seed[no]>>27);
// urand_seed[no] ^= (urand_seed[no]<<37);
// return (retval);
// for (i=0; i<8; i++) /* s2 * s3 -> ad2 */
// u[i] = urand(i);
// for (i=0; i<8; i++) { /* s2 * s3 -> ad2 */
// ss[i] = (r2>>(i*8+7))&1 ^ (r3>>(i*8+7))&1;
//int s2e = (r2>>(i*8))&0x7f; s2e = s2e<SPU_DATA_BITS?s2e:SPU_DATA_BITS;
//int s3e = (r3>>(i*8))&0x7f; s3e = s3e<SPU_DATA_BITS?s3e:SPU_DATA_BITS;
// s2[i] = 0LL;
// s3[i] = 0LL;
// for (j=0; j<SPU_COUT_BITS; j++) {
// int k = j * SPU_DATA_DIST; /* SPU_DATA_BITS=15なら4bit毎 */
// s2[i] |= ((u[(i+0)%8]>>k&SPU_DATA_BITS)<=s2e)<<j;
// s3[i] |= ((u[(i+1)%8]>>k&SPU_DATA_BITS)<=s3e)<<j;
// }
// o1[i] = s2[i] & s3[i];
// o1[i] = ss[i]<<63|(o1[i]&0x7fffffffffffffffLL);
// }
function [63:0] urand;
input [63:0] us;
reg [63:0] u1;
reg [63:0] u2;
reg [63:0] u3;
begin
u1 = us[63:0] ^ {us[34:0],29'd0};
u2 = u1[63:0] ^ {27'd0,u1[63:27]};
u3 = u2[63:0] ^ {u2[26:0],37'd0};
urand = u3;
end
endfunction
reg [63:0] ur0;
reg [63:0] ur1;
reg [63:0] ur2;
reg [63:0] ur3;
reg [63:0] ur4;
reg [63:0] ur5;
reg [63:0] ur6;
reg [63:0] ur7;
wire [63:0] ur0n = urand(ur0);
wire [63:0] ur1n = urand(ur1);
wire [63:0] ur2n = urand(ur2);
wire [63:0] ur3n = urand(ur3);
wire [63:0] ur4n = urand(ur4);
wire [63:0] ur5n = urand(ur5);
wire [63:0] ur6n = urand(ur6);
wire [63:0] ur7n = urand(ur7);
always @(posedge ACLK or negedge RSTN) begin
if (~RSTN) begin
ur0 <= 64'hc3c3c3c3a5a5a5a5;
ur1 <= 64'h123456789abcdef0;
ur2 <= 64'he1e1e1e1d4d4d4d4;
ur3 <= 64'h8888777766665555;
ur4 <= 64'h8787878796969696;
ur5 <= 64'hfedcba9876543210;
ur6 <= 64'h5a5a5a5a3c3c3c3c;
ur7 <= 64'hbbbbccccddddeeee;
end
else if (exec || fold) begin
ur0 <= ur0n;
ur1 <= ur1n;
ur2 <= ur2n;
ur3 <= ur3n;
ur4 <= ur4n;
ur5 <= ur5n;
ur6 <= ur6n;
ur7 <= ur7n;
end
end
wire [`SPU_DATA_BITS:0] r_sfma0;
wire [`SPU_DATA_BITS:0] r_sfma1;
wire [`SPU_DATA_BITS:0] r_sfma2;
wire [`SPU_DATA_BITS:0] r_sfma3;
wire [`SPU_DATA_BITS:0] r_sfma4;
wire [`SPU_DATA_BITS:0] r_sfma5;
wire [`SPU_DATA_BITS:0] r_sfma6;
wire [`SPU_DATA_BITS:0] r_sfma7;
assign r_sfma0[`SPU_DATA_BITS] = ex2[ 7] ^ ex3[ 7];
assign r_sfma1[`SPU_DATA_BITS] = ex2[15] ^ ex3[15];
assign r_sfma2[`SPU_DATA_BITS] = ex2[23] ^ ex3[23];
assign r_sfma3[`SPU_DATA_BITS] = ex2[31] ^ ex3[31];
assign r_sfma4[`SPU_DATA_BITS] = ex2[39] ^ ex3[39];
assign r_sfma5[`SPU_DATA_BITS] = ex2[47] ^ ex3[47];
assign r_sfma6[`SPU_DATA_BITS] = ex2[55] ^ ex3[55];
assign r_sfma7[`SPU_DATA_BITS] = ex2[63] ^ ex3[63];
wire [`SPU_DATA_LOG2-1:0] s2e0 = (ex2[ 6: 0]<`SPU_DATA_BITS)?ex2[ 6: 0]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s2e1 = (ex2[14: 8]<`SPU_DATA_BITS)?ex2[14: 8]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s2e2 = (ex2[22:16]<`SPU_DATA_BITS)?ex2[22:16]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s2e3 = (ex2[30:24]<`SPU_DATA_BITS)?ex2[30:24]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s2e4 = (ex2[38:32]<`SPU_DATA_BITS)?ex2[38:32]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s2e5 = (ex2[46:40]<`SPU_DATA_BITS)?ex2[46:40]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s2e6 = (ex2[54:48]<`SPU_DATA_BITS)?ex2[54:48]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s2e7 = (ex2[62:56]<`SPU_DATA_BITS)?ex2[62:56]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s3e0 = (ex3[ 6: 0]<`SPU_DATA_BITS)?ex3[ 6: 0]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s3e1 = (ex3[14: 8]<`SPU_DATA_BITS)?ex3[14: 8]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s3e2 = (ex3[22:16]<`SPU_DATA_BITS)?ex3[22:16]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s3e3 = (ex3[30:24]<`SPU_DATA_BITS)?ex3[30:24]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s3e4 = (ex3[38:32]<`SPU_DATA_BITS)?ex3[38:32]:`SPU_DATA_BITS;
wire [`SPU_DATA_LOG2-1:0] s3e5 = (ex3[46:40]<`SPU_DATA_BITS)?ex3[46:40]:`SPU_DATA_BITS;