1 | //===-- Square root of IEEE 754 floating point numbers ----------*- C++ -*-===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_SQRT_H |
10 | #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_SQRT_H |
11 | |
12 | #include "src/__support/common.h" |
13 | #include "src/__support/macros/properties/architectures.h" |
14 | |
15 | #if !defined(LIBC_TARGET_ARCH_IS_X86) |
16 | #error "Invalid include" |
17 | #endif |
18 | |
19 | #include "src/__support/FPUtil/generic/sqrt.h" |
20 | |
21 | namespace LIBC_NAMESPACE { |
22 | namespace fputil { |
23 | |
24 | template <> LIBC_INLINE float sqrt<float>(float x) { |
25 | float result; |
26 | __asm__ __volatile__("sqrtss %x1, %x0" : "=x" (result) : "x" (x)); |
27 | return result; |
28 | } |
29 | |
30 | template <> LIBC_INLINE double sqrt<double>(double x) { |
31 | double result; |
32 | __asm__ __volatile__("sqrtsd %x1, %x0" : "=x" (result) : "x" (x)); |
33 | return result; |
34 | } |
35 | |
36 | #ifdef LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64 |
37 | template <> LIBC_INLINE long double sqrt<long double>(long double x) { |
38 | long double result; |
39 | __asm__ __volatile__("sqrtsd %x1, %x0" : "=x" (result) : "x" (x)); |
40 | return result; |
41 | } |
42 | #else |
43 | template <> LIBC_INLINE long double sqrt<long double>(long double x) { |
44 | __asm__ __volatile__("fsqrt" : "+t" (x)); |
45 | return x; |
46 | } |
47 | #endif |
48 | |
49 | } // namespace fputil |
50 | } // namespace LIBC_NAMESPACE |
51 | |
52 | #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_SQRT_H |
53 | |