[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / libc / src / __support / FPUtil / riscv / sqrt.h
blob0363822a4e8aff60ef4cf23a43cd8c4a47be64b8
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_RISCV_SQRT_H
10 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/__support/macros/properties/architectures.h"
16 #if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
17 #error "Invalid include"
18 #endif
20 #include "src/__support/FPUtil/generic/sqrt.h"
22 namespace LIBC_NAMESPACE_DECL {
23 namespace fputil {
25 #ifdef __riscv_flen
26 template <> LIBC_INLINE float sqrt<float>(float x) {
27 float result;
28 __asm__ __volatile__("fsqrt.s %0, %1\n\t" : "=f"(result) : "f"(x));
29 return result;
32 #if __riscv_flen >= 64
33 template <> LIBC_INLINE double sqrt<double>(double x) {
34 double result;
35 __asm__ __volatile__("fsqrt.d %0, %1\n\t" : "=f"(result) : "f"(x));
36 return result;
38 #endif // __riscv_flen >= 64
39 #endif // __riscv_flen
41 } // namespace fputil
42 } // namespace LIBC_NAMESPACE_DECL
44 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H