Skip to content

Commit c0861e9

Browse files
committed
Revert "[flang] IEEE underflow control for Arm (#124617)"
This reverts commit c4c76ea. This breaks LLVM build on Windows: https://lab.llvm.org/buildbot/#/builders/161/builds/4322
1 parent 4424c44 commit c0861e9

File tree

2 files changed

+22
-45
lines changed

2 files changed

+22
-45
lines changed

flang/include/flang/Tools/TargetSetup.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,34 @@ namespace Fortran::tools {
2424
const std::string &compilerVersion, const std::string &compilerOptions) {
2525

2626
const llvm::Triple &targetTriple{targetMachine.getTargetTriple()};
27-
28-
targetCharacteristics.set_ieeeFeature(evaluate::IeeeFeature::Halting, true);
29-
27+
// FIXME: Handle real(3) ?
28+
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64) {
29+
targetCharacteristics.DisableType(
30+
Fortran::common::TypeCategory::Real, /*kind=*/10);
31+
}
3032
if (targetTriple.getArch() == llvm::Triple::ArchType::x86_64) {
3133
targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/3);
3234
targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/4);
3335
targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/8);
3436
}
35-
3637
if (targetTriple.isARM() || targetTriple.isAArch64()) {
3738
targetCharacteristics.set_haltingSupportIsUnknownAtCompileTime();
3839
targetCharacteristics.set_ieeeFeature(
3940
evaluate::IeeeFeature::Halting, false);
40-
targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/3);
41-
targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/4);
42-
targetCharacteristics.set_hasSubnormalFlushingControl(/*kind=*/8);
43-
}
44-
45-
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64) {
46-
targetCharacteristics.DisableType(
47-
Fortran::common::TypeCategory::Real, /*kind=*/10);
41+
} else {
42+
targetCharacteristics.set_ieeeFeature(evaluate::IeeeFeature::Halting);
4843
}
4944

50-
// Check for kind=16 support. See flang/runtime/Float128Math/math-entries.h.
51-
// TODO: Take this from TargetInfo::getLongDoubleFormat for cross compilation.
45+
// Figure out if we can support F128: see
46+
// flang/runtime/Float128Math/math-entries.h
47+
// TODO: this should be taken from TargetInfo::getLongDoubleFormat to support
48+
// cross-compilation
5249
#ifdef FLANG_RUNTIME_F128_MATH_LIB
53-
constexpr bool f128Support = true; // use libquadmath wrappers
50+
// we can use libquadmath wrappers
51+
constexpr bool f128Support = true;
5452
#elif HAS_LDBL128
55-
constexpr bool f128Support = true; // use libm wrappers
53+
// we can use libm wrappers
54+
constexpr bool f128Support = true;
5655
#else
5756
constexpr bool f128Support = false;
5857
#endif

flang/runtime/exceptions.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#include "flang/Runtime/exceptions.h"
1212
#include "terminator.h"
1313
#include <cfenv>
14-
#if __aarch64__
15-
#include <fpu_control.h>
16-
#elif __x86_64__
14+
#if __x86_64__
1715
#include <xmmintrin.h>
1816
#endif
1917

@@ -92,40 +90,20 @@ bool RTNAME(SupportHalting)([[maybe_unused]] uint32_t except) {
9290
#endif
9391
}
9492

95-
// A hardware FZ (flush to zero) bit is the negation of the
96-
// ieee_[get|set]_underflow_mode GRADUAL argument.
97-
#if defined(_MM_FLUSH_ZERO_MASK)
98-
// The x86_64 MXCSR FZ bit affects computations of real kinds 3, 4, and 8.
99-
#elif defined(_FPU_GETCW)
100-
// The aarch64 FPCR FZ bit affects computations of real kinds 3, 4, and 8.
101-
// bit 24: FZ -- single, double precision flush to zero bit
102-
// bit 19: FZ16 -- half precision flush to zero bit [not currently relevant]
103-
#define _FPU_FPCR_FZ_MASK_ 0x01080000
104-
#endif
105-
10693
bool RTNAME(GetUnderflowMode)(void) {
107-
#if defined(_MM_FLUSH_ZERO_MASK)
94+
#if _MM_FLUSH_ZERO_MASK
95+
// The MXCSR Flush to Zero flag is the negation of the ieee_get_underflow_mode
96+
// GRADUAL argument. It affects real computations of kinds 3, 4, and 8.
10897
return _MM_GET_FLUSH_ZERO_MODE() == _MM_FLUSH_ZERO_OFF;
109-
#elif defined(_FPU_GETCW)
110-
uint64_t fpcr;
111-
_FPU_GETCW(fpcr);
112-
return (fpcr & _FPU_FPCR_FZ_MASK_) == 0;
11398
#else
11499
return false;
115100
#endif
116101
}
117102
void RTNAME(SetUnderflowMode)(bool flag) {
118-
#if defined(_MM_FLUSH_ZERO_MASK)
103+
#if _MM_FLUSH_ZERO_MASK
104+
// The MXCSR Flush to Zero flag is the negation of the ieee_set_underflow_mode
105+
// GRADUAL argument. It affects real computations of kinds 3, 4, and 8.
119106
_MM_SET_FLUSH_ZERO_MODE(flag ? _MM_FLUSH_ZERO_OFF : _MM_FLUSH_ZERO_ON);
120-
#elif defined(_FPU_GETCW)
121-
uint64_t fpcr;
122-
_FPU_GETCW(fpcr);
123-
if (flag) {
124-
fpcr &= ~_FPU_FPCR_FZ_MASK_;
125-
} else {
126-
fpcr |= _FPU_FPCR_FZ_MASK_;
127-
}
128-
_FPU_SETCW(fpcr);
129107
#endif
130108
}
131109

0 commit comments

Comments
 (0)