Skip to content

Commit a179a1b

Browse files
authored
[libc][math] Add x86-64 sqrt specialization for 80-bit long double. (#139203)
1 parent 802a2e3 commit a179a1b

File tree

1 file changed

+8
-0
lines changed
  • libc/src/__support/FPUtil

1 file changed

+8
-0
lines changed

libc/src/__support/FPUtil/sqrt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ template <> LIBC_INLINE double sqrt<double>(double x) {
3535
}
3636
#endif // LIBC_TARGET_CPU_HAS_FPU_DOUBLE
3737

38+
// Use 80-bit long double instruction on x86.
39+
// https://godbolt.org/z/oWEaj6hxK
40+
#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
41+
template <> LIBC_INLINE long double sqrt<long double>(long double x) {
42+
return __builtin_elementwise_sqrt(x);
43+
}
44+
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
45+
3846
} // namespace fputil
3947
} // namespace LIBC_NAMESPACE_DECL
4048

0 commit comments

Comments
 (0)