Warning: This file is not a C or C++ file. It does not have highlighting.

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#include "src/__support/macros/properties/cpu_features.h"
16
17#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
18#error "Invalid include"
19#endif
20
21#include "src/__support/FPUtil/generic/sqrt.h"
22
23namespace LIBC_NAMESPACE_DECL {
24namespace fputil {
25
26#ifdef LIBC_TARGET_CPU_HAS_FPU_FLOAT
27template <> LIBC_INLINE float sqrt<float>(float x) {
28 float result;
29 asm("fsqrt.s %0, %1\n\t" : "=f"(result) : "f"(x));
30 return result;
31}
32#endif // LIBC_TARGET_CPU_HAS_FPU_FLOAT
33
34#ifdef LIBC_TARGET_CPU_HAS_FPU_DOUBLE
35template <> LIBC_INLINE double sqrt<double>(double x) {
36 double result;
37 asm("fsqrt.d %0, %1\n\t" : "=f"(result) : "f"(x));
38 return result;
39}
40#endif // LIBC_TARGET_CPU_HAS_FPU_FLOAT
41
42} // namespace fputil
43} // namespace LIBC_NAMESPACE_DECL
44
45#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H
46

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libc/src/__support/FPUtil/riscv/sqrt.h