Skip to content

Commit 0cf7974

Browse files
committed
[libc] Fix generated float128 header for aarch64 target.
1 parent 8959206 commit 0cf7974

File tree

7 files changed

+41
-5
lines changed

7 files changed

+41
-5
lines changed

libc/config/linux/api.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def IntTypesAPI : PublicAPI<"inttypes.h"> {
5555
}
5656

5757
def MathAPI : PublicAPI<"math.h"> {
58-
let Types = ["double_t", "float_t"];
58+
let Types = ["double_t", "float_t", "float128"];
5959
}
6060

6161
def FenvAPI: PublicAPI<"fenv.h"> {

libc/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ add_gen_header(
9292
.llvm-libc-macros.math_macros
9393
.llvm-libc-types.double_t
9494
.llvm-libc-types.float_t
95+
.llvm-libc-types.float128
9596
)
9697

9798
# TODO: This should be conditional on POSIX networking being included.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@ add_header(rpc_opcodes_t HDR rpc_opcodes_t.h)
9696
add_header(ACTION HDR ACTION.h)
9797
add_header(ENTRY HDR ENTRY.h)
9898
add_header(struct_hsearch_data HDR struct_hsearch_data.h)
99+
add_header(float128 HDR float128.h)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===-- Definition of float128 type ---------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __LLVM_LIBC_TYPES_FLOAT128_H__
10+
#define __LLVM_LIBC_TYPES_FLOAT128_H__
11+
12+
#if defined(__clang__)
13+
#define LIBC_COMPILER_IS_CLANG
14+
#define LIBC_COMPILER_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
15+
#elif defined(__GNUC__)
16+
#define LIBC_COMPILER_IS_GCC
17+
#define LIBC_COMPILER_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
18+
#endif
19+
20+
#if (defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301)) && \
21+
(defined(__aarch64__) || defined(__riscv) || defined(__x86_64__))
22+
typedef _Float128 float128;
23+
#elif (defined(LIBC_COMPILER_CLANG_VER) && (LIBC_COMPILER_CLANG_VER >= 600)) &&\
24+
(defined(__x86_64__) && !defined(__Fuchsia__))
25+
typedef __float128 float128;
26+
#elif (LDBL_MANT_DIG == 113) || (__LDBL_MANT_DIG__ == 113)
27+
typedef long double float128;
28+
#endif
29+
30+
#endif // __LLVM_LIBC_TYPES_FLOAT128_H__

libc/spec/spec.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def LongDoubleType : NamedType<"long double">;
5151
def CharType : NamedType<"char">;
5252

5353
// TODO: Add compatibility layer to use C23 type _Float128 if possible.
54-
def Float128Type : NamedType<"__float128">;
54+
def Float128Type : NamedType<"float128">;
5555

5656
// Common types
5757
def VoidPtr : PtrType<VoidType>;

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def StdC : StandardSpec<"stdc"> {
352352
[
353353
NamedType<"float_t">,
354354
NamedType<"double_t">,
355+
NamedType<"float128">,
355356
],
356357
[], // Enumerations
357358
[

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include <float.h> // LDBL_MANT_DIG
2020

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

@@ -53,6 +53,9 @@ 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.
5659
#if (defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301)) && \
5760
(defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
5861
defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) || \

0 commit comments

Comments
 (0)