[libc-commits] [libc] [libc][math] Add x86-64 sqrt specialization for 80-bit long double. (PR #139203)

via libc-commits libc-commits at lists.llvm.org
Thu May 8 20:52:12 PDT 2025


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/139203

None

>From 141b944fc5081ad8543148d5a68d1e11a01124d7 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Thu, 8 May 2025 23:48:37 -0400
Subject: [PATCH] [libc][math] Add x86-64 sqrt specialization for 80-bit long
 double.

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

diff --git a/libc/src/__support/FPUtil/sqrt.h b/libc/src/__support/FPUtil/sqrt.h
index 1d377ab9a4e2d..0e6be73b66018 100644
--- a/libc/src/__support/FPUtil/sqrt.h
+++ b/libc/src/__support/FPUtil/sqrt.h
@@ -35,6 +35,14 @@ template <> LIBC_INLINE double sqrt<double>(double x) {
 }
 #endif // LIBC_TARGET_CPU_HAS_FPU_DOUBLE
 
+// Use 80-bit long double instruction on x86.
+// https://godbolt.org/z/oWEaj6hxK
+#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
+template <> LIBC_INLINE long double sqrt<long double>(long double x) {
+  return __builtin_elementwise_sqrt(x);
+}
+#endif
+
 } // namespace fputil
 } // namespace LIBC_NAMESPACE_DECL
 



More information about the libc-commits mailing list