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/config.h" 14 #include "src/__support/macros/properties/architectures.h" 15 16 #if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) 17 #error "Invalid include" 18 #endif 19 20 #include "src/__support/FPUtil/generic/sqrt.h" 21 22 namespace LIBC_NAMESPACE_DECL { 23 namespace fputil { 24 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; 30 } 31 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; 37 } 38 #endif // __riscv_flen >= 64 39 #endif // __riscv_flen 40 41 } // namespace fputil 42 } // namespace LIBC_NAMESPACE_DECL 43 44 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H 45