[flang-commits] [flang] [flang][runtime] Add FLANG_RUNTIME_NO_REAL_3 flag to build (PR #105856)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Aug 23 09:58:22 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/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).
>From 50c57eaf4425f92eb0c2f03de1d7a2df1deed43d Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 23 Aug 2024 09:54:32 -0700
Subject: [PATCH] [flang][runtime] Add FLANG_RUNTIME_NO_REAL_3 flag to build
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).
---
flang/runtime/numeric.cpp | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/flang/runtime/numeric.cpp b/flang/runtime/numeric.cpp
index 28687b1971b7ed..40bacf07157a27 100644
--- a/flang/runtime/numeric.cpp
+++ b/flang/runtime/numeric.cpp
@@ -142,6 +142,11 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedRealKind(
#else
constexpr bool hasReal2{false};
#endif
+#ifndef FLANG_RUNTIME_NO_REAL_3
+ constexpr bool hasReal3{true};
+#else
+ constexpr bool hasReal3{false};
+#endif
#if defined LDBL_MANT_DIG == 64 && !defined FLANG_RUNTIME_NO_REAL_10
constexpr bool hasReal10{true};
#else
@@ -171,9 +176,9 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedRealKind(
}
if (r <= 4) {
- kind = kind < 2 ? 2 : kind;
+ kind = kind < 2 ? (hasReal2 ? 2 : 4) : kind;
} else if (r <= 37) {
- kind = kind < 3 ? (p == 3 ? 4 : 3) : kind;
+ kind = kind < 3 ? (hasReal3 && p != 3 ? 3 : 4) : kind;
} else if (r <= 307) {
kind = kind < 8 ? 8 : kind;
} else if (hasReal10 && r <= 4931) {
More information about the flang-commits
mailing list