• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/__support/macros/properties/cpu_features.h"
15 
16 #if !(defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2))
17 #error "sqrtss / sqrtsd need SSE2"
18 #endif
19 
20 #include "src/__support/FPUtil/generic/sqrt.h"
21 
22 namespace LIBC_NAMESPACE {
23 namespace fputil {
24 
25 template <> LIBC_INLINE float sqrt<float>(float x) {
26   float result;
27   __asm__ __volatile__("sqrtss %x1, %x0" : "=x"(result) : "x"(x));
28   return result;
29 }
30 
31 template <> LIBC_INLINE double sqrt<double>(double x) {
32   double result;
33   __asm__ __volatile__("sqrtsd %x1, %x0" : "=x"(result) : "x"(x));
34   return result;
35 }
36 
37 #ifdef LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
38 template <> LIBC_INLINE long double sqrt<long double>(long double x) {
39   long double result;
40   __asm__ __volatile__("sqrtsd %x1, %x0" : "=x"(result) : "x"(x));
41   return result;
42 }
43 #else
44 template <> LIBC_INLINE long double sqrt<long double>(long double x) {
45   __asm__ __volatile__("fsqrt" : "+t"(x));
46   return x;
47 }
48 #endif
49 
50 } // namespace fputil
51 } // namespace LIBC_NAMESPACE
52 
53 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_SQRT_H
54