Skip to content

Commit 66c0560

Browse files
committed
[RISCV][Clang] Add some RVV Integer intrinsic functions.
1. Rename RVVBinBuiltin to RVVOutputOp1Builtin because it is not related to the number of operand. 2. Add RVV Integer instuctions which use RVVOutputOp1Builtin. Reviewed By: craig.topper Authored-by: Roger Ferrer Ibanez <[email protected]> Co-Authored-by: Zakk Chen <[email protected]> Differential Revision: https://reviews.llvm.org/D99524
1 parent f8f4d8f commit 66c0560

35 files changed

+84172
-17
lines changed

clang/include/clang/Basic/riscv_vector.td

Lines changed: 122 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,58 @@ class RVVBuiltin<string suffix, string prototype, string type_range,
200200
// Basic classes with automatic codegen.
201201
//===----------------------------------------------------------------------===//
202202

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 {
211208
foreach s_p = suffixes_prototypes in {
212209
let Name = NAME # "_" # s_p[0] in {
213210
defvar suffix = s_p[1];
214211
defvar prototype = s_p[2];
215-
def : RVVBinBuiltin<suffix, prototype, type_range>;
212+
def : RVVBuiltin<suffix, prototype, type_range>;
216213
}
217214
}
218215
}
219216
}
220217

218+
// IntrinsicTypes is output, op1 [-1, 1]
219+
multiclass RVVOutOp1BuiltinSet<string intrinsic_name, string type_range,
220+
list<list<string>> suffixes_prototypes> {
221+
defm "" : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 1]>;
222+
}
223+
224+
multiclass RVVSignedBinBuiltinSet {
225+
defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
226+
[["vv", "v", "vvv"],
227+
["vx", "v", "vve"]]>;
228+
}
229+
230+
multiclass RVVUnsignedBinBuiltinSet {
231+
defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
232+
[["vv", "Uv", "UvUvUv"],
233+
["vx", "Uv", "UvUvUe"]]>;
234+
}
235+
236+
multiclass RVVIntBinBuiltinSet {
237+
defm "" : RVVSignedBinBuiltinSet;
238+
defm "" : RVVUnsignedBinBuiltinSet;
239+
}
240+
241+
multiclass RVVIntTerBuiltinSet {
242+
defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
243+
[["vv", "v", "vvvv"],
244+
["vx", "v", "vvev"],
245+
["vv", "Uv", "UvUvUvUv"],
246+
["vx", "Uv", "UvUvUeUv"]]>;
247+
}
248+
249+
multiclass RVVFloatingBinBuiltinSet {
250+
defm "" : RVVOutOp1BuiltinSet<NAME, "fd",
251+
[["vv", "v", "vvv"],
252+
["vf", "v", "vve"]]>;
253+
}
254+
221255
defvar TypeList = ["c","s","i","l","f","d"];
222256
defvar EEWList = [["8", "(Log2EEW:3)"],
223257
["16", "(Log2EEW:4)"],
@@ -387,14 +421,85 @@ defm : RVVIndexedLoad<"vloxei">;
387421

388422
// 12. Vector Integer Arithmetic Instructions
389423
// 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"]]>;
424+
defm vadd : RVVIntBinBuiltinSet;
425+
defm vsub : RVVIntBinBuiltinSet;
426+
defm vrsub : RVVOutOp1BuiltinSet<"vrsub", "csil",
427+
[["vx", "v", "vve"],
428+
["vx", "Uv", "UvUvUe"]]>;
429+
430+
// 12.2. Vector Widening Integer Add/Subtract
431+
// TODO
432+
433+
// 12.3. Vector Integer Extension
434+
// TODO
435+
436+
// 12.4. Vector Integer Add-with-Carry / Subtract-with-Borrow Instructions
437+
// TODO
438+
439+
// 12.5. Vector Bitwise Logical Instructions
440+
defm vand : RVVIntBinBuiltinSet;
441+
defm vxor : RVVIntBinBuiltinSet;
442+
defm vor : RVVIntBinBuiltinSet;
443+
444+
// 12.6. Vector Single-Width Bit Shift Instructions
445+
defm vsll : RVVOutOp1BuiltinSet<"vsll", "csil",
446+
[["vv", "v", "vvUv"],
447+
["vx", "v", "vvz"],
448+
["vv", "Uv", "UvUvUv"],
449+
["vx", "Uv", "UvUvz"]]>;
450+
defm vsrl : RVVOutOp1BuiltinSet<"vsrl", "csil",
451+
[["vv", "Uv", "UvUvUv"],
452+
["vx", "Uv", "UvUvz"]]>;
453+
defm vsra : RVVOutOp1BuiltinSet<"vsra", "csil",
454+
[["vv", "v", "vvUv"],
455+
["vx", "v", "vvz"]]>;
456+
457+
// 12.7. Vector Narrowing Integer Right Shift Instructions
458+
// TODO
459+
460+
// 12.8. Vector Integer Comparison Instructions
461+
// TODO
462+
463+
// 12.9. Vector Integer Min/Max Instructions
464+
defm vminu : RVVUnsignedBinBuiltinSet;
465+
defm vmin : RVVSignedBinBuiltinSet;
466+
defm vmaxu : RVVUnsignedBinBuiltinSet;
467+
defm vmax : RVVSignedBinBuiltinSet;
468+
469+
// 12.10. Vector Single-Width Integer Multiply Instructions
470+
defm vmul : RVVIntBinBuiltinSet;
471+
defm vmulh : RVVSignedBinBuiltinSet;
472+
defm vmulhu : RVVUnsignedBinBuiltinSet;
473+
defm vmulhsu : RVVOutOp1BuiltinSet<"vmulhsu", "csil",
474+
[["vv", "v", "vvUv"],
475+
["vx", "v", "vvUe"]]>;
476+
477+
// 12.11. Vector Integer Divide Instructions
478+
defm vdivu : RVVUnsignedBinBuiltinSet;
479+
defm vdiv : RVVSignedBinBuiltinSet;
480+
defm vremu : RVVUnsignedBinBuiltinSet;
481+
defm vrem : RVVSignedBinBuiltinSet;
482+
483+
// 12.12. Vector Widening Integer Multiply Instructions
484+
// TODO
485+
486+
// 12.13. Vector Single-Width Integer Multiply-Add Instructions
487+
let HasMaskedOffOperand = false in {
488+
defm vmacc : RVVIntTerBuiltinSet;
489+
defm vnmsac : RVVIntTerBuiltinSet;
490+
defm vmadd : RVVIntTerBuiltinSet;
491+
defm vnmsub : RVVIntTerBuiltinSet;
492+
}
493+
494+
// 12.14. Vector Widening Integer Multiply-Add Instructions
495+
// TODO
496+
497+
// 12.15. Vector Integer Merge Instructions
498+
// TODO
499+
500+
// 12.16. Vector Integer Move Instructions
501+
// TODO
395502

396503
// 14. Vector Floating-Point Instructions
397504
// 14.2. Vector Single-Width Floating-Point Add/Subtract Instructions
398-
defm vfadd : RVVBinBuiltinSet<"vfadd", "fd",
399-
[["vv", "v", "vvv"],
400-
["vf", "v", "vve"]]>;
505+
defm vfadd : RVVFloatingBinBuiltinSet;

0 commit comments

Comments
 (0)