[libc-commits] [libc] [libc] Fix generated float128 header for aarch64 target. (PR #78017)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Tue Jan 23 10:20:08 PST 2024


================
@@ -0,0 +1,45 @@
+//===-- 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__
+
+#include <include/llvm-libc-macros/float-macros.h> // LDBL_MANT_DIG
+
+// Define temporary compiler and its version
+#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 // __clang__, __GNUC__
+
+#if (defined(__LIBC_COMPILER_GCC_VER) && (__LIBC_COMPILER_GCC_VER >= 1301)) && \
+    (defined(__aarch64__) || defined(__riscv) || defined(__x86_64__))
+#define LIBC_COMPILER_HAS_C23_FLOAT128
+typedef _Float128 float128;
+#elif (defined(__LIBC_COMPILER_CLANG_VER) &&                                   \
+       (__LIBC_COMPILER_CLANG_VER >= 600)) &&                                  \
+    (defined(__x86_64__) && !defined(__Fuchsia__))
+#define LIBC_COMPILER_HAS_FLOAT128_EXTENSION
+typedef __float128 float128;
+#elif (LDBL_MANT_DIG == 113)
+typedef long double float128;
+#endif
----------------
nickdesaulniers wrote:

Then clang defines `__FLOAT128__` ...

I wonder if we can use feature detection here, rather than version checks. Then having the messy redef then undef compiler version stuff can go away.

For example, I suspect that most of this header can simply be:

```c
#if defined(__clang__) && defined(__FLOAT128__)
typedef __float128 float128;
#elif !defined(__clang__) && defined(__GNUC__) && defined(__FLT128_IS_IEC_60559__)
typedef _Float128 float128;
#elif (LDBL_MANT_DIG == 113;
typedef long double float128;
#else
#error "unsupported float128 type for platform"
#endif
```

Does IEC 60559 state what preprocessor define should exist when `_Float128` is supported?

https://github.com/llvm/llvm-project/pull/78017


More information about the libc-commits mailing list