Skip to content

Commit e30b666

Browse files
committed
Sync and consolidate float128 type logic in one place.
1 parent 7e476e0 commit e30b666

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ set(TARGET_LIBM_ENTRYPOINTS
379379
if(LIBC_COMPILER_HAS_FLOAT128)
380380
list(APPEND TARGET_LIBM_ENTRYPOINTS
381381
# math.h C23 _Float128 entrypoints
382-
# Temporarily disabled since float128 isn't working on the aarch64 buildbot
383-
# libc.src.math.fabsf128
382+
libc.src.math.fabsf128
384383
)
385384
endif()
386385

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,10 @@ add_header(ENTRY HDR ENTRY.h)
9898
add_header(struct_hsearch_data HDR struct_hsearch_data.h)
9999
add_header(struct_epoll_event HDR struct_epoll_event.h)
100100
add_header(struct_epoll_data HDR struct_epoll_data.h)
101-
add_header(float128 HDR float128.h)
101+
add_header(
102+
float128
103+
HDR
104+
float128.h
105+
DEPENDS
106+
libc.include.llvm-libc-macros.float_macros
107+
)

libc/include/llvm-libc-types/float128.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,37 @@
99
#ifndef __LLVM_LIBC_TYPES_FLOAT128_H__
1010
#define __LLVM_LIBC_TYPES_FLOAT128_H__
1111

12+
#include <llvm-libc-macros/float-macros.h> // LDBL_MANT_DIG
13+
14+
// Define temporary compiler and its version
1215
#if defined(__clang__)
13-
#define LIBC_COMPILER_IS_CLANG
14-
#define LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
16+
#define __LIBC_COMPILER_IS_CLANG
17+
#define __LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
1518
#elif defined(__GNUC__)
16-
#define LIBC_COMPILER_IS_GCC
17-
#define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
18-
#endif
19+
#define __LIBC_COMPILER_IS_GCC
20+
#define __LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
21+
#endif // __clang__, __GNUC__
1922

20-
#if (defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301)) && \
23+
#if (defined(__LIBC_COMPILER_GCC_VER) && (__LIBC_COMPILER_GCC_VER >= 1301)) && \
2124
(defined(__aarch64__) || defined(__riscv) || defined(__x86_64__))
25+
#define LIBC_COMPILER_HAS_C23_FLOAT128
2226
typedef _Float128 float128;
23-
#elif (defined(LIBC_COMPILER_CLANG_VER) && \
24-
(LIBC_COMPILER_CLANG_VER >= 600)) && \
27+
#elif (defined(__LIBC_COMPILER_CLANG_VER) && \
28+
(__LIBC_COMPILER_CLANG_VER >= 600)) && \
2529
(defined(__x86_64__) && !defined(__Fuchsia__))
30+
#define LIBC_COMPILER_HAS_FLOAT128_EXTENSION
2631
typedef __float128 float128;
27-
#elif (LDBL_MANT_DIG == 113) || (__LDBL_MANT_DIG__ == 113)
32+
#elif (LDBL_MANT_DIG == 113)
2833
typedef long double float128;
2934
#endif
3035

36+
// Clean up temporary macros
37+
#ifdef __LIBC_COMPILER_IS_CLANG
38+
#undef __LIBC_COMPILER_IS_CLANG
39+
#undef __LIBC_COMPILER_CLANG_VER
40+
#elif defined(__LIBC_COMPILER_IS_GCC)
41+
#undef __LIBC_COMPILER_IS_GCC
42+
#undef __LIBC_COMPILER_GCC_VER
43+
#endif // __LIBC_COMPILER_IS_CLANG, __LIBC_COMPILER_IS_GCC
44+
3145
#endif // __LLVM_LIBC_TYPES_FLOAT128_H__

libc/src/__support/macros/properties/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ add_header_library(
3333
.compiler
3434
.cpu_features
3535
.os
36+
libc.include.llvm-libc-types.float128
3637
)

libc/src/__support/macros/properties/float.h

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_FLOAT_H
1212
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_FLOAT_H
1313

14+
#include "llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG
15+
#include "llvm-libc-types/float128.h" // float128
1416
#include "src/__support/macros/properties/architectures.h"
1517
#include "src/__support/macros/properties/compiler.h"
1618
#include "src/__support/macros/properties/cpu_features.h"
1719
#include "src/__support/macros/properties/os.h"
1820

19-
#include <float.h> // LDBL_MANT_DIG
20-
2121
// 'long double' properties.
22-
#if (LDBL_MANT_DIG == 53) || (__LDBL_MANT_DIG__ == 53)
22+
#if (LDBL_MANT_DIG == 53)
2323
#define LIBC_LONG_DOUBLE_IS_FLOAT64
24-
#elif (LDBL_MANT_DIG == 64) || (__LDBL_MANT_DIG__ == 64)
24+
#elif (LDBL_MANT_DIG == 64)
2525
#define LIBC_LONG_DOUBLE_IS_X86_FLOAT80
26-
#elif (LDBL_MANT_DIG == 113) || (__LDBL_MANT_DIG__ == 113)
26+
#elif (LDBL_MANT_DIG == 113)
2727
#define LIBC_LONG_DOUBLE_IS_FLOAT128
2828
#endif
2929

@@ -53,29 +53,6 @@ using float16 = _Float16;
5353
#endif
5454

5555
// float128 support.
56-
// If the definition of float128 here is updated, also update
57-
// include/llvm-libc-types/float128.h
58-
// so that the type definition in generated header `math.h` matched.
59-
#if (defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301)) && \
60-
(defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
61-
defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) || \
62-
defined(LIBC_TARGET_ARCH_IS_X86_64))
63-
#define LIBC_COMPILER_HAS_C23_FLOAT128
64-
#endif
65-
#if (defined(LIBC_COMPILER_CLANG_VER) && (LIBC_COMPILER_CLANG_VER >= 600)) && \
66-
(defined(LIBC_TARGET_ARCH_IS_X86_64) && \
67-
defined(LIBC_TARGET_OS_IS_LINUX) && !defined(LIBC_TARGET_OS_IS_FUCHSIA))
68-
#define LIBC_COMPILER_HAS_FLOAT128_EXTENSION
69-
#endif
70-
71-
#if defined(LIBC_COMPILER_HAS_C23_FLOAT128)
72-
using float128 = _Float128;
73-
#elif defined(LIBC_COMPILER_HAS_FLOAT128_EXTENSION)
74-
using float128 = __float128;
75-
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT128)
76-
using float128 = long double;
77-
#endif
78-
7956
#if defined(LIBC_COMPILER_HAS_C23_FLOAT128) || \
8057
defined(LIBC_COMPILER_HAS_FLOAT128_EXTENSION) || \
8158
defined(LIBC_LONG_DOUBLE_IS_FLOAT128)

0 commit comments

Comments
 (0)