| |
| |
| |
| |
| |
| |
| |
|
|
| #include "src/math/cospif.h" |
| #include "sincosf_utils.h" |
| #include "src/__support/FPUtil/FEnvImpl.h" |
| #include "src/__support/FPUtil/FPBits.h" |
| #include "src/__support/FPUtil/multiply_add.h" |
| #include "src/__support/common.h" |
| #include "src/__support/macros/config.h" |
| #include "src/__support/macros/optimization.h" |
| #include "src/__support/macros/properties/cpu_features.h" |
|
|
| namespace LIBC_NAMESPACE_DECL { |
|
|
| LLVM_LIBC_FUNCTION(float, cospif, (float x)) { |
| using FPBits = typename fputil::FPBits<float>; |
|
|
| FPBits xbits(x); |
| xbits.set_sign(Sign::POS); |
|
|
| uint32_t x_abs = xbits.uintval(); |
| double xd = static_cast<double>(xbits.get_val()); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| if (LIBC_UNLIKELY(x_abs < 0x38A2'F984U)) { |
|
|
| #if defined(LIBC_TARGET_CPU_HAS_FMA_FLOAT) |
| return fputil::multiply_add(xbits.get_val(), -0x1.0p-25f, 1.0f); |
| #else |
| return static_cast<float>(fputil::multiply_add(xd, -0x1.0p-25, 1.0)); |
| #endif |
| } |
|
|
| |
| if (LIBC_UNLIKELY(x_abs >= 0x4B00'0000)) { |
|
|
| if (LIBC_UNLIKELY(x_abs < 0x4B80'0000)) { |
| return (x_abs & 0x1) ? -1.0f : 1.0f; |
| } |
|
|
| |
| if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) { |
| if (xbits.is_signaling_nan()) { |
| fputil::raise_except_if_required(FE_INVALID); |
| return FPBits::quiet_nan().get_val(); |
| } |
|
|
| if (x_abs == 0x7f80'0000U) { |
| fputil::set_errno_if_required(EDOM); |
| fputil::raise_except_if_required(FE_INVALID); |
| } |
| return x + FPBits::quiet_nan().get_val(); |
| } |
|
|
| return 1.0f; |
| } |
|
|
| |
| |
| |
| |
| |
| double sin_k, cos_k, sin_y, cosm1_y; |
|
|
| sincospif_eval(xd, sin_k, cos_k, sin_y, cosm1_y); |
|
|
| if (LIBC_UNLIKELY(sin_y == 0 && cos_k == 0)) { |
| return 0.0f; |
| } |
|
|
| return static_cast<float>(fputil::multiply_add( |
| sin_y, -sin_k, fputil::multiply_add(cosm1_y, cos_k, cos_k))); |
| } |
|
|
| } |
|
|