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

via libc-commits libc-commits at lists.llvm.org
Fri May 9 07:31:34 PDT 2025


Author: lntue
Date: 2025-05-09T10:31:31-04:00
New Revision: a179a1b3a8302ecd92cf9e7a01beb6732f265c26

URL: https://github.com/llvm/llvm-project/commit/a179a1b3a8302ecd92cf9e7a01beb6732f265c26
DIFF: https://github.com/llvm/llvm-project/commit/a179a1b3a8302ecd92cf9e7a01beb6732f265c26.diff

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

Added: 
    

Modified: 
    libc/src/__support/FPUtil/sqrt.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/sqrt.h b/libc/src/__support/FPUtil/sqrt.h
index 1d377ab9a4e2d..d4ed744b4010d 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 // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
+
 } // namespace fputil
 } // namespace LIBC_NAMESPACE_DECL
 


        


More information about the libc-commits mailing list