Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][runtime] Add FLANG_RUNTIME_NO_REAL_3 flag to build #105856

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

klausler
Copy link
Contributor

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).

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).
@klausler klausler requested a review from Renaud-K August 23, 2024 16:58
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Aug 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2024

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

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).


Full diff: https://github.com/llvm/llvm-project/pull/105856.diff

1 Files Affected:

  • (modified) flang/runtime/numeric.cpp (+7-2)
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) {

Copy link
Contributor

@Renaud-K Renaud-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Looks good.

@klausler klausler merged commit 57b89fd into llvm:main Aug 23, 2024
11 checks passed
@klausler klausler deleted the nokind3 branch August 23, 2024 18:27
5chmidti pushed a commit that referenced this pull request Aug 24, 2024
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).
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this pull request Sep 2, 2024
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants