Skip to content

Commit

Permalink
Merge pull request #72 from howjmay/rcp
Browse files Browse the repository at this point in the history
feat: Add _mm_rcp_[ps|ss]
  • Loading branch information
howjmay authored Jan 27, 2024
2 parents 33badd5 + 029ee45 commit b0befa1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
13 changes: 11 additions & 2 deletions sse2rvv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2572,9 +2572,18 @@ FORCE_INLINE __m64 _m_pshufw(__m64 a, int imm8) {
return _mm_shuffle_pi16(a, imm8);
}

// FORCE_INLINE __m128 _mm_rcp_ps (__m128 a) {}
FORCE_INLINE __m128 _mm_rcp_ps(__m128 a) {
// TODO add high precision mode
vfloat32m1_t _a = vreinterpretq_m128_f32(a);
return vreinterpretq_f32_m128(__riscv_vfrec7_v_f32m1(_a, 4));
}

// FORCE_INLINE __m128 _mm_rcp_ss (__m128 a) {}
FORCE_INLINE __m128 _mm_rcp_ss(__m128 a) {
// TODO add high precision mode
vfloat32m1_t _a = vreinterpretq_m128_f32(a);
vfloat32m1_t recip = __riscv_vfrec7_v_f32m1(_a, 4);
return vreinterpretq_f32_m128(__riscv_vslideup_vx_f32m1(_a, recip, 0, 1));
}

// FORCE_INLINE __m128d _mm_round_pd (__m128d a, int rounding) {}

Expand Down
48 changes: 24 additions & 24 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3017,35 +3017,35 @@ result_t test_m_pshufw(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
}

result_t test_mm_rcp_ps(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// const float *_a = impl.test_cases_float_pointer1;
// float dx = 1.0f / _a[0];
// float dy = 1.0f / _a[1];
// float dz = 1.0f / _a[2];
// float dw = 1.0f / _a[3];
//
// __m128 a = load_m128(_a);
// __m128 c = _mm_rcp_ps(a);
// return validate_float_error(c, dx, dy, dz, dw, 0.001f);
// #else
#ifdef ENABLE_TEST_ALL
const float *_a = impl.test_cases_float_pointer1;
float _c[4];
for (int i = 0; i < 4; i++) {
_c[i] = 1.0f / _a[i];
}

__m128 a = load_m128(_a);
__m128 c = _mm_rcp_ps(a);
return validate_float_error(c, _c[0], _c[1], _c[2], _c[3], 0.01f);
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

result_t test_mm_rcp_ss(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// const float *_a = impl.test_cases_float_pointer1;
//
// float dx = 1.0f / _a[0];
// float dy = _a[1];
// float dz = _a[2];
// float dw = _a[3];
// __m128 a = load_m128(_a);
// __m128 c = _mm_rcp_ss(a);
// return validate_float_error(c, dx, dy, dz, dw, 0.001f);
// #else
#ifdef ENABLE_TEST_ALL
const float *_a = impl.test_cases_float_pointer1;
float _c[4];
_c[0] = 1.0f / _a[0];
_c[1] = _a[1];
_c[2] = _a[2];
_c[3] = _a[3];
__m128 a = load_m128(_a);
__m128 c = _mm_rcp_ss(a);
return validate_float_error(c, _c[0], _c[1], _c[2], _c[3], 0.01f);
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

result_t test_mm_rsqrt_ps(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
Expand Down

0 comments on commit b0befa1

Please sign in to comment.