[libc-commits] [libc] 4ac3f7e - [libc][obvious] fix sqrt when long double is double

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Mar 29 16:05:45 PDT 2022


Author: Michael Jones
Date: 2022-03-29T16:05:40-07:00
New Revision: 4ac3f7e41aaea0ad678a41cc2408bb9eda7ba33c

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

LOG: [libc][obvious] fix sqrt when long double is double

Previously, the "fsqrt" instruction was used on all x86_64 platforms
for finding the square root of long doubles. On long double is double
platforms (e.g. windows) this created errors. This patch changes square
root function for long doubles to be the same as the one for doubles if
long doubles are doubles.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D122688

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/x86_64/sqrt.h b/libc/src/__support/FPUtil/x86_64/sqrt.h
index e3c68206c5a63..c2ca4b1a1016b 100644
--- a/libc/src/__support/FPUtil/x86_64/sqrt.h
+++ b/libc/src/__support/FPUtil/x86_64/sqrt.h
@@ -32,10 +32,18 @@ template <> inline double sqrt<double>(double x) {
   return result;
 }
 
+#ifdef LONG_DOUBLE_IS_DOUBLE
+template <> inline long double sqrt<long double>(long double x) {
+  long double result;
+  __asm__ __volatile__("sqrtsd %x1, %x0" : "=x"(result) : "x"(x));
+  return result;
+}
+#else
 template <> inline long double sqrt<long double>(long double x) {
   __asm__ __volatile__("fsqrt" : "+t"(x));
   return x;
 }
+#endif
 
 } // namespace fputil
 } // namespace __llvm_libc


        


More information about the libc-commits mailing list