[libc-commits] [PATCH] D122688: [libc][obvious] fix sqrt when long double is double
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Mar 29 14:55:47 PDT 2022
michaelrj created this revision.
michaelrj added reviewers: sivachandra, lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett, pengfei.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122688
Files:
libc/src/__support/FPUtil/x86_64/sqrt.h
Index: libc/src/__support/FPUtil/x86_64/sqrt.h
===================================================================
--- libc/src/__support/FPUtil/x86_64/sqrt.h
+++ libc/src/__support/FPUtil/x86_64/sqrt.h
@@ -32,10 +32,18 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122688.418991.patch
Type: text/x-patch
Size: 650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220329/84cac16c/attachment.bin>
More information about the libc-commits
mailing list