brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 8cff03a Raw
46 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H10#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H11 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#endif20 21#include "src/__support/FPUtil/generic/sqrt.h"22 23namespace LIBC_NAMESPACE_DECL {24namespace fputil {25 26#ifdef LIBC_TARGET_CPU_HAS_FPU_FLOAT27template <> 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_FLOAT33 34#ifdef LIBC_TARGET_CPU_HAS_FPU_DOUBLE35template <> 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_FLOAT41 42} // namespace fputil43} // namespace LIBC_NAMESPACE_DECL44 45#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H46