@@ -200,24 +200,146 @@ class RVVBuiltin<string suffix, string prototype, string type_range,
200
200
// Basic classes with automatic codegen.
201
201
//===----------------------------------------------------------------------===//
202
202
203
- class RVVBinBuiltin<string suffix, string prototype, string type_range>
204
- : RVVBuiltin<suffix, prototype, type_range> {
205
- let IntrinsicTypes = [-1, 1];
206
- }
207
-
208
- multiclass RVVBinBuiltinSet<string intrinsic_name, string type_range,
209
- list<list<string>> suffixes_prototypes> {
210
- let IRName = intrinsic_name, IRNameMask = intrinsic_name # "_mask" in {
203
+ multiclass RVVBuiltinSet<string intrinsic_name, string type_range,
204
+ list<list<string>> suffixes_prototypes,
205
+ list<int> intrinsic_types> {
206
+ let IRName = intrinsic_name, IRNameMask = intrinsic_name # "_mask",
207
+ IntrinsicTypes = intrinsic_types in {
211
208
foreach s_p = suffixes_prototypes in {
212
209
let Name = NAME # "_" # s_p[0] in {
213
210
defvar suffix = s_p[1];
214
211
defvar prototype = s_p[2];
215
- def : RVVBinBuiltin <suffix, prototype, type_range>;
212
+ def : RVVBuiltin <suffix, prototype, type_range>;
216
213
}
217
214
}
218
215
}
219
216
}
220
217
218
+ // IntrinsicTypes is output, op0, op1 [-1, 0, 1]
219
+ multiclass RVVOutOp0Op1BuiltinSet<string intrinsic_name, string type_range,
220
+ list<list<string>> suffixes_prototypes> {
221
+ defm NAME : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes,
222
+ [-1, 0, 1]>;
223
+ }
224
+
225
+ // IntrinsicTypes is output, op1 [-1, 1]
226
+ multiclass RVVOutOp1BuiltinSet<string intrinsic_name, string type_range,
227
+ list<list<string>> suffixes_prototypes> {
228
+ defm "" : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 1]>;
229
+ }
230
+
231
+ multiclass RVVOp0Op1BuiltinSet<string intrinsic_name, string type_range,
232
+ list<list<string>> suffixes_prototypes> {
233
+ defm "" : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [0, 1]>;
234
+ }
235
+
236
+ multiclass RVVOutOp1Op2BuiltinSet<string intrinsic_name, string type_range,
237
+ list<list<string>> suffixes_prototypes> {
238
+ defm "" : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 1, 2]>;
239
+ }
240
+
241
+ multiclass RVVSignedBinBuiltinSet {
242
+ defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
243
+ [["vv", "v", "vvv"],
244
+ ["vx", "v", "vve"]]>;
245
+ }
246
+
247
+ multiclass RVVUnsignedBinBuiltinSet {
248
+ defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
249
+ [["vv", "Uv", "UvUvUv"],
250
+ ["vx", "Uv", "UvUvUe"]]>;
251
+ }
252
+
253
+ multiclass RVVIntBinBuiltinSet {
254
+ defm "" : RVVSignedBinBuiltinSet;
255
+ defm "" : RVVUnsignedBinBuiltinSet;
256
+ }
257
+
258
+ multiclass RVVSignedShiftBuiltinSet {
259
+ defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
260
+ [["vv", "v", "vvUv"],
261
+ ["vx", "v", "vvz"]]>;
262
+ }
263
+
264
+ multiclass RVVUnsignedShiftBuiltinSet {
265
+ defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
266
+ [["vv", "Uv", "UvUvUv"],
267
+ ["vx", "Uv", "UvUvz"]]>;
268
+ }
269
+
270
+ multiclass RVVShiftBuiltinSet {
271
+ defm "" : RVVSignedShiftBuiltinSet;
272
+ defm "" : RVVUnsignedShiftBuiltinSet;
273
+ }
274
+
275
+ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
276
+ multiclass RVVSignedNShiftBuiltinSet {
277
+ defm "" : RVVOutOp0Op1BuiltinSet<NAME, "csil",
278
+ [["wv", "v", "vwUv"],
279
+ ["wx", "v", "vwz"]]>;
280
+ }
281
+ multiclass RVVUnsignedNShiftBuiltinSet {
282
+ defm "" : RVVOutOp0Op1BuiltinSet<NAME, "csil",
283
+ [["wv", "Uv", "UvUwUv"],
284
+ ["wx", "Uv", "UvUwz"]]>;
285
+ }
286
+ }
287
+
288
+ multiclass RVVIntTerBuiltinSet {
289
+ defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
290
+ [["vv", "v", "vvvv"],
291
+ ["vx", "v", "vvev"],
292
+ ["vv", "Uv", "UvUvUvUv"],
293
+ ["vx", "Uv", "UvUvUeUv"]]>;
294
+ }
295
+
296
+ multiclass RVVCarryinBuiltinSet {
297
+ defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
298
+ [["vvm", "v", "vvvm"],
299
+ ["vxm", "v", "vvem"],
300
+ ["vvm", "Uv", "UvUvUvm"],
301
+ ["vxm", "Uv", "UvUvUem"]]>;
302
+ }
303
+
304
+ multiclass RVVCarryOutInBuiltinSet<string intrinsic_name> {
305
+ defm "" : RVVOp0Op1BuiltinSet<intrinsic_name, "csil",
306
+ [["vvm", "vm", "mvvm"],
307
+ ["vxm", "vm", "mvem"],
308
+ ["vvm", "Uvm", "mUvUvm"],
309
+ ["vxm", "Uvm", "mUvUem"]]>;
310
+ }
311
+
312
+ multiclass RVVSignedMaskOutBuiltinSet {
313
+ defm "" : RVVOp0Op1BuiltinSet<NAME, "csil",
314
+ [["vv", "vm", "mvv"],
315
+ ["vx", "vm", "mve"]]>;
316
+ }
317
+
318
+ multiclass RVVUnsignedMaskOutBuiltinSet {
319
+ defm "" : RVVOp0Op1BuiltinSet<NAME, "csil",
320
+ [["vv", "Uvm", "mUvUv"],
321
+ ["vx", "Uvm", "mUvUe"]]>;
322
+ }
323
+
324
+ multiclass RVVIntMaskOutBuiltinSet {
325
+ defm "" : RVVSignedMaskOutBuiltinSet;
326
+ defm "" : RVVUnsignedMaskOutBuiltinSet;
327
+ }
328
+
329
+ multiclass RVVFloatingBinBuiltinSet {
330
+ defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
331
+ [["vv", "v", "vvv"],
332
+ ["vf", "v", "vve"]]>;
333
+ }
334
+
335
+ multiclass RVVIntExt<string intrinsic_name, string suffix, string prototype,
336
+ string type_range> {
337
+ let IRName = intrinsic_name, IRNameMask = intrinsic_name # "_mask",
338
+ MangledName = NAME, IntrinsicTypes = [-1, 0] in {
339
+ def "" : RVVBuiltin<suffix, prototype, type_range>;
340
+ }
341
+ }
342
+
221
343
defvar TypeList = ["c","s","i","l","f","d"];
222
344
defvar EEWList = [["8", "(Log2EEW:3)"],
223
345
["16", "(Log2EEW:4)"],
@@ -387,14 +509,152 @@ defm : RVVIndexedLoad<"vloxei">;
387
509
388
510
// 12. Vector Integer Arithmetic Instructions
389
511
// 12.1. Vector Single-Width Integer Add and Subtract
390
- defm vadd : RVVBinBuiltinSet<"vadd", "csil",
391
- [["vv", "v", "vvv"],
392
- ["vx", "v", "vve"],
393
- ["vv", "Uv", "UvUvUv"],
394
- ["vx", "Uv", "UvUvUe"]]>;
512
+ defm vadd : RVVIntBinBuiltinSet;
513
+ defm vsub : RVVIntBinBuiltinSet;
514
+ defm vrsub : RVVOutOp1BuiltinSet<"vrsub", "csil",
515
+ [["vx", "v", "vve"],
516
+ ["vx", "Uv", "UvUvUe"]]>;
517
+
518
+ // 12.2. Vector Widening Integer Add/Subtract
519
+ // TODO
520
+
521
+ // 12.3. Vector Integer Extension
522
+ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
523
+ defm vsext_vf2 : RVVIntExt<"vsext", "w", "wv", "csi">;
524
+ defm vzext_vf2 : RVVIntExt<"vzext", "Uw", "UwUv", "csi">;
525
+ }
526
+ let Log2LMUL = [-3, -2, -1, 0, 1] in {
527
+ defm vsext_vf4 : RVVIntExt<"vsext", "q", "qv", "cs">;
528
+ defm vzext_vf4 : RVVIntExt<"vzext", "Uq", "UqUv", "cs">;
529
+ }
530
+ let Log2LMUL = [-3, -2, -1, 0] in {
531
+ defm vsext_vf8 : RVVIntExt<"vsext", "o", "ov", "c">;
532
+ defm vzext_vf8 : RVVIntExt<"vzext", "Uo", "UoUv", "c">;
533
+ }
534
+
535
+ // 12.4. Vector Integer Add-with-Carry / Subtract-with-Borrow Instructions
536
+ let HasMask = false in {
537
+ defm vadc : RVVCarryinBuiltinSet;
538
+ defm vmadc : RVVCarryOutInBuiltinSet<"vmadc_carry_in">;
539
+ defm vmadc : RVVIntMaskOutBuiltinSet;
540
+ defm vsbc : RVVCarryinBuiltinSet;
541
+ defm vmsbc : RVVCarryOutInBuiltinSet<"vmsbc_borrow_in">;
542
+ defm vmsbc : RVVIntMaskOutBuiltinSet;
543
+ }
544
+
545
+ // 12.5. Vector Bitwise Logical Instructions
546
+ defm vand : RVVIntBinBuiltinSet;
547
+ defm vxor : RVVIntBinBuiltinSet;
548
+ defm vor : RVVIntBinBuiltinSet;
549
+
550
+ // 12.6. Vector Single-Width Bit Shift Instructions
551
+ defm vsll : RVVShiftBuiltinSet;
552
+ defm vsrl : RVVUnsignedShiftBuiltinSet;
553
+ defm vsra : RVVSignedShiftBuiltinSet;
554
+
555
+ // 12.7. Vector Narrowing Integer Right Shift Instructions
556
+ defm vnsrl : RVVUnsignedNShiftBuiltinSet;
557
+ defm vnsra : RVVSignedNShiftBuiltinSet;
558
+
559
+ // 12.8. Vector Integer Comparison Instructions
560
+ defm vmseq : RVVIntMaskOutBuiltinSet;
561
+ defm vmsne : RVVIntMaskOutBuiltinSet;
562
+ defm vmsltu : RVVUnsignedMaskOutBuiltinSet;
563
+ defm vmslt : RVVSignedMaskOutBuiltinSet;
564
+ defm vmsleu : RVVUnsignedMaskOutBuiltinSet;
565
+ defm vmsle : RVVSignedMaskOutBuiltinSet;
566
+ defm vmsgtu : RVVOp0Op1BuiltinSet<"vmsgtu", "csil",
567
+ [["vx", "Uvm", "mUvUe"]]>;
568
+ defm vmsgt : RVVOp0Op1BuiltinSet<"vmsgt", "csil",
569
+ [["vx", "vm", "mve"]]>;
570
+
571
+ // 12.9. Vector Integer Min/Max Instructions
572
+ defm vminu : RVVUnsignedBinBuiltinSet;
573
+ defm vmin : RVVSignedBinBuiltinSet;
574
+ defm vmaxu : RVVUnsignedBinBuiltinSet;
575
+ defm vmax : RVVSignedBinBuiltinSet;
576
+
577
+ // 12.10. Vector Single-Width Integer Multiply Instructions
578
+ defm vmul : RVVIntBinBuiltinSet;
579
+ defm vmulh : RVVSignedBinBuiltinSet;
580
+ defm vmulhu : RVVUnsignedBinBuiltinSet;
581
+ defm vmulhsu : RVVOutOp1BuiltinSet<"vmulhsu", "csil",
582
+ [["vv", "v", "vvUv"],
583
+ ["vx", "v", "vvUe"]]>;
584
+
585
+ // 12.11. Vector Integer Divide Instructions
586
+ defm vdivu : RVVUnsignedBinBuiltinSet;
587
+ defm vdiv : RVVSignedBinBuiltinSet;
588
+ defm vremu : RVVUnsignedBinBuiltinSet;
589
+ defm vrem : RVVSignedBinBuiltinSet;
590
+
591
+ // 12.12. Vector Widening Integer Multiply Instructions
592
+ let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
593
+ defm vwmul : RVVOutOp0Op1BuiltinSet<"vwmul", "csi",
594
+ [["vv", "w", "wvv"],
595
+ ["vx", "w", "wve"]]>;
596
+ defm vwmulu : RVVOutOp0Op1BuiltinSet<"vwmulu", "csi",
597
+ [["vv", "Uw", "UwUvUv"],
598
+ ["vx", "Uw", "UwUvUe"]]>;
599
+ defm vwmulsu : RVVOutOp0Op1BuiltinSet<"vwmulsu", "csi",
600
+ [["vv", "w", "wvUv"],
601
+ ["vx", "w", "wvUe"]]>;
602
+ }
603
+
604
+ // 12.13. Vector Single-Width Integer Multiply-Add Instructions
605
+ let HasMaskedOffOperand = false in {
606
+ defm vmacc : RVVIntTerBuiltinSet;
607
+ defm vnmsac : RVVIntTerBuiltinSet;
608
+ defm vmadd : RVVIntTerBuiltinSet;
609
+ defm vnmsub : RVVIntTerBuiltinSet;
610
+ }
611
+
612
+ // 12.14. Vector Widening Integer Multiply-Add Instructions
613
+ let HasMaskedOffOperand = false,
614
+ Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
615
+ defm vwmaccu : RVVOutOp1Op2BuiltinSet<"vwmaccu", "csi",
616
+ [["vv", "Uw", "UwUwUvUv"],
617
+ ["vx", "Uw", "UwUwUeUv"]]>;
618
+ defm vwmacc : RVVOutOp1Op2BuiltinSet<"vwmacc", "csi",
619
+ [["vv", "w", "wwvv"],
620
+ ["vx", "w", "wwev"]]>;
621
+ defm vwmaccsu : RVVOutOp1Op2BuiltinSet<"vwmaccsu", "csi",
622
+ [["vv", "w", "wwvUv"],
623
+ ["vx", "w", "wweUv"]]>;
624
+ defm vwmaccus : RVVOutOp1Op2BuiltinSet<"vwmaccus", "csi",
625
+ [["vx", "w", "wwUev"]]>;
626
+ }
627
+
628
+ // 12.15. Vector Integer Merge Instructions
629
+ // TODO
630
+
631
+ // 12.16. Vector Integer Move Instructions
632
+ // TODO
633
+
634
+ // 13. Vector Fixed-Point Arithmetic Instructions
635
+ // 13.1. Vector Single-Width Saturating Add and Subtract
636
+ defm vsaddu : RVVUnsignedBinBuiltinSet;
637
+ defm vsadd : RVVSignedBinBuiltinSet;
638
+ defm vssubu : RVVUnsignedBinBuiltinSet;
639
+ defm vssub : RVVSignedBinBuiltinSet;
640
+
641
+ // 13.2. Vector Single-Width Averaging Add and Subtract
642
+ defm vaaddu : RVVUnsignedBinBuiltinSet;
643
+ defm vaadd : RVVSignedBinBuiltinSet;
644
+ defm vasubu : RVVUnsignedBinBuiltinSet;
645
+ defm vasub : RVVSignedBinBuiltinSet;
646
+
647
+ // 13.3. Vector Single-Width Fractional Multiply with Rounding and Saturation
648
+ defm vsmul : RVVSignedBinBuiltinSet;
649
+
650
+ // 13.4. Vector Single-Width Scaling Shift Instructions
651
+ defm vssrl : RVVUnsignedShiftBuiltinSet;
652
+ defm vssra : RVVSignedShiftBuiltinSet;
653
+
654
+ // 13.5. Vector Narrowing Fixed-Point Clip Instructions
655
+ defm vnclipu : RVVUnsignedNShiftBuiltinSet;
656
+ defm vnclip : RVVSignedNShiftBuiltinSet;
395
657
396
658
// 14. Vector Floating-Point Instructions
397
659
// 14.2. Vector Single-Width Floating-Point Add/Subtract Instructions
398
- defm vfadd : RVVBinBuiltinSet<"vfadd", "fd",
399
- [["vv", "v", "vvv"],
400
- ["vf", "v", "vve"]]>;
660
+ defm vfadd : RVVFloatingBinBuiltinSet;
0 commit comments