Skip to content

Commit aaba840

Browse files
[NFC][Clang][AArch64]Refactor implementation of Neon vectors MFloat8… (#114804)
…x8 and MFloat8x16 This patch adds MFloat8 as a TypeFlag and Kind on Neon to generate the typedefs using emitNeonTypeDefs. It does not need any change in Clang, because SEMA and CodeGen use the Builtins defined in AArch64SVEACLETypes.def
1 parent ef102b4 commit aaba840

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

clang/include/clang/Basic/arm_neon_incl.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def OP_UNAVAILABLE : Operation {
218218
// h: half-float
219219
// d: double
220220
// b: bfloat16
221+
// m: mfloat8
221222
//
222223
// Typespec modifiers
223224
// ------------------

clang/utils/TableGen/NeonEmitter.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ enum EltType {
101101
Float16,
102102
Float32,
103103
Float64,
104-
BFloat16
104+
BFloat16,
105+
MFloat8 // Not used by Sema or CodeGen in Clang
105106
};
106107

107108
} // end namespace NeonTypeFlags
@@ -143,14 +144,7 @@ class Type {
143144
private:
144145
TypeSpec TS;
145146

146-
enum TypeKind {
147-
Void,
148-
Float,
149-
SInt,
150-
UInt,
151-
Poly,
152-
BFloat16
153-
};
147+
enum TypeKind { Void, Float, SInt, UInt, Poly, BFloat16, MFloat8 };
154148
TypeKind Kind;
155149
bool Immediate, Constant, Pointer;
156150
// ScalarForMangling and NoManglingQ are really not suited to live here as
@@ -203,6 +197,7 @@ class Type {
203197
bool isLong() const { return isInteger() && ElementBitwidth == 64; }
204198
bool isVoid() const { return Kind == Void; }
205199
bool isBFloat16() const { return Kind == BFloat16; }
200+
bool isMFloat8() const { return Kind == MFloat8; }
206201
unsigned getNumElements() const { return Bitwidth / ElementBitwidth; }
207202
unsigned getSizeInBits() const { return Bitwidth; }
208203
unsigned getElementSizeInBits() const { return ElementBitwidth; }
@@ -657,6 +652,8 @@ std::string Type::str() const {
657652
S += "float";
658653
else if (isBFloat16())
659654
S += "bfloat";
655+
else if (isMFloat8())
656+
S += "mfloat";
660657
else
661658
S += "int";
662659

@@ -699,6 +696,9 @@ std::string Type::builtin_str() const {
699696
else if (isBFloat16()) {
700697
assert(ElementBitwidth == 16 && "BFloat16 can only be 16 bits");
701698
S += "y";
699+
} else if (isMFloat8()) {
700+
assert(ElementBitwidth == 8 && "MFloat8 can only be 8 bits");
701+
S += "m";
702702
} else
703703
switch (ElementBitwidth) {
704704
case 16: S += "h"; break;
@@ -758,6 +758,10 @@ unsigned Type::getNeonEnum() const {
758758
Base = (unsigned)NeonTypeFlags::BFloat16;
759759
}
760760

761+
if (isMFloat8()) {
762+
Base = (unsigned)NeonTypeFlags::MFloat8;
763+
}
764+
761765
if (Bitwidth == 128)
762766
Base |= (unsigned)NeonTypeFlags::QuadFlag;
763767
if (isInteger() && !isSigned())
@@ -779,6 +783,8 @@ Type Type::fromTypedefName(StringRef Name) {
779783
T.Kind = Poly;
780784
} else if (Name.consume_front("bfloat")) {
781785
T.Kind = BFloat16;
786+
} else if (Name.consume_front("mfloat")) {
787+
T.Kind = MFloat8;
782788
} else {
783789
assert(Name.starts_with("int"));
784790
Name = Name.drop_front(3);
@@ -879,6 +885,10 @@ void Type::applyTypespec(bool &Quad) {
879885
Kind = BFloat16;
880886
ElementBitwidth = 16;
881887
break;
888+
case 'm':
889+
Kind = MFloat8;
890+
ElementBitwidth = 8;
891+
break;
882892
default:
883893
llvm_unreachable("Unhandled type code!");
884894
}
@@ -993,6 +1003,9 @@ std::string Intrinsic::getInstTypeCode(Type T, ClassKind CK) const {
9931003
if (T.isBFloat16())
9941004
return "bf16";
9951005

1006+
if (T.isMFloat8())
1007+
return "mfp8";
1008+
9961009
if (T.isPoly())
9971010
typeCode = 'p';
9981011
else if (T.isInteger())
@@ -1030,7 +1043,7 @@ std::string Intrinsic::getBuiltinTypeStr() {
10301043

10311044
Type RetT = getReturnType();
10321045
if ((LocalCK == ClassI || LocalCK == ClassW) && RetT.isScalar() &&
1033-
!RetT.isFloating() && !RetT.isBFloat16())
1046+
!RetT.isFloating() && !RetT.isBFloat16() && !RetT.isMFloat8())
10341047
RetT.makeInteger(RetT.getElementSizeInBits(), false);
10351048

10361049
// Since the return value must be one type, return a vector type of the
@@ -2270,7 +2283,7 @@ static void emitNeonTypeDefs(const std::string& types, raw_ostream &OS) {
22702283
for (auto &TS : TDTypeVec) {
22712284
bool IsA64 = false;
22722285
Type T(TS, ".");
2273-
if (T.isDouble())
2286+
if (T.isDouble() || T.isMFloat8())
22742287
IsA64 = true;
22752288

22762289
if (InIfdef && !IsA64) {
@@ -2282,15 +2295,20 @@ static void emitNeonTypeDefs(const std::string& types, raw_ostream &OS) {
22822295
InIfdef = true;
22832296
}
22842297

2285-
if (T.isPoly())
2298+
if (T.isMFloat8())
2299+
OS << "typedef __MFloat8x";
2300+
else if (T.isPoly())
22862301
OS << "typedef __attribute__((neon_polyvector_type(";
22872302
else
22882303
OS << "typedef __attribute__((neon_vector_type(";
22892304

22902305
Type T2 = T;
22912306
T2.makeScalar();
2292-
OS << T.getNumElements() << "))) ";
2293-
OS << T2.str();
2307+
OS << T.getNumElements();
2308+
if (T.isMFloat8())
2309+
OS << "_t ";
2310+
else
2311+
OS << "))) " << T2.str();
22942312
OS << " " << T.str() << ";\n";
22952313
}
22962314
if (InIfdef)
@@ -2303,7 +2321,7 @@ static void emitNeonTypeDefs(const std::string& types, raw_ostream &OS) {
23032321
for (auto &TS : TDTypeVec) {
23042322
bool IsA64 = false;
23052323
Type T(TS, ".");
2306-
if (T.isDouble())
2324+
if (T.isDouble() || T.isMFloat8())
23072325
IsA64 = true;
23082326

23092327
if (InIfdef && !IsA64) {
@@ -2589,8 +2607,6 @@ void NeonEmitter::runVectorTypes(raw_ostream &OS) {
25892607

25902608
OS << "#if defined(__aarch64__) || defined(__arm64ec__)\n";
25912609
OS << "typedef __mfp8 mfloat8_t;\n";
2592-
OS << "typedef __MFloat8x8_t mfloat8x8_t;\n";
2593-
OS << "typedef __MFloat8x16_t mfloat8x16_t;\n";
25942610
OS << "typedef double float64_t;\n";
25952611
OS << "#endif\n\n";
25962612

@@ -2648,7 +2664,7 @@ __arm_set_fpm_lscale2(fpm_t __fpm, uint64_t __scale) {
26482664
26492665
)";
26502666

2651-
emitNeonTypeDefs("cQcsQsiQilQlUcQUcUsQUsUiQUiUlQUlhQhfQfdQd", OS);
2667+
emitNeonTypeDefs("cQcsQsiQilQlUcQUcUsQUsUiQUiUlQUlmQmhQhfQfdQd", OS);
26522668

26532669
emitNeonTypeDefs("bQb", OS);
26542670
OS << "#endif // __ARM_NEON_TYPES_H\n";

0 commit comments

Comments
 (0)