From 039e56d9f895ef9c938b2748a26f881537d2f1c4 Mon Sep 17 00:00:00 2001 From: Yang Hau Date: Thu, 25 Jul 2024 16:47:40 +0800 Subject: [PATCH] feat: Add vrsqrte[s|d]_[f32|f64] --- neon2rvv.h | 4 ++-- tests/impl.cpp | 26 ++++++++++++++++++++++++-- tests/impl.h | 4 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/neon2rvv.h b/neon2rvv.h index 245fbde3..313e58c0 100644 --- a/neon2rvv.h +++ b/neon2rvv.h @@ -7259,9 +7259,9 @@ FORCE_INLINE float64x1_t vrsqrte_f64(float64x1_t a) { return __riscv_vfrsqrt7_v_ FORCE_INLINE float64x2_t vrsqrteq_f64(float64x2_t a) { return __riscv_vfrsqrt7_v_f64m1(a, 2); } -// FORCE_INLINE float32_t vrsqrtes_f32(float32_t a); +FORCE_INLINE float32_t vrsqrtes_f32(float32_t a) { return 1 / sqrtf(a); } -// FORCE_INLINE float64_t vrsqrted_f64(float64_t a); +FORCE_INLINE float64_t vrsqrted_f64(float64_t a) { return 1 / sqrt(a); } // FORCE_INLINE uint32x4_t vrsqrteq_u32(uint32x4_t a); diff --git a/tests/impl.cpp b/tests/impl.cpp index b3a58a8b..f01084f8 100644 --- a/tests/impl.cpp +++ b/tests/impl.cpp @@ -25845,9 +25845,31 @@ result_t test_vrsqrteq_f64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { #endif // ENABLE_TEST_ALL } -result_t test_vrsqrtes_f32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; } +result_t test_vrsqrtes_f32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { +#ifdef ENABLE_TEST_ALL + const float *_a = impl.test_cases_float_pointer1; + float _c, c; + _c = 1 / sqrtf(_a[0]); + + c = vrsqrtes_f32(_a[0]); + return validate_float_error(c, _c, 0.01f); +#else + return TEST_UNIMPL; +#endif // ENABLE_TEST_ALL +} -result_t test_vrsqrted_f64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; } +result_t test_vrsqrted_f64(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { +#ifdef ENABLE_TEST_ALL + const double *_a = (const double *)impl.test_cases_float_pointer1; + double _c, c; + _c = 1 / sqrt(_a[0]); + + c = vrsqrted_f64(_a[0]); + return validate_double_error(c, _c, 0.01f); +#else + return TEST_UNIMPL; +#endif // ENABLE_TEST_ALL +} result_t test_vrsqrteq_u32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_UNIMPL; } diff --git a/tests/impl.h b/tests/impl.h index 47d95dc5..f7ae14bf 100644 --- a/tests/impl.h +++ b/tests/impl.h @@ -1401,8 +1401,8 @@ _(vrsqrteq_f32) \ _(vrsqrte_f64) \ _(vrsqrteq_f64) \ - /*_(vrsqrtes_f32) */ \ - /*_(vrsqrted_f64) */ \ + _(vrsqrtes_f32) \ + _(vrsqrted_f64) \ _(vrsqrteq_u32) \ _(vget_lane_s8) \ _(vget_lane_s16) \