[libc] Fix generated float128 header for aarch64 target. by lntue · Pull Request #78017 · llvm/llvm-project (original) (raw)
diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td index 85f6b59264eb06..8d39069a96e48d 100644 --- a/libc/config/linux/api.td +++ b/libc/config/linux/api.td @@ -55,7 +55,7 @@ def IntTypesAPI : PublicAPI<"inttypes.h"> { }
def MathAPI : PublicAPI<"math.h"> {
- let Types = ["double_t", "float_t"];
- let Types = ["double_t", "float_t", "float128"]; }
def FenvAPI: PublicAPI<"fenv.h"> { diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt index 2c2d1b9b0fd155..be6668049ad4ac 100644 --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -84,6 +84,7 @@ add_gen_header( .llvm-libc-macros.math_macros .llvm-libc-types.double_t .llvm-libc-types.float_t
- .llvm-libc-types.float128
)
TODO: This should be conditional on POSIX networking being included.
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt index 500900ffa0bbb0..7603eaac811417 100644 --- a/libc/include/llvm-libc-types/CMakeLists.txt +++ b/libc/include/llvm-libc-types/CMakeLists.txt @@ -96,3 +96,4 @@ add_header(rpc_opcodes_t HDR rpc_opcodes_t.h) add_header(ACTION HDR ACTION.h) add_header(ENTRY HDR ENTRY.h) add_header(struct_hsearch_data HDR struct_hsearch_data.h) +add_header(float128 HDR float128.h) diff --git a/libc/include/llvm-libc-types/float128.h b/libc/include/llvm-libc-types/float128.h new file mode 100644 index 00000000000000..7030384e7d314a --- /dev/null +++ b/libc/include/llvm-libc-types/float128.h @@ -0,0 +1,30 @@ +//===-- Definition of float128 type ---------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TYPES_FLOAT128_H +#define LLVM_LIBC_TYPES_FLOAT128_H + +#if defined(clang) +#define LIBC_COMPILER_IS_CLANG +#define LIBC_COMPILER_CLANG_VER (clang_major * 100 + clang_minor) +#elif defined(GNUC) +#define LIBC_COMPILER_IS_GCC +#define LIBC_COMPILER_GCC_VER (GNUC * 100 + GNUC_MINOR) +#endif + +#if (defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301)) && \
- (defined(aarch64) || defined(__riscv) || defined(x86_64))
+typedef _Float128 float128; +#elif (defined(LIBC_COMPILER_CLANG_VER) && (LIBC_COMPILER_CLANG_VER >= 600)) &&\
- (defined(x86_64) && !defined(Fuchsia))
+typedef __float128 float128; +#elif (LDBL_MANT_DIG == 113) || (LDBL_MANT_DIG == 113) +typedef long double float128; +#endif + +#endif // LLVM_LIBC_TYPES_FLOAT128_H diff --git a/libc/spec/spec.td b/libc/spec/spec.td index 9b689b5eb502a9..5b281a496432fc 100644 --- a/libc/spec/spec.td +++ b/libc/spec/spec.td @@ -51,7 +51,7 @@ def LongDoubleType : NamedType<"long double">; def CharType : NamedType<"char">;
// TODO: Add compatibility layer to use C23 type _Float128 if possible. -def Float128Type : NamedType<"__float128">; +def Float128Type : NamedType<"float128">;
// Common types def VoidPtr : PtrType; diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 714dc21f95ba54..05446b32c66da2 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -352,6 +352,7 @@ def StdC : StandardSpec<"stdc"> { [ NamedType<"float_t">, NamedType<"double_t">,
NamedType<"float128">, ], [], // Enumerations [
diff --git a/libc/src/__support/macros/properties/float.h b/libc/src/__support/macros/properties/float.h index 98ca2a5d4bc46f..bf2bcc7ffd9d63 100644 --- a/libc/src/__support/macros/properties/float.h +++ b/libc/src/__support/macros/properties/float.h @@ -19,11 +19,11 @@ #include <float.h> // LDBL_MANT_DIG
// 'long double' properties. -#if (LDBL_MANT_DIG == 53) +#if (LDBL_MANT_DIG == 53) || (LDBL_MANT_DIG == 53) #define LIBC_LONG_DOUBLE_IS_FLOAT64 -#elif (LDBL_MANT_DIG == 64) +#elif (LDBL_MANT_DIG == 64) || (LDBL_MANT_DIG == 64) #define LIBC_LONG_DOUBLE_IS_X86_FLOAT80 -#elif (LDBL_MANT_DIG == 113) +#elif (LDBL_MANT_DIG == 113) || (LDBL_MANT_DIG == 113) #define LIBC_LONG_DOUBLE_IS_FLOAT128 #endif
@@ -53,6 +53,9 @@ using float16 = _Float16; #endif
// float128 support.
+// If the definition of float128 here is updated, also update
+// include/llvm-libc-types/float128.h
+// so that the type definition in generated header math.h
matched.
#if (defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301)) &&
(defined(LIBC_TARGET_ARCH_IS_AARCH64) ||
defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) || \