Skip to content

Commit de397fb

Browse files
[WIP][CLANG][AArch64] Add the modal 8 bit floating-point scalar type
ARM ACLE PR#323[1] adds new modal types for 8-bit floating point intrinsic. From the PR#323: ``` ACLE defines the `__mfp8` type, which can be used for the E5M2 and E4M3 8-bit floating-point formats. It is a storage and interchange only type with no arithmetic operations other than intrinsic calls. `mfloat8_t` | equivalent to `__mfp8` | ```` The type should be an opaque type and its format in undefined in Clang. Only defined in the backend by a status/format register, for AArch64 the FPMR. This patch is an attempt to the add the fpm8_t scalar type. It has a parser and codegen for the new scalar type. The patch it is lowering to and 8bit unsigned as it has no format. But maybe we should add another opaque type. According to ACLE[1] proposal [1] ARM-software/acle#323
1 parent 9e63632 commit de397fb

40 files changed

+269
-4
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
11151115
CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
11161116
CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
11171117
SatUnsignedLongFractTy;
1118+
CanQualType MFloat8Ty;
11181119
CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
11191120
CanQualType BFloat16Ty;
11201121
CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3

clang/include/clang/AST/BuiltinTypes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ FLOATING_TYPE(Float128, Float128Ty)
221221
// '__ibm128'
222222
FLOATING_TYPE(Ibm128, Ibm128Ty)
223223

224+
225+
// '__fpm8'
226+
UNSIGNED_TYPE(MFloat8, MFloat8Ty)
227+
224228
//===- Language-specific types --------------------------------------------===//
225229

226230
// This is the type of C++0x 'nullptr'.

clang/include/clang/AST/Type.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
24922492
bool isDoubleType() const;
24932493
bool isBFloat16Type() const;
24942494
bool isFloat128Type() const;
2495+
bool isMFloat8Type() const;
24952496
bool isIbm128Type() const;
24962497
bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
24972498
bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
@@ -7944,6 +7945,10 @@ inline bool Type::isBFloat16Type() const {
79447945
return isSpecificBuiltinType(BuiltinType::BFloat16);
79457946
}
79467947

7948+
inline bool Type::isMFloat8Type() const {
7949+
return isSpecificBuiltinType(BuiltinType::MFloat8);
7950+
}
7951+
79477952
inline bool Type::isFloat128Type() const {
79487953
return isSpecificBuiltinType(BuiltinType::Float128);
79497954
}

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7858,6 +7858,8 @@ def err_bad_lvalue_to_rvalue_cast : Error<
78587858
def err_bad_rvalue_to_rvalue_cast : Error<
78597859
"cannot cast from rvalue of type %1 to rvalue reference type %2; types are "
78607860
"not compatible">;
7861+
def err_bad_mfloat8_cast : Error<
7862+
"cannot cast %0 to %1; types are not compatible">;
78617863
def err_bad_static_cast_pointer_nonpointer : Error<
78627864
"cannot cast from type %1 to pointer type %2">;
78637865
def err_bad_static_cast_member_pointer_nonmp : Error<

clang/include/clang/Basic/Specifiers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace clang {
6868
TST_Accum, // ISO/IEC JTC1 SC22 WG14 N1169 Extension
6969
TST_Fract,
7070
TST_BFloat16,
71+
TST_MFloat8,
7172
TST_float,
7273
TST_double,
7374
TST_float128,

clang/include/clang/Basic/TargetBuiltins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ namespace clang {
198198
Float16,
199199
Float32,
200200
Float64,
201-
BFloat16
201+
BFloat16,
202+
MFloat8
202203
};
203204

204205
NeonTypeFlags(unsigned F) : Flags(F) {}

clang/include/clang/Basic/TargetInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class TargetInfo : public TransferrableTargetInfo,
234234
bool HasFullBFloat16; // True if the backend supports native bfloat16
235235
// arithmetic. Used to determine excess precision
236236
// support in the frontend.
237+
bool HasMFloat8;
237238
bool HasIbm128;
238239
bool HasLongDouble;
239240
bool HasFPReturn;
@@ -700,6 +701,9 @@ class TargetInfo : public TransferrableTargetInfo,
700701
return HasBFloat16 || HasFullBFloat16;
701702
}
702703

704+
/// Determine whether the _fpm8 type is supported on this target.
705+
virtual bool hasMFloat8Type() const { return HasMFloat8; }
706+
703707
/// Determine whether the BFloat type is fully supported on this target, i.e
704708
/// arithemtic operations.
705709
virtual bool hasFullBFloat16Type() const { return HasFullBFloat16; }

clang/include/clang/Basic/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ KEYWORD(__bool , KEYALTIVEC|KEYZVECTOR)
655655
// ARM NEON extensions.
656656
ALIAS("__fp16", half , KEYALL)
657657
KEYWORD(__bf16 , KEYALL)
658+
KEYWORD(__mfp8 , KEYALL)
658659

659660
// OpenCL Extension.
660661
KEYWORD(half , HALFSUPPORT)

clang/include/clang/Sema/DeclSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class DeclSpec {
287287
static const TST TST_bitint = clang::TST_bitint;
288288
static const TST TST_half = clang::TST_half;
289289
static const TST TST_BFloat16 = clang::TST_BFloat16;
290+
static const TST TST_MFloat8 = clang::TST_MFloat8;
290291
static const TST TST_float = clang::TST_float;
291292
static const TST TST_double = clang::TST_double;
292293
static const TST TST_float16 = clang::TST_Float16;

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,9 @@ enum PredefinedTypeIDs {
10781078
/// \brief The '__ibm128' type
10791079
PREDEF_TYPE_IBM128_ID = 74,
10801080

1081+
/// \bried The '__mfp8' type
1082+
PREDEF_TYPE_MFLOAT8_ID = 75,
1083+
10811084
/// OpenCL image types with auto numeration
10821085
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
10831086
PREDEF_TYPE_##Id##_ID,
@@ -1109,7 +1112,7 @@ enum PredefinedTypeIDs {
11091112
///
11101113
/// Type IDs for non-predefined types will start at
11111114
/// NUM_PREDEF_TYPE_IDs.
1112-
const unsigned NUM_PREDEF_TYPE_IDS = 503;
1115+
const unsigned NUM_PREDEF_TYPE_IDS = 504;
11131116

11141117
// Ensure we do not overrun the predefined types we reserved
11151118
// in the enum PredefinedTypeIDs above.

0 commit comments

Comments
 (0)