-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathvmfpu.sv
More file actions
2409 lines (2143 loc) · 102 KB
/
Copy pathvmfpu.sv
File metadata and controls
2409 lines (2143 loc) · 102 KB
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
// Copyright 2021 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51
//
// Authors: Matheus Cavalcante <matheusd@iis.ee.ethz.ch>
// Matteo Perotti <mperotti@iis.ee.ethz.ch>
// Description:
// Ara's integer multiplier and floating-point unit.
module vmfpu import ara_pkg::*; import rvv_pkg::*; import fpnew_pkg::*;
import cf_math_pkg::idx_width; #(
parameter int unsigned NrLanes = 0,
parameter int unsigned VLEN = 0,
parameter config_pkg::cva6_cfg_t CVA6Cfg = cva6_config_pkg::cva6_cfg,
// Support for floating-point data types
parameter fpu_support_e FPUSupport = FPUSupportHalfSingleDouble,
// External support for vfrec7, vfrsqrt7, rounding-toward-odd
parameter fpext_support_e FPExtSupport = FPExtSupportEnable,
// Support for fixed-point data types
parameter fixpt_support_e FixPtSupport = FixedPointEnable,
// Type used to address vector register file elements
parameter type vaddr_t = logic,
parameter type vfu_operation_t = logic,
// Dependant parameters. DO NOT CHANGE!
localparam int unsigned DataWidth = $bits(elen_t),
localparam int unsigned StrbWidth = DataWidth/8,
localparam type strb_t = logic [DataWidth/8-1:0],
localparam type vlen_t = logic[$clog2(VLEN+1)-1:0]
) (
input logic clk_i,
input logic rst_ni,
input logic[idx_width(NrLanes)-1:0] lane_id_i,
// Interface with Dispatcher
output logic mfpu_vxsat_o,
input vxrm_t mfpu_vxrm_i,
// Interface with CVA6
output logic [4:0] fflags_ex_o,
output logic fflags_ex_valid_o,
// Interface with the lane sequencer
input vfu_operation_t vfu_operation_i,
input logic vfu_operation_valid_i,
output logic mfpu_ready_o,
output logic [NrVInsn-1:0] mfpu_vinsn_done_o,
// Interface with the lane
output logic fpu_red_complete_o,
// Interface with the operand queues
input elen_t [2:0] mfpu_operand_i,
input logic [2:0] mfpu_operand_valid_i,
output logic [2:0] mfpu_operand_ready_o,
// Interface with the vector register file
output logic mfpu_result_req_o,
output vid_t mfpu_result_id_o,
output vaddr_t mfpu_result_addr_o,
output elen_t mfpu_result_wdata_o,
output strb_t mfpu_result_be_o,
input logic mfpu_result_gnt_i,
// Interface with the Slide Unit
output logic mfpu_red_valid_o,
input logic mfpu_red_ready_i,
input elen_t sldu_operand_i,
input logic sldu_mfpu_valid_i,
output logic sldu_mfpu_ready_o,
// Interface with the Mask unit
output elen_t mask_operand_o,
output logic mask_operand_valid_o,
input logic mask_operand_ready_i,
input strb_t mask_i,
input logic mask_valid_i,
output logic mask_ready_o
);
// Power gating registers
`include "common_cells/registers.svh"
////////////////////////////////
// Vector instruction queue //
////////////////////////////////
// We store a certain number of in-flight vector instructions
localparam VInsnQueueDepth = MfpuInsnQueueDepth;
struct packed {
vfu_operation_t [VInsnQueueDepth-1:0] vinsn;
// Each instruction can be in one of the three execution phases.
// - Being accepted (i.e., it is being stored for future execution in this
// vector functional unit).
// - Being processed (i.e., its micro-operations are currently being processed
// by the corresponding functional units).
// - Being issued (i.e., its micro-operations are currently being issued
// to the corresponding functional units).
// - Being committed (i.e., its results are being written to the vector
// register file).
// We need pointers to index which instruction is at each execution phase
// between the VInsnQueueDepth instructions in memory.
logic [idx_width(VInsnQueueDepth)-1:0] accept_pnt;
logic [idx_width(VInsnQueueDepth)-1:0] issue_pnt;
logic [idx_width(VInsnQueueDepth)-1:0] processing_pnt;
logic [idx_width(VInsnQueueDepth)-1:0] commit_pnt;
// We also need to count how many instructions are queueing to be
// issued/committed, to avoid accepting more instructions than
// we can handle.
logic [idx_width(VInsnQueueDepth):0] issue_cnt;
logic [idx_width(VInsnQueueDepth):0] processing_cnt;
logic [idx_width(VInsnQueueDepth):0] commit_cnt;
} vinsn_queue_d, vinsn_queue_q;
// Is the vector instruction queue full?
logic vinsn_queue_full;
assign vinsn_queue_full = (vinsn_queue_q.commit_cnt == VInsnQueueDepth);
// Do we have a vector instruction ready to be issued?
vfu_operation_t vinsn_issue_d, vinsn_issue_q;
logic vinsn_issue_d_valid, vinsn_issue_q_valid;
assign vinsn_issue_d = vinsn_queue_d.vinsn[vinsn_queue_d.issue_pnt];
assign vinsn_issue_d_valid = (vinsn_queue_d.issue_cnt != '0);
assign vinsn_issue_q_valid = (vinsn_queue_q.issue_cnt != '0);
// Do we have a vector instruction being processed?
vfu_operation_t vinsn_processing_d, vinsn_processing_q;
logic vinsn_processing_d_valid, vinsn_processing_q_valid;
assign vinsn_processing_d = vinsn_queue_d.vinsn[vinsn_queue_d.processing_pnt];
assign vinsn_processing_q = vinsn_queue_q.vinsn[vinsn_queue_q.processing_pnt];
assign vinsn_processing_d_valid = (vinsn_queue_d.processing_cnt != '0);
assign vinsn_processing_q_valid = (vinsn_queue_q.processing_cnt != '0);
// Do we have a vector instruction with results being committed?
vfu_operation_t vinsn_commit;
logic vinsn_commit_valid;
assign vinsn_commit = vinsn_queue_q.vinsn[vinsn_queue_q.commit_pnt];
assign vinsn_commit_valid = (vinsn_queue_q.commit_cnt != '0);
always_ff @(posedge clk_i or negedge rst_ni) begin
if (!rst_ni) begin
vinsn_queue_q <= '0;
vinsn_issue_q <= '0;
end else begin
vinsn_queue_q <= vinsn_queue_d;
vinsn_issue_q <= vinsn_issue_d;
end
end
////////////////////
// Result queue //
////////////////////
localparam int unsigned ResultQueueDepth = 2;
// There is a result queue per VFU, holding the results that were not
// yet accepted by the corresponding lane.
typedef struct packed {
vid_t id;
vaddr_t addr;
elen_t wdata;
strb_t be;
logic mask;
} payload_t;
// Result queue
payload_t [ResultQueueDepth-1:0] result_queue_d, result_queue_q;
logic [ResultQueueDepth-1:0] result_queue_valid_d, result_queue_valid_q;
// We need two pointers in the result queue. One pointer to
// indicate with `payload_t` we are currently writing into (write_pnt),
// and one pointer to indicate which `payload_t` we are currently
// reading from and writing into the lanes (read_pnt).
logic [idx_width(ResultQueueDepth)-1:0] result_queue_write_pnt_d, result_queue_write_pnt_q;
logic [idx_width(ResultQueueDepth)-1:0] result_queue_read_pnt_d, result_queue_read_pnt_q;
// We need to count how many valid elements are there in this result queue.
logic [idx_width(ResultQueueDepth):0] result_queue_cnt_d, result_queue_cnt_q;
// Is the result queue full?
logic result_queue_full;
assign result_queue_full = (result_queue_cnt_q == ResultQueueDepth);
always_ff @(posedge clk_i or negedge rst_ni) begin: p_result_queue_ff
if (!rst_ni) begin
result_queue_q <= '0;
result_queue_valid_q <= '0;
result_queue_write_pnt_q <= '0;
result_queue_read_pnt_q <= '0;
result_queue_cnt_q <= '0;
end else begin
result_queue_q <= result_queue_d;
result_queue_valid_q <= result_queue_valid_d;
result_queue_write_pnt_q <= result_queue_write_pnt_d;
result_queue_read_pnt_q <= result_queue_read_pnt_d;
result_queue_cnt_q <= result_queue_cnt_d;
end
end
//////////////////////
// Helper signals //
//////////////////////
logic vinsn_issue_mul, vinsn_issue_div, vinsn_issue_fpu;
assign vinsn_issue_mul = vinsn_issue_q.op inside {[VMUL:VSMUL]};
assign vinsn_issue_div = vinsn_issue_q.op inside {[VDIVU:VREM]};
assign vinsn_issue_fpu = vinsn_issue_q.op inside {[VFADD:VMFGE]};
// This function returns the latency of the FPU operation,
// depending on the sew as well
typedef logic [idx_width(LatFMax)-1:0] fpu_latency_t;
function automatic fpu_latency_t fpu_latency(vew_e sew, ara_op_e op);
case (op) inside
VFDIV, VFRDIV, VFSQRT: fpu_latency = LatFDivSqrt;
[VFREDMIN:VFREDMAX]: fpu_latency = LatFNonComp;
[VFCVTXUF:VFCVTFF]: fpu_latency = LatFConv;
[VFMIN:VFSGNJX]: fpu_latency = LatFNonComp;
// FP comparisons are non-computational FPU ops (CVFPU NONCOMP group),
// like VFMIN..VFSGNJX above. Without this case they fall through to the
// arithmetic (sew-based) latency, which mis-aligns the mask-routing tag
// under pipeline pressure and sends the comparison result to the VRF
// instead of the mask unit.
[VMFEQ:VMFGE]: fpu_latency = LatFNonComp;
default: begin
case (sew)
EW64: fpu_latency = LatFCompEW64;
EW32: fpu_latency = LatFCompEW32;
EW16: fpu_latency = LatFCompEW16;
default: fpu_latency = LatFCompEW8;
endcase
end
endcase
endfunction: fpu_latency
//////////////////////
// Scalar operand //
//////////////////////
elen_t scalar_op;
// Replicate the scalar operand on the 64-bit word, depending
// on the element width.
always_comb begin
// Default assignment
scalar_op = '0;
case (vinsn_issue_q.vtype.vsew)
EW64: scalar_op = {1{vinsn_issue_q.scalar_op[63:0]}};
EW32: scalar_op = {2{vinsn_issue_q.scalar_op[31:0]}};
EW16: scalar_op = {4{vinsn_issue_q.scalar_op[15:0]}};
EW8 : scalar_op = {8{vinsn_issue_q.scalar_op[ 7:0]}};
default:;
endcase
end
/////////////////////
// Mask operands //
/////////////////////
logic mask_operand_ready;
logic mask_operand_gnt;
assign mask_operand_gnt = mask_operand_ready && result_queue_q[result_queue_read_pnt_q].mask && result_queue_valid_q[result_queue_read_pnt_q];
spill_register #(
.T(elen_t)
) i_mask_operand_register (
.clk_i (clk_i ),
.rst_ni (rst_ni ),
.data_o (mask_operand_o ),
.valid_o (mask_operand_valid_o ),
.ready_i (mask_operand_ready_i ),
.data_i (result_queue_q[result_queue_read_pnt_q].wdata ),
.valid_i (result_queue_q[result_queue_read_pnt_q].mask && result_queue_valid_q[result_queue_read_pnt_q]),
.ready_o (mask_operand_ready )
);
//////////////////////////////
// Narrowing instructions //
//////////////////////////////
// This function returns 1'b1 if `op` is a narrowing instruction, i.e.,
// it produces only EEW/2 per cycle.
function automatic logic narrowing(resize_e resize);
narrowing = 1'b0;
if (resize == CVT_NARROW)
narrowing = 1'b1;
endfunction: narrowing
// If this is a narrowing instruction, point to which half of the
// output EEW word we are producing.
// Input selector, used to acknowledge the mask operands once every two cycles
logic narrowing_select_in_d, narrowing_select_in_q;
// Output selector, used to control the Result MUX and validate the results
logic narrowing_select_out_d, narrowing_select_out_q;
// FPU SIMD result needs to be shuffled for narrowing instructions before commit
elen_t narrowing_shuffled_result;
// Helper signal to shuffle the narrowed result
logic [7:0] narrowing_shuffle_be;
//////////////////
// Multiplier //
//////////////////
// Clock-gate for the multipliers
logic clkgate_en_d, clkgate_en_q, clk_i_gated;
tc_clk_gating i_simd_mul_manual_clk_gate (
.clk_i (clk_i ),
.en_i (clkgate_en_q),
.test_en_i (1'b0 ),
.clk_o (clk_i_gated )
);
assign clkgate_en_d = vinsn_processing_d_valid & (vinsn_processing_d.op inside {[VMUL:VSMUL]});
elen_t [3:0] vmul_simd_result;
logic [3:0] vmul_simd_in_valid;
logic [3:0] vmul_simd_in_ready;
logic [3:0] vmul_simd_out_valid;
logic [3:0] vmul_simd_out_ready;
// We let the mask percolate throughout the pipeline to have the mask unit synchronized with the
// operand queues
// Another choice would be to delay the mask grant when the vmul_result is committed
strb_t [3:0] vmul_simd_mask;
vxsat_t [3:0] mfpu_vxsat;
logic [7:0] mfpu_vxsat_q, mfpu_vxsat_d;
// mfpu saturation calculation
assign mfpu_vxsat_o = |(mfpu_vxsat_q & result_queue_q[result_queue_read_pnt_q].be);
// Only for power-saving purposes
// The pipeline inside the multipliers is passive and always enabled
// Masking the inputs is almost necessary since their logic cone is huge
elen_t vmul_simd_op_a_q, vmul_simd_op_b_q, vmul_simd_op_c_q;
strb_t vmul_simd_mask_q;
ara_op_e vmul_simd_op_q;
elen_t [3:0] vmul_simd_op_a_q_gated;
elen_t [3:0] vmul_simd_op_b_q_gated;
elen_t [3:0] vmul_simd_op_c_q_gated;
strb_t [3:0] vmul_simd_mask_q_gated;
ara_op_e [3:0] vmul_simd_op_q_gated;
logic [3:0] vmul_simd_in_valid_q;
logic gate_ff_en, gate_ff_clr;
// Enable if the next stage is ready
assign gate_ff_en = vmul_simd_in_ready[vinsn_processing_q.vtype.vsew];
// Flush if the next stage is clear but there is no valid input
assign gate_ff_clr = vmul_simd_in_ready[vinsn_processing_q.vtype.vsew] &
~vmul_simd_in_valid[vinsn_issue_q.vtype.vsew];
`FFLARNC(vmul_simd_op_a_q, vinsn_issue_q.use_scalar_op ? scalar_op : mfpu_operand_i[0],
gate_ff_en, gate_ff_clr, '0, clk_i_gated, rst_ni);
`FFLARNC(vmul_simd_op_b_q, mfpu_operand_i[1],
gate_ff_en, gate_ff_clr, '0, clk_i_gated, rst_ni);
`FFLARNC(vmul_simd_op_c_q, mfpu_operand_i[2],
gate_ff_en, gate_ff_clr, '0, clk_i_gated, rst_ni);
`FFLARNC(vmul_simd_mask_q, mask_i,
gate_ff_en, gate_ff_clr, '0, clk_i_gated, rst_ni);
`FFLARNC(vmul_simd_op_q, vinsn_issue_q.op,
gate_ff_en, gate_ff_clr, ara_op_e'('0), clk_i_gated, rst_ni);
`FFLARNC(vmul_simd_in_valid_q, vmul_simd_in_valid,
gate_ff_en, gate_ff_clr, '0, clk_i_gated, rst_ni);
for (genvar i = 0; i < 4; i++) begin
`ifdef GF22
power_gating_gf22 #(
`else
power_gating_generic #(
`endif
.T (elen_t),
.NO_GLITCH(1'b0 )
) i_simd_mul_gating_op_a (
.in_i (vmul_simd_op_a_q ),
.en_i (vmul_simd_in_valid_q[i] ),
.out_o(vmul_simd_op_a_q_gated[i])
);
`ifdef GF22
power_gating_gf22 #(
`else
power_gating_generic #(
`endif
.T(elen_t),
.NO_GLITCH(1'b0 )
) i_simd_mul_gating_op_b (
.in_i (vmul_simd_op_b_q ),
.en_i (vmul_simd_in_valid_q[i] ),
.out_o (vmul_simd_op_b_q_gated[i])
);
`ifdef GF22
power_gating_gf22 #(
`else
power_gating_generic #(
`endif
.T(elen_t),
.NO_GLITCH(1'b0 )
) i_simd_mul_gating_op_c (
.in_i (vmul_simd_op_c_q ),
.en_i (vmul_simd_in_valid_q[i] ),
.out_o (vmul_simd_op_c_q_gated[i])
);
`ifdef GF22
power_gating_gf22 #(
`else
power_gating_generic #(
`endif
.T(strb_t),
.NO_GLITCH(1'b0 )
) i_simd_mul_gating_mask (
.in_i (vmul_simd_mask_q ),
.en_i (vmul_simd_in_valid_q[i] ),
.out_o (vmul_simd_mask_q_gated[i])
);
`ifdef GF22
power_gating_gf22 #(
`else
power_gating_generic #(
`endif
.T(ara_op_e),
.NO_GLITCH(1'b0 )
) i_simd_mul_gating_op (
.in_i (vmul_simd_op_q ),
.en_i (vmul_simd_in_valid_q[i]),
.out_o (vmul_simd_op_q_gated[i])
);
end
simd_mul #(
.FixPtSupport(FixPtSupport ),
.NumPipeRegs (LatMultiplierEW64),
.ElementWidth(EW64 )
) i_simd_mul_ew64 (
.clk_i (clk_i_gated ),
.rst_ni (rst_ni ),
.operand_a_i(vmul_simd_op_a_q_gated[EW64] ),
.operand_b_i(vmul_simd_op_b_q_gated[EW64] ),
.operand_c_i(vmul_simd_op_c_q_gated[EW64] ),
.mask_i (vmul_simd_mask_q_gated[EW64] ),
.op_i (vmul_simd_op_q_gated[EW64] ),
.vxsat_o (mfpu_vxsat[EW64] ),
.vxrm_i (mfpu_vxrm_i ),
.result_o (vmul_simd_result[EW64] ),
.mask_o (vmul_simd_mask[EW64] ),
.valid_i (vmul_simd_in_valid_q[EW64] ),
.ready_o (vmul_simd_in_ready[EW64] ),
.ready_i (vmul_simd_out_ready[EW64] ),
.valid_o (vmul_simd_out_valid[EW64] )
);
simd_mul #(
.FixPtSupport(FixPtSupport ),
.NumPipeRegs (LatMultiplierEW32),
.ElementWidth(EW32 )
) i_simd_mul_ew32 (
.clk_i (clk_i_gated ),
.rst_ni (rst_ni ),
.operand_a_i(vmul_simd_op_a_q_gated[EW32] ),
.operand_b_i(vmul_simd_op_b_q_gated[EW32] ),
.operand_c_i(vmul_simd_op_c_q_gated[EW32] ),
.mask_i (vmul_simd_mask_q_gated[EW32] ),
.op_i (vmul_simd_op_q_gated[EW32] ),
.vxsat_o (mfpu_vxsat[EW32] ),
.vxrm_i (mfpu_vxrm_i ),
.result_o (vmul_simd_result[EW32] ),
.mask_o (vmul_simd_mask[EW32] ),
.valid_i (vmul_simd_in_valid_q[EW32] ),
.ready_o (vmul_simd_in_ready[EW32] ),
.ready_i (vmul_simd_out_ready[EW32] ),
.valid_o (vmul_simd_out_valid[EW32] )
);
simd_mul #(
.FixPtSupport(FixPtSupport ),
.NumPipeRegs (LatMultiplierEW16),
.ElementWidth(EW16 )
) i_simd_mul_ew16 (
.clk_i (clk_i_gated ),
.rst_ni (rst_ni ),
.operand_a_i(vmul_simd_op_a_q_gated[EW16] ),
.operand_b_i(vmul_simd_op_b_q_gated[EW16] ),
.operand_c_i(vmul_simd_op_c_q_gated[EW16] ),
.mask_i (vmul_simd_mask_q_gated[EW16] ),
.op_i (vmul_simd_op_q_gated[EW16] ),
.result_o (vmul_simd_result[EW16] ),
.vxsat_o (mfpu_vxsat[EW16] ),
.vxrm_i (mfpu_vxrm_i ),
.mask_o (vmul_simd_mask[EW16] ),
.valid_i (vmul_simd_in_valid_q[EW16] ),
.ready_o (vmul_simd_in_ready[EW16] ),
.ready_i (vmul_simd_out_ready[EW16] ),
.valid_o (vmul_simd_out_valid[EW16] )
);
simd_mul #(
.FixPtSupport(FixPtSupport ),
.NumPipeRegs (LatMultiplierEW8),
.ElementWidth(EW8 )
) i_simd_mul_ew8 (
.clk_i (clk_i_gated ),
.rst_ni (rst_ni ),
.operand_a_i(vmul_simd_op_a_q_gated[EW8] ),
.operand_b_i(vmul_simd_op_b_q_gated[EW8] ),
.operand_c_i(vmul_simd_op_c_q_gated[EW8] ),
.mask_i (vmul_simd_mask_q_gated[EW8] ),
.op_i (vmul_simd_op_q_gated[EW8] ),
.vxsat_o (mfpu_vxsat[EW8] ),
.vxrm_i (mfpu_vxrm_i ),
.result_o (vmul_simd_result[EW8] ),
.mask_o (vmul_simd_mask[EW8] ),
.valid_i (vmul_simd_in_valid_q[EW8] ),
.ready_o (vmul_simd_in_ready[EW8] ),
.ready_i (vmul_simd_out_ready[EW8] ),
.valid_o (vmul_simd_out_valid[EW8] )
);
// The outputs of the SIMD multipliers are read in order
elen_t vmul_result;
logic vmul_in_valid;
logic vmul_in_ready;
logic vmul_out_valid;
logic vmul_out_ready;
strb_t vmul_mask;
always_comb begin
// Only one SIMD Multiplier receives the request
vmul_simd_in_valid = '0;
vmul_simd_in_valid[vinsn_issue_q.vtype.vsew] = clkgate_en_q & vmul_in_valid;
vmul_in_ready = clkgate_en_q & vmul_simd_in_ready[vinsn_issue_q.vtype.vsew];
// Saturation flag
mfpu_vxsat_d = mfpu_vxsat[vinsn_processing_q.vtype.vsew];
// We read the responses of a single SIMD Multiplier
vmul_result = vmul_simd_result[vinsn_processing_q.vtype.vsew];
vmul_mask = vmul_simd_mask[vinsn_processing_q.vtype.vsew];
vmul_out_valid = vmul_simd_out_valid[vinsn_processing_q.vtype.vsew];
vmul_simd_out_ready = '0;
vmul_simd_out_ready[vinsn_processing_q.vtype.vsew] = vmul_out_ready;
end
///////////////
// Divider //
///////////////
elen_t vdiv_result;
// Short circuit to invalid input elements with a mask
strb_t issue_be;
logic vdiv_in_valid;
logic vdiv_out_valid;
logic vdiv_in_ready;
logic vdiv_out_ready;
// We let the mask percolate throughout the pipeline to have the mask unit synchronized with the
// operand queues. Another choice would be to delay the mask grant when the vdiv_result is
// committed.
strb_t vdiv_mask;
simd_div # (
.CVA6Cfg(CVA6Cfg)
) i_simd_div (
.clk_i (clk_i ),
.rst_ni (rst_ni ),
.operand_a_i(mfpu_operand_i[1] ),
.operand_b_i(vinsn_issue_q.use_scalar_op ? scalar_op : mfpu_operand_i[0]),
.mask_i (mask_i ),
.op_i (vinsn_issue_q.op ),
.be_i (issue_be ),
.vew_i (vinsn_issue_q.vtype.vsew ),
.result_o (vdiv_result ),
.mask_o (vdiv_mask ),
.valid_i (vdiv_in_valid ),
.ready_o (vdiv_in_ready ),
.ready_i (vdiv_out_ready ),
.valid_o (vdiv_out_valid )
);
//////////////////
// Reductions //
//////////////////
// Cut the path between the SLDU and the MFPU. This increase latency
// but does has negligible impact on long vectors
elen_t sldu_operand_q;
logic sldu_mfpu_valid_q, sldu_mfpu_ready_d;
spill_register #(
.T(elen_t)
) i_mfpu_reduction_spill_register (
.clk_i (clk_i ),
.rst_ni (rst_ni ),
.valid_i(sldu_mfpu_valid_i),
.ready_o(sldu_mfpu_ready_o),
.data_i (sldu_operand_i ),
.valid_o(sldu_mfpu_valid_q),
.ready_i(sldu_mfpu_ready_d),
.data_o (sldu_operand_q )
);
// During an inter-lane reduction (after the intra-lane reduction), the NrLanes partial results
// must be reduced to only one. The first reduction is done by NrLanes/2 FUs, then NrLanes/4, and
// so on. In the end, the result is collected in Lane 0 and the last SIMD reduction is performed.
// The following function determines how many partial results this lane must process during the
// inter-lane reduction.
typedef logic [idx_width(NrLanes/2):0] reduction_rx_cnt_t;
reduction_rx_cnt_t reduction_rx_cnt_d, reduction_rx_cnt_q;
reduction_rx_cnt_t simd_red_cnt_max_d, simd_red_cnt_max_q;
// Reductions commit by zeroing the commit counter
// When the workload is unbalanced, some lanes can start the operation with a zeroed commit counter
// In this case, the ALU should NOT commit until the inter-lanes phase is over
logic prevent_commit;
// Count how many transactions we must do in total to complete the reduction operation
logic [idx_width($clog2(NrLanes)+1):0] sldu_transactions_cnt_d, sldu_transactions_cnt_q;
// Handshake synchronizer
// Since the SLDU must receive a valid signals also from lanes that should not send anything,
// we need to synchronize the dummy valids. A valid is given, then it is deleted after an
// handshake. It will be given again only after a valid_o by the SLDU
logic red_hs_synch_d, red_hs_synch_q;
// Counter to drive SIMD reductions
logic [1:0] simd_red_cnt_d, simd_red_cnt_q;
// Signal the first operation of an instruction. The first operation of a reduction instruction
// the operation is performed between the first vector element and the scalar.
// This signal has the highest privilage in multiple if-else loops
logic first_op_d, first_op_q;
// Inform the lane SLDU/ADDRGEN arbiter that this reduction is over
logic fpu_red_complete_d;
`FF(fpu_red_complete_o, fpu_red_complete_d, 1'b0, clk_i, rst_ni);
// Signal to indicate the state of the MFPU
typedef enum logic [2:0] {
NO_REDUCTION, INTRA_LANE_REDUCTION, INTER_LANES_REDUCTION_TX,
INTER_LANES_REDUCTION_RX, LN0_REDUCTION_COMMIT, SIMD_REDUCTION,
OSUM_REDUCTION, MFPU_WAIT
} mfpu_state_e;
mfpu_state_e mfpu_state_d, mfpu_state_q;
// ntr_filling indicates that the neutral value is being sent to the FPU as an operand
logic ntr_filling_d, ntr_filling_q;
// Check if there is a valid result data that can be used as an operand (result_queue_q)
// Because result_queue_valid may be set to 0, we need a signal to indicate that the old value is still valid
logic first_result_op_valid_d, first_result_op_valid_q;
// Count until the first result is avaible, used to end the neutral value filling
logic [3:0] intra_issued_op_cnt_d, intra_issued_op_cnt_q;
// Count how many operands received from the operand queue
vlen_t intra_op_rx_cnt_d, intra_op_rx_cnt_q;
logic intra_op_rx_cnt_en;
// This signal is used to cut a in2reg bad path
// This works since the signal is never checked
// twice in two consecutive cycles
logic mfpu_red_ready_q;
// Input multiplexers.
elen_t simd_red_operand;
strb_t red_mask;
// The ordered sum issue counter indicates how many elements in the operand data (64 bits) have been issued
// e.g. assume EEW=16, there are four elements in the operand data (4 * 16bits = 64 bits), the osum_issue_cnt counts from 0 to 3
logic [3:0] osum_issue_cnt_d, osum_issue_cnt_q;
// This function returns 1'b1 if `op` is a reduction instruction, i.e.,
// it must accumulate the result (intra-lane reduction) before sending it to the
// sliding unit (inter-lane and SIMD reduction).
function automatic logic is_reduction(ara_op_e op);
is_reduction = 1'b0;
if (op inside {[VFREDUSUM:VFWREDOSUM]})
is_reduction = 1'b1;
endfunction: is_reduction
// This function returns the next mfpu_state for the next instruction
function automatic mfpu_state_e next_mfpu_state(ara_op_e op);
if (op inside {VFREDUSUM, VFREDMIN, VFREDMAX, VFWREDUSUM})
next_mfpu_state = INTRA_LANE_REDUCTION;
else if (op inside {VFREDOSUM, VFWREDOSUM})
next_mfpu_state = OSUM_REDUCTION;
else
next_mfpu_state = NO_REDUCTION;
endfunction : next_mfpu_state
// Deactivate all masked or position disabled elements
function automatic elen_t processed_red_operand(elen_t mfpu_operand, logic is_masked, strb_t mask, logic [3:0] issue_element_cnt, elen_t ntr_val);
automatic strb_t pos_mask = be(issue_element_cnt, vinsn_issue_q.vtype.vsew);
for (int i=0; i<8; i++)
processed_red_operand[8*i +: 8] = ((~is_masked | mask[i]) & pos_mask[i]) ? mfpu_operand[8*i +: 8] : ntr_val[8*i +: 8];
endfunction : processed_red_operand
// This function returns the element pointed by the osum_issue_cnt
// For EW16, the positions of the elements in one 64-bit data are as follows:
// e12 | e4 | e8 | e0
// [63:48] | [47:32] | [31:16] | [15:0]
function automatic elen_t processed_osum_operand(elen_t mfpu_operand, logic [2:0] osum_issue_cnt, vew_e ew, logic is_masked, strb_t mask, elen_t ntr_val);
case (ew)
EW8: if (RVVB(FPUSupport) || RVVBA(FPUSupport)) begin
case (osum_issue_cnt)
4'd0: processed_osum_operand = (is_masked & ~mask[0]) ? {56'd0, ntr_val[7:0] } : {56'd0, mfpu_operand[7:0] };
4'd1: processed_osum_operand = (is_masked & ~mask[4]) ? {56'd0, ntr_val[39:32]} : {56'd0, mfpu_operand[39:32]};
4'd2: processed_osum_operand = (is_masked & ~mask[2]) ? {56'd0, ntr_val[23:16]} : {56'd0, mfpu_operand[23:16]};
4'd3: processed_osum_operand = (is_masked & ~mask[6]) ? {56'd0, ntr_val[55:48]} : {56'd0, mfpu_operand[55:48]};
4'd4: processed_osum_operand = (is_masked & ~mask[1]) ? {56'd0, ntr_val[15:8] } : {56'd0, mfpu_operand[15:8] };
4'd5: processed_osum_operand = (is_masked & ~mask[5]) ? {56'd0, ntr_val[47:40]} : {56'd0, mfpu_operand[47:40]};
4'd6: processed_osum_operand = (is_masked & ~mask[3]) ? {56'd0, ntr_val[31:24]} : {56'd0, mfpu_operand[31:24]};
4'd7: processed_osum_operand = (is_masked & ~mask[7]) ? {56'd0, ntr_val[63:56]} : {56'd0, mfpu_operand[63:56]};
// Default case, no meaning
default: processed_osum_operand = (is_masked & ~mask[7]) ? {56'd0, ntr_val[63:56]} : {56'd0, mfpu_operand[63:56]};
endcase
end
EW16: begin
case (osum_issue_cnt)
4'd0: processed_osum_operand = (is_masked & ~mask[0]) ? {48'd0, ntr_val[15:0] } : {48'd0, mfpu_operand[15:0] };
4'd1: processed_osum_operand = (is_masked & ~mask[4]) ? {48'd0, ntr_val[47:32]} : {48'd0, mfpu_operand[47:32]};
4'd2: processed_osum_operand = (is_masked & ~mask[2]) ? {48'd0, ntr_val[31:16]} : {48'd0, mfpu_operand[31:16]};
4'd3: processed_osum_operand = (is_masked & ~mask[6]) ? {48'd0, ntr_val[63:48]} : {48'd0, mfpu_operand[63:48]};
// Default case, no meaning
default: processed_osum_operand = (is_masked & ~mask[6]) ? {48'd0, ntr_val[63:48]} : {48'd0, mfpu_operand[63:48]};
endcase
end
EW32: begin
case (osum_issue_cnt)
4'd0: processed_osum_operand = (is_masked & ~mask[0]) ? {32'd0, ntr_val[31:0]} : {32'd0, mfpu_operand[31:0] };
4'd1: processed_osum_operand = (is_masked & ~mask[4]) ? {32'd0, ntr_val[31:0]} : {32'd0, mfpu_operand[63:32]};
// Default case, no meaning
default: processed_osum_operand = (is_masked & ~mask[4]) ? {32'd0, ntr_val[31:0]} : {32'd0, mfpu_operand[63:32]};
endcase
end
//EW32: processed_osum_operand = (is_masked & ~mask[osum_issue_cnt * 4]) ?
// {32'd0, ntr_val[osum_issue_cnt * 32 +: 31]} :
// {32'd0, mfpu_operand[osum_issue_cnt * 32 +: 31]};
EW64: processed_osum_operand = (is_masked & ~mask[0]) ? ntr_val : mfpu_operand;
default:;
endcase
endfunction : processed_osum_operand
// Use this function to assign a counter value to each lane if you can use in-lane parameters with your flow
function automatic reduction_rx_cnt_t reduction_rx_cnt_init(int unsigned NrLanes, logic [3:0] lane_id);
// The even lanes do not receive intermediate results. Only Lane 0 will receive the final result, but this is not checked here.
case (lane_id)
0: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
1: reduction_rx_cnt_init = reduction_rx_cnt_t'(1);
2: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
3: reduction_rx_cnt_init = reduction_rx_cnt_t'(2);
4: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
5: reduction_rx_cnt_init = reduction_rx_cnt_t'(1);
6: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
7: reduction_rx_cnt_init = reduction_rx_cnt_t'(3);
8: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
9: reduction_rx_cnt_init = reduction_rx_cnt_t'(1);
10: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
11: reduction_rx_cnt_init = reduction_rx_cnt_t'(2);
12: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
13: reduction_rx_cnt_init = reduction_rx_cnt_t'(1);
14: reduction_rx_cnt_init = reduction_rx_cnt_t'(0);
15: reduction_rx_cnt_init = reduction_rx_cnt_t'(4);
endcase
endfunction: reduction_rx_cnt_init
////////////////////////////////
// Floating-point conversion //
////////////////////////////////
logic [$clog2(fp_mantissa_bits(EW8, 0))-1:0] fp8_m_lzc[4]; // 2 bits each
logic [$clog2(fp_mantissa_bits(EW16, 0))-1:0] fp16_m_lzc[2]; // 4 bits each
logic [$clog2(fp_mantissa_bits(EW32, 0))-1:0] fp32_m_lzc; // 5 bits each
fp8_t fp8[4];
fp16_t fp16[2];
fp32_t fp32;
// To convert subnormal numbers to normalized form in floating-point numbers,
// it is necessary to determine the number of leading zeros in the mantissa.
// This is typically accomplished using a lzc (leading zero count) module,
// which can accurately count the number of leading zeros in a given number.
// By knowing the number of leading zeros in the mantissa, we can properly
// adjust the exponent and shift the binary point to achieve a normalized
// representation of the number.
if ({RVVB(FPUSupport), RVVH(FPUSupport)} == 2'b11) begin
// sew: 8-bit
for (genvar i = 0; i < 4; i++) begin
lzc #(
.WIDTH(fp_mantissa_bits(EW8, 0)),
.MODE (1)
) leading_zero_e8_i (
.in_i (fp8[i].m ),
.cnt_o (fp8_m_lzc[i]),
.empty_o(/*Unused*/ )
);
end
end
if ({RVVH(FPUSupport), RVVF(FPUSupport)} == 2'b11) begin
// sew: 16-bit
for (genvar i = 0; i < 2; i++) begin
lzc #(
.WIDTH(fp_mantissa_bits(EW16, 0)),
.MODE (1)
) leading_zero_e16_i (
.in_i (fp16[i].m ),
.cnt_o (fp16_m_lzc[i]),
.empty_o(/*Unused*/ )
);
end
end
if ({RVVF(FPUSupport), RVVD(FPUSupport)} == 2'b11) begin
// sew: 32-bit
lzc #(
.WIDTH(fp_mantissa_bits(EW32, 0)),
.MODE (1)
) leading_zero_e32 (
.in_i (fp32.m ),
.cnt_o (fp32_m_lzc),
.empty_o(/*Unused*/)
);
end
///////////
// FPU //
///////////
// FPU-related signals
elen_t vfpu_result, vfpu_processed_result;
status_t vfpu_ex_flag, vfpu_ex_flag_fn;
strb_t vfpu_mask;
logic vfpu_in_valid;
logic vfpu_out_valid;
logic vfpu_in_ready;
logic vfpu_out_ready;
logic fflags_ex_valid_d, fflags_ex_valid_q;
logic [4:0] fflags_ex_d, fflags_ex_q;
// In floating-point comparisons the tag is used as mask,
// In unordered reductions the tag is used as ntr indicator.
// 0: no neutral value,
// 1: only one of the operands is neutral value,
// 2: both operands are neutral values
strb_t vfpu_tag_in, vfpu_tag_out;
assign vfpu_mask = vfpu_tag_out;
// neutral value for Intraline reduction optimization
elen_t ntr_val;
// FPU preprocessed signals
elen_t operand_a;
elen_t operand_b;
elen_t operand_c;
// fp_sign is used in control block
logic [2:0] fp_sign;
// Is the FPU enabled?
if (FPUSupport != FPUSupportNone) begin : fpu_gen
// Features (enabled formats, vectors etc.)
localparam fpu_features_t FPUFeatures = '{
Width : 64,
EnableVectors: 1'b1,
EnableNanBox : 1'b1,
FpFmtMask : {RVVF(FPUSupport), RVVD(FPUSupport), RVVH(FPUSupport), RVVB(FPUSupport), RVVHA(FPUSupport), RVVBA(FPUSupport)},
IntFmtMask : {logic'(RVVB(FPUSupport) || RVVBA(FPUSupport)), 1'b1, 1'b1, 1'b1}
};
// Implementation (number of registers etc)
localparam fpu_implementation_t FPUImplementation = '{
PipeRegs: '{
'{LatFCompEW32, LatFCompEW64, LatFCompEW16, LatFCompEW8, LatFCompEW16Alt, LatFCompEW8Alt},
'{default: LatFDivSqrt},
'{default: LatFNonComp},
'{default: LatFConv},
'{default: LatFDotp}},
UnitTypes: '{
'{default: PARALLEL}, // ADDMUL
'{default: MERGED}, // DIVSQRT
'{default: PARALLEL}, // NONCOMP
'{default: MERGED}, // CONV
'{default: DISABLED}}, // DOTP
PipeConfig: DISTRIBUTED
};
// Don't compress classify result
localparam int unsigned TrueSIMDClass = 1;
localparam int unsigned EnableSIMDMask = 1;
localparam fpnew_pkg::divsqrt_unit_t DivSqrtSel = fpnew_pkg::PULP;
operation_e fp_op;
logic fp_opmod;
fp_format_e fp_src_fmt, fp_dst_fmt;
int_format_e fp_int_fmt;
roundmode_e fp_rm;
// FPU preprocessing stage
always_comb begin: fpu_operand_preprocessing_p
// Default rounding-mode from fcsr.rm
fp_rm = vinsn_issue_q.fp_rm;
fp_op = ADD;
fp_opmod = 1'b0;
fp_src_fmt = FP64;
fp_dst_fmt = FP64;
fp_int_fmt = INT64;
fp_sign = 3'b0;
// Default neutral value
ntr_val = '0;
unique case (vinsn_issue_q.op)
// Addition is between operands B and C, A was moved to C in the lane_sequencer
VFADD: fp_op = ADD;
VFSUB: begin
fp_op = ADD;
fp_sign[1] = 1'b1;
end
VFRSUB: begin
fp_op = ADD;
fp_opmod = 1'b1;
end
VFMUL : fp_op = MUL;
VFDIV,
VFRDIV: fp_op = DIV;
VFSQRT: fp_op = SQRT;
VFMACC,
VFMADD,
VFMSAC,
VFMSUB: begin
fp_op = FMADD;
fp_sign[2] = (vinsn_issue_q.op == VFMSAC) | (vinsn_issue_q.op == VFMSUB);
end
VFNMACC,
VFNMSAC,
VFNMADD,
VFNMSUB: begin
fp_op = FNMSUB;
fp_sign[2] = (vinsn_issue_q.op == VFNMACC) | (vinsn_issue_q.op == VFNMADD);
end
VFMIN: begin
fp_op = MINMAX;
fp_rm = RNE;
end
VFMAX: begin
fp_op = MINMAX;
fp_rm = RTZ;
end
VFCLASS,
VFREC7,
VFRSQRT7: begin
fp_op = CLASSIFY;
end
VFSGNJ : begin
fp_op = SGNJ;
fp_rm = RNE;
end
VFSGNJN : begin
fp_op = SGNJ;
fp_rm = RTZ;
end
VFSGNJX : begin
fp_op = SGNJ;
fp_rm = RDN;
end
VMFEQ, VMFNE: begin
fp_op = CMP;
fp_rm = RDN;
end
VMFLE: begin
fp_op = CMP;
fp_rm = RNE;
end
VMFLT: begin
fp_op = CMP;
fp_rm = RTZ;
end
VMFGT: begin
fp_sign[0] = 1'b1;
fp_sign[1] = 1'b1;
fp_op = CMP;
fp_rm = RTZ;
end
VMFGE: begin
fp_sign[0] = 1'b1;
fp_sign[1] = 1'b1;
fp_op = CMP;
fp_rm = RNE;
end
VFCVTXUF: begin
fp_op = F2I;
fp_opmod = 1'b1;
end
VFCVTXF: begin
fp_op = F2I;
fp_opmod = 1'b0;
end
VFCVTFXU: begin
fp_op = I2F;
fp_opmod = 1'b1;
end
VFCVTFX: begin
fp_op = I2F;
fp_opmod = 1'b0;
end
VFCVTRTZXUF: begin
fp_op = F2I;
fp_opmod = 1'b1;
fp_rm = RTZ;
end
VFCVTRTZXF: begin