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#include "../llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG
13
14// Currently, C23 `_Float128` type is only defined as a built-in type in GCC 7
15// or later, and only for C. For C++, or for clang, `__float128` is defined
16// instead, and only on x86-64 targets.
17//
18// TODO: Update C23 `_Float128` type detection again when clang supports it.
19// https://github.com/llvm/llvm-project/issues/80195
20#if defined(__STDC_IEC_60559_BFP__) && !defined(__clang__) && \
21 !defined(__cplusplus)
22#define LIBC_TYPES_HAS_NATIVE_FLOAT128
23typedef _Float128 float128;
24#elif defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
25// Use __float128 type. gcc and clang sometime use __SIZEOF_FLOAT128__ to
26// notify the availability of __float128.
27// clang also uses __FLOAT128__ macro to notify the availability of __float128
28// type: https://reviews.llvm.org/D15120
29// Disable on x86_64 Clang version less than 18.1 due to issue passing
30// __float128 via varargs prior to
31// https://github.com/llvm/llvm-project/pull/75156.
32#if !(defined(__clang__) && \
33 (__clang_major__ * 100 + __clang_minor__ < 1801) && defined(__x86_64__))
34#define LIBC_TYPES_HAS_NATIVE_FLOAT128
35typedef __float128 float128;
36#endif // !(Clang < 18.1 on x86_64)
37#elif (LDBL_MANT_DIG == 113)
38#define LIBC_TYPES_HAS_NATIVE_FLOAT128
39typedef long double float128;
40#endif
41
42#endif // LLVM_LIBC_TYPES_FLOAT128_H
43