1 //===-- Square root of IEEE 754 floating point numbers ----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_H
10 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_H
12 #include "src/__support/common.h"
13 #include "src/__support/macros/properties/architectures.h"
15 #if !defined(LIBC_TARGET_ARCH_IS_X86)
16 #error "Invalid include"
19 #include "src/__support/FPUtil/generic/sqrt.h"
21 namespace __llvm_libc
{
24 template <> LIBC_INLINE
float sqrt
<float>(float x
) {
26 __asm__
__volatile__("sqrtss %x1, %x0" : "=x"(result
) : "x"(x
));
30 template <> LIBC_INLINE
double sqrt
<double>(double x
) {
32 __asm__
__volatile__("sqrtsd %x1, %x0" : "=x"(result
) : "x"(x
));
36 #ifdef LONG_DOUBLE_IS_DOUBLE
37 template <> LIBC_INLINE
long double sqrt
<long double>(long double x
) {
39 __asm__
__volatile__("sqrtsd %x1, %x0" : "=x"(result
) : "x"(x
));
43 template <> LIBC_INLINE
long double sqrt
<long double>(long double x
) {
44 __asm__
__volatile__("fsqrt" : "+t"(x
));
50 } // namespace __llvm_libc
52 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_H