• 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_RISCV_SQRT_H
10 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_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_ANY_RISCV)
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 #ifdef __riscv_flen
25 template <> LIBC_INLINE float sqrt<float>(float x) {
26   float result;
27   __asm__ __volatile__("fsqrt.s %0, %1\n\t" : "=f"(result) : "f"(x));
28   return result;
29 }
30 
31 #if __riscv_flen >= 64
32 template <> LIBC_INLINE double sqrt<double>(double x) {
33   double result;
34   __asm__ __volatile__("fsqrt.d %0, %1\n\t" : "=f"(result) : "f"(x));
35   return result;
36 }
37 #endif // __riscv_flen >= 64
38 #endif // __riscv_flen
39 
40 } // namespace fputil
41 } // namespace LIBC_NAMESPACE
42 
43 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H
44