Skip to content

Commit 57b89fd

Browse files
authored
[flang][runtime] Add FLANG_RUNTIME_NO_REAL_3 flag to build (#105856)
Allow a runtime build to disable SELECTED_REAL_KIND from returning kind 3 (16-bit truncated form of 32-bit IEEE-754 floating point, a/k/a "brain float" or bfloat16).
1 parent 8f08b75 commit 57b89fd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

flang/runtime/numeric.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedRealKind(
142142
#else
143143
constexpr bool hasReal2{false};
144144
#endif
145+
#ifndef FLANG_RUNTIME_NO_REAL_3
146+
constexpr bool hasReal3{true};
147+
#else
148+
constexpr bool hasReal3{false};
149+
#endif
145150
#if defined LDBL_MANT_DIG == 64 && !defined FLANG_RUNTIME_NO_REAL_10
146151
constexpr bool hasReal10{true};
147152
#else
@@ -171,9 +176,9 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedRealKind(
171176
}
172177

173178
if (r <= 4) {
174-
kind = kind < 2 ? 2 : kind;
179+
kind = kind < 2 ? (hasReal2 ? 2 : 4) : kind;
175180
} else if (r <= 37) {
176-
kind = kind < 3 ? (p == 3 ? 4 : 3) : kind;
181+
kind = kind < 3 ? (hasReal3 && p != 3 ? 3 : 4) : kind;
177182
} else if (r <= 307) {
178183
kind = kind < 8 ? 8 : kind;
179184
} else if (hasReal10 && r <= 4931) {

0 commit comments

Comments
 (0)