[libc-commits] [libc] [libc][math] Fix use of float16 not guarded by LIBC_TYPES_HAS_FLOAT16 (PR #100241)

via libc-commits libc-commits at lists.llvm.org
Tue Jul 23 15:12:45 PDT 2024


https://github.com/overmighty created https://github.com/llvm/llvm-project/pull/100241

None

>From 81f34ef0af8c4875eb7ea305eb5b54321ea03b87 Mon Sep 17 00:00:00 2001
From: OverMighty <its.overmighty at gmail.com>
Date: Wed, 24 Jul 2024 00:08:19 +0200
Subject: [PATCH] [libc][math] Fix use of float16 not guarded by
 LIBC_TYPES_HAS_FLOAT16

---
 libc/src/__support/FPUtil/BasicOperations.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index 8ce9522a9ba6d..50f1e19e08d64 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -44,6 +44,7 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> max(T x, T y) {
   return x > y ? x : y;
 }
 
+#ifdef LIBC_TYPES_HAS_FLOAT16
 #if defined(__LIBC_USE_BUILTIN_FMAXF16_FMINF16)
 template <> LIBC_INLINE float16 max(float16 x, float16 y) {
   return __builtin_fmaxf16(x, y);
@@ -58,6 +59,7 @@ template <> LIBC_INLINE float16 max(float16 x, float16 y) {
   return ((xi > yi) != (xi < 0 && yi < 0)) ? x : y;
 }
 #endif
+#endif // LIBC_TYPES_HAS_FLOAT16
 
 #if defined(__LIBC_USE_BUILTIN_FMAX_FMIN) && !defined(LIBC_TARGET_ARCH_IS_X86)
 template <> LIBC_INLINE float max(float x, float y) {
@@ -82,6 +84,7 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> min(T x, T y) {
   return x < y ? x : y;
 }
 
+#ifdef LIBC_TYPES_HAS_FLOAT16
 #if defined(__LIBC_USE_BUILTIN_FMAXF16_FMINF16)
 template <> LIBC_INLINE float16 min(float16 x, float16 y) {
   return __builtin_fminf16(x, y);
@@ -96,6 +99,7 @@ template <> LIBC_INLINE float16 min(float16 x, float16 y) {
   return ((xi < yi) != (xi < 0 && yi < 0)) ? x : y;
 }
 #endif
+#endif // LIBC_TYPES_HAS_FLOAT16
 
 #if defined(__LIBC_USE_BUILTIN_FMAX_FMIN) && !defined(LIBC_TARGET_ARCH_IS_X86)
 template <> LIBC_INLINE float min(float x, float y) {



More information about the libc-commits mailing list