[libc] [llvm] [libc] add flag for FP_*LOGB0/NAN values (PR #86723)

Michael Jones via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 12:54:41 PDT 2024


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/86723

These values vary by system, this flag allows you to toggle their value.


>From 456b726b488c4215b5055101778ec8036f53bc7d Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Tue, 26 Mar 2024 12:53:30 -0700
Subject: [PATCH] [libc] add flag for FP_*LOGB0/NAN values

These values vary by system, this flag allows you to toggle their value.
---
 libc/include/llvm-libc-macros/math-macros.h       | 14 ++++++++++++--
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel |  1 +
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 03c7a823e6e96b..0c524eb4918968 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -30,11 +30,21 @@
 #define INFINITY __builtin_inf()
 #define NAN __builtin_nanf("")
 
+#ifdef __FP_LOGB0_MIN
 #define FP_ILOGB0 (-INT_MAX - 1)
-#define FP_ILOGBNAN INT_MAX
-
 #define FP_LLOGB0 (-LONG_MAX - 1)
+#else
+#define FP_ILOGB0 (-INT_MAX)
+#define FP_LLOGB0 (-LONG_MAX)
+#endif
+
+#ifdef __FP_LOGBNAN_MIN
+#define FP_ILOGBNAN (-INT_MAX - 1)
+#define FP_LLOGBNAN (-LONG_MAX - 1)
+#else
+#define FP_ILOGBNAN INT_MAX
 #define FP_LLOGBNAN LONG_MAX
+#endif
 
 #ifdef __FAST_MATH__
 #define math_errhandling 0
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 57dc75a3a48e60..09edc276035260 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -68,6 +68,7 @@ libc_support_library(
     name = "llvm_libc_macros_math_macros",
     hdrs = ["include/llvm-libc-macros/math-macros.h"],
     deps = [":llvm_libc_macros_limits_macros"],
+    defines = ["__FP_LOGBNAN_MIN"],
 )
 
 libc_support_library(



More information about the llvm-commits mailing list