Skip to content

[libc][riscv] Check if we have F or D extension before using them #79036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libc/src/__support/FPUtil/riscv/FMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace LIBC_NAMESPACE {
namespace fputil {

#ifdef __riscv_flen
template <typename T>
LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
float result;
Expand All @@ -35,6 +36,7 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
return result;
}

#if __riscv_flen >= 64
template <typename T>
LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y, T z) {
double result;
Expand All @@ -43,6 +45,8 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y, T z) {
: "f"(x), "f"(y), "f"(z));
return result;
}
#endif // __riscv_flen >= 64
#endif // __riscv_flen

} // namespace fputil
} // namespace LIBC_NAMESPACE
Expand Down
4 changes: 4 additions & 0 deletions libc/src/__support/FPUtil/riscv/sqrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@
namespace LIBC_NAMESPACE {
namespace fputil {

#ifdef __riscv_flen
template <> LIBC_INLINE float sqrt<float>(float x) {
float result;
__asm__ __volatile__("fsqrt.s %0, %1\n\t" : "=f"(result) : "f"(x));
return result;
}

#if __riscv_flen >= 64
template <> LIBC_INLINE double sqrt<double>(double x) {
double result;
__asm__ __volatile__("fsqrt.d %0, %1\n\t" : "=f"(result) : "f"(x));
return result;
}
#endif // __riscv_flen >= 64
#endif // __riscv_flen

} // namespace fputil
} // namespace LIBC_NAMESPACE
Expand Down