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

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Mar 27 14:56:25 PDT 2024


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

>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 1/2] [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(

>From 21b21ffe5ea9a0e6989f51263f4e281c3157dcca Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 27 Mar 2024 14:55:59 -0700
Subject: [PATCH 2/2] undo LOGB0 changes

---
 libc/include/llvm-libc-macros/math-macros.h | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 0c524eb4918968..1497e32044e975 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -30,13 +30,8 @@
 #define INFINITY __builtin_inf()
 #define NAN __builtin_nanf("")
 
-#ifdef __FP_LOGB0_MIN
 #define FP_ILOGB0 (-INT_MAX - 1)
 #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)



More information about the libc-commits mailing list