[libc-commits] [libc] [libc][NFC] Tighten up guard conditions for sqrt and polyeval (PR #93791)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Thu May 30 02:07:41 PDT 2024


https://github.com/gchatelet created https://github.com/llvm/llvm-project/pull/93791

None

>From 47015ae8c504f3b7bcc35dd1597e1a298ef89579 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Thu, 30 May 2024 09:03:25 +0000
Subject: [PATCH] [libc][NFC] Tighten up guard conditions for sqrt and polyeval

---
 libc/src/__support/FPUtil/sqrt.h            | 3 ++-
 libc/src/__support/FPUtil/x86_64/PolyEval.h | 6 ++++--
 libc/src/__support/FPUtil/x86_64/sqrt.h     | 5 +++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libc/src/__support/FPUtil/sqrt.h b/libc/src/__support/FPUtil/sqrt.h
index 3ba1bdf687a3e..eb86ddfa89d8e 100644
--- a/libc/src/__support/FPUtil/sqrt.h
+++ b/libc/src/__support/FPUtil/sqrt.h
@@ -10,8 +10,9 @@
 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_SQRT_H
 
 #include "src/__support/macros/properties/architectures.h"
+#include "src/__support/macros/properties/cpu_features.h"
 
-#if defined(LIBC_TARGET_ARCH_IS_X86_64)
+#if defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2)
 #include "x86_64/sqrt.h"
 #elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
 #include "aarch64/sqrt.h"
diff --git a/libc/src/__support/FPUtil/x86_64/PolyEval.h b/libc/src/__support/FPUtil/x86_64/PolyEval.h
index 69fd776320799..713fa029021e2 100644
--- a/libc/src/__support/FPUtil/x86_64/PolyEval.h
+++ b/libc/src/__support/FPUtil/x86_64/PolyEval.h
@@ -11,9 +11,11 @@
 
 #include "src/__support/common.h"
 #include "src/__support/macros/properties/architectures.h"
+#include "src/__support/macros/properties/cpu_features.h"
 
-#if !defined(LIBC_TARGET_ARCH_IS_X86_64)
-#error "Invalid include"
+#if !(defined(LIBC_TARGET_ARCH_IS_X86_64) &&                                   \
+      defined(LIBC_TARGET_CPU_HAS_SSE2) && defined(LIBC_TARGET_CPU_HAS_FMA))
+#error "Missing FMA and SS2 support"
 #endif
 
 #include <immintrin.h>
diff --git a/libc/src/__support/FPUtil/x86_64/sqrt.h b/libc/src/__support/FPUtil/x86_64/sqrt.h
index 93ba8c0b33fdc..bfcc5e98834d6 100644
--- a/libc/src/__support/FPUtil/x86_64/sqrt.h
+++ b/libc/src/__support/FPUtil/x86_64/sqrt.h
@@ -11,9 +11,10 @@
 
 #include "src/__support/common.h"
 #include "src/__support/macros/properties/architectures.h"
+#include "src/__support/macros/properties/cpu_features.h"
 
-#if !defined(LIBC_TARGET_ARCH_IS_X86)
-#error "Invalid include"
+#if !(defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2))
+#error "sqrtss / sqrtsd need SSE2"
 #endif
 
 #include "src/__support/FPUtil/generic/sqrt.h"



More information about the libc-commits mailing list