[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / __support / FPUtil / x86_64 / sqrt.h
blobd445c58eb4be2e09f5fde4a72295890eb63c844b
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 //===----------------------------------------------------------------------===//
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"
17 #endif
19 #include "src/__support/FPUtil/generic/sqrt.h"
21 namespace __llvm_libc {
22 namespace fputil {
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;
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;
36 #ifdef LONG_DOUBLE_IS_DOUBLE
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;
42 #else
43 template <> LIBC_INLINE long double sqrt<long double>(long double x) {
44 __asm__ __volatile__("fsqrt" : "+t"(x));
45 return x;
47 #endif
49 } // namespace fputil
50 } // namespace __llvm_libc
52 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_H