Skip to content

Commit 4daa33f

Browse files
committed
[flang][runtime] Use __float128 where possible & needed in runtime
On targets with __float128 available and distinct from long double, use it to support more kind=16 entry points. This affects mostly x86-64 targets. This means that more runtime entry points are defined for lowering to call. Delete Common/long-double.h and its LONG_DOUBLE macro in favor of testing the standard macro LDBL_MANT_DIG. Differential Revision: https://reviews.llvm.org/D127025
1 parent 30f1938 commit 4daa33f

16 files changed

+304
-137
lines changed

flang/include/flang/Common/long-double.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

flang/include/flang/Runtime/cpp-type.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
#include "flang/Common/Fortran.h"
1515
#include "flang/Common/uint128.h"
16+
#include "flang/Runtime/float128.h"
17+
#include <cfloat>
1618
#include <complex>
1719
#include <cstdint>
20+
#include <type_traits>
1821

1922
namespace Fortran::runtime {
2023

@@ -24,6 +27,12 @@ template <TypeCategory CAT, int KIND> struct CppTypeForHelper {};
2427
template <TypeCategory CAT, int KIND>
2528
using CppTypeFor = typename CppTypeForHelper<CAT, KIND>::type;
2629

30+
template <TypeCategory CAT, int KIND, bool SFINAE = false>
31+
constexpr bool HasCppTypeFor{false};
32+
template <TypeCategory CAT, int KIND>
33+
constexpr bool HasCppTypeFor<CAT, KIND, true>{
34+
!std::is_void_v<typename CppTypeForHelper<CAT, KIND>::type>};
35+
2736
template <int KIND> struct CppTypeForHelper<TypeCategory::Integer, KIND> {
2837
using type = common::HostSignedIntType<8 * KIND>;
2938
};
@@ -35,12 +44,21 @@ template <> struct CppTypeForHelper<TypeCategory::Real, 4> {
3544
template <> struct CppTypeForHelper<TypeCategory::Real, 8> {
3645
using type = double;
3746
};
47+
#if LDBL_MANT_DIG == 64
3848
template <> struct CppTypeForHelper<TypeCategory::Real, 10> {
3949
using type = long double;
4050
};
51+
#endif
52+
#if LDBL_MANT_DIG == 113
53+
using CppFloat128Type = long double;
54+
#elif HAS_FLOAT128
55+
using CppFloat128Type = __float128;
56+
#endif
57+
#if LDBL_MANT_DIG == 113 || HAS_FLOAT128
4158
template <> struct CppTypeForHelper<TypeCategory::Real, 16> {
42-
using type = long double;
59+
using type = CppFloat128Type;
4360
};
61+
#endif
4462

4563
template <int KIND> struct CppTypeForHelper<TypeCategory::Complex, KIND> {
4664
using type = std::complex<CppTypeFor<TypeCategory::Real, KIND>>;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*===-- flang/Runtime/float128.h ----------------------------------*- C -*-===
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+
/* This header is usable in both C and C++ code.
10+
* Isolates build compiler checks to determine the presence of an IEEE-754
11+
* quad-precision type named __float128 type that isn't __ibm128
12+
* (double/double). We don't care whether the type has underlying hardware
13+
* support or is emulated.
14+
*
15+
* 128-bit arithmetic may be available via "long double"; this can
16+
* be determined by LDBL_MANT_DIG == 113. A machine may have both 128-bit
17+
* long double and __float128; prefer long double by testing for it first.
18+
*/
19+
20+
#ifndef FORTRAN_RUNTIME_FLOAT128_H_
21+
#define FORTRAN_RUNTIME_FLOAT128_H_
22+
23+
#undef HAS_FLOAT128
24+
#if __x86_64__
25+
#if __GNUC__ >= 7 || __clang_major >= 7
26+
#define HAS_FLOAT128 1
27+
#endif
28+
#elif defined __PPC__ && __GNUC__ >= 8
29+
#define HAS_FLOAT128 1
30+
#endif
31+
32+
#endif /* FORTRAN_RUNTIME_FLOAT128_H_ */

0 commit comments

Comments
 (0)