Skip to content

Commit 4f4ca1f

Browse files
committed
Fix build of ieee_arithmetic module
1 parent 5556bf2 commit 4f4ca1f

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

flang/module/ieee_arithmetic.f90

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,33 @@ end function ieee_round_ne
161161
G(1) G(2) G(4) G(8) G(16)
162162
#define SPECIFICS_L(G) \
163163
G(1) G(2) G(4) G(8)
164+
165+
#if FLANG_SUPPORT_R16
164166
#if __x86_64__
165167
#define SPECIFICS_R(G) \
166168
G(2) G(3) G(4) G(8) G(10) G(16)
167169
#else
168170
#define SPECIFICS_R(G) \
169171
G(2) G(3) G(4) G(8) G(16)
170172
#endif
173+
#else
174+
#if __x86_64__
175+
#define SPECIFICS_R(G) \
176+
G(2) G(3) G(4) G(8) G(10)
177+
#else
178+
#define SPECIFICS_R(G) \
179+
G(2) G(3) G(4) G(8)
180+
#endif
181+
#endif
182+
171183
#define SPECIFICS_II(G) \
172184
G(1,1) G(1,2) G(1,4) G(1,8) G(1,16) \
173185
G(2,1) G(2,2) G(2,4) G(2,8) G(2,16) \
174186
G(4,1) G(4,2) G(4,4) G(4,8) G(4,16) \
175187
G(8,1) G(8,2) G(8,4) G(8,8) G(8,16) \
176188
G(16,1) G(16,2) G(16,4) G(16,8) G(16,16)
189+
190+
#if FLANG_SUPPORT_R16
177191
#if __x86_64__
178192
#define SPECIFICS_RI(G) \
179193
G(2,1) G(2,2) G(2,4) G(2,8) G(2,16) \
@@ -190,7 +204,24 @@ end function ieee_round_ne
190204
G(8,1) G(8,2) G(8,4) G(8,8) G(8,16) \
191205
G(16,1) G(16,2) G(16,4) G(16,8) G(16,16)
192206
#endif
207+
#else
208+
#if __x86_64__
209+
#define SPECIFICS_RI(G) \
210+
G(2,1) G(2,2) G(2,4) G(2,8) \
211+
G(3,1) G(3,2) G(3,4) G(3,8) \
212+
G(4,1) G(4,2) G(4,4) G(4,8) \
213+
G(8,1) G(8,2) G(8,4) G(8,8) \
214+
G(10,1) G(10,2) G(10,4) G(10,8)
215+
#else
216+
#define SPECIFICS_RI(G) \
217+
G(2,1) G(2,2) G(2,4) G(2,8) \
218+
G(3,1) G(3,2) G(3,4) G(3,8) \
219+
G(4,1) G(4,2) G(4,4) G(4,8) \
220+
G(8,1) G(8,2) G(8,4) G(8,8)
221+
#endif
222+
#endif
193223

224+
#if FLANG_SUPPORT_R16
194225
#if __x86_64__
195226
#define SPECIFICS_RR(G) \
196227
G(2,2) G(2,3) G(2,4) G(2,8) G(2,10) G(2,16) \
@@ -207,6 +238,22 @@ end function ieee_round_ne
207238
G(8,2) G(8,3) G(8,4) G(8,8) G(8,16) \
208239
G(16,2) G(16,3) G(16,4) G(16,8) G(16,16)
209240
#endif
241+
#else
242+
#if __x86_64__
243+
#define SPECIFICS_RR(G) \
244+
G(2,2) G(2,3) G(2,4) G(2,8) G(2,10) \
245+
G(3,2) G(3,3) G(3,4) G(3,8) G(3,10) \
246+
G(4,2) G(4,3) G(4,4) G(4,8) G(4,10) \
247+
G(8,2) G(8,3) G(8,4) G(8,8) G(8,10) \
248+
G(10,2) G(10,3) G(10,4) G(10,8) G(10,10)
249+
#else
250+
#define SPECIFICS_RR(G) \
251+
G(2,2) G(2,3) G(2,4) G(2,8) \
252+
G(3,2) G(3,3) G(3,4) G(3,8) \
253+
G(4,2) G(4,3) G(4,4) G(4,8) \
254+
G(8,2) G(8,3) G(8,4) G(8,8)
255+
#endif
256+
#endif
210257

211258
#define IEEE_CLASS_R(XKIND) \
212259
elemental type(ieee_class_type) function ieee_class_a##XKIND(x); \
@@ -462,8 +509,10 @@ end function ieee_real_a##AKIND##_i##KKIND;
462509
interface ieee_real
463510
SPECIFICS_I(IEEE_REAL_I)
464511
SPECIFICS_R(IEEE_REAL_R)
512+
#if FLANG_SUPPORT_R16
465513
SPECIFICS_II(IEEE_REAL_II)
466514
SPECIFICS_RI(IEEE_REAL_RI)
515+
#endif
467516
end interface ieee_real
468517
public :: ieee_real
469518
#undef IEEE_REAL_I

flang/tools/f18/CMakeLists.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ set(MODULES_WITHOUT_IMPLEMENTATION
3131

3232
set(MODULES ${MODULES_WITH_IMPLEMENTATION} ${MODULES_WITHOUT_IMPLEMENTATION})
3333

34+
# Check if 128-bit float computations can be done via long double.
35+
check_cxx_source_compiles(
36+
"#include <cfloat>
37+
#if LDBL_MANT_DIG != 113
38+
#error LDBL_MANT_DIG != 113
39+
#endif
40+
int main() { return 0; }
41+
"
42+
HAVE_LDBL_MANT_DIG_113)
43+
44+
# Figure out whether we can support REAL(KIND=16)
45+
if (FLANG_RUNTIME_F128_MATH_LIB)
46+
set(FLANG_SUPPORT_R16 "1")
47+
elseif (HAVE_LDBL_MANT_DIG_113)
48+
set(FLANG_SUPPORT_R16 "1")
49+
else()
50+
set(FLANG_SUPPORT_R16 "0")
51+
endif()
52+
3453
# Init variable to hold extra object files coming from the Fortran modules;
3554
# these module files will be contributed from the CMakeLists in flang/tools/f18.
3655
set(module_objects "")
@@ -76,6 +95,10 @@ if (NOT CMAKE_CROSSCOMPILING)
7695
endif()
7796
endif()
7897

98+
set(decls "")
99+
if (FLANG_SUPPORT_R16)
100+
set(decls "-DFLANG_SUPPORT_R16")
101+
endif()
79102

80103
# Some modules have an implementation part that needs to be added to the
81104
# FortranRuntime library.
@@ -92,7 +115,7 @@ if (NOT CMAKE_CROSSCOMPILING)
92115
# TODO: We may need to flag this with conditional, in case Flang is built w/o OpenMP support
93116
add_custom_command(OUTPUT ${base}.mod ${object_output}
94117
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
95-
COMMAND flang-new ${opts} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
118+
COMMAND flang-new ${opts} ${decls} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
96119
${FLANG_SOURCE_DIR}/module/${filename}.f90
97120
DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
98121
)

0 commit comments

Comments
 (0)