Skip to content

Commit

Permalink
Merge pull request #70 from howjmay/crc
Browse files Browse the repository at this point in the history
feat: Add _mm_crc32_[u8|u16|u32|u64]
  • Loading branch information
howjmay authored Jan 27, 2024
2 parents b8476ea + 2f71a63 commit 53f6600
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 42 deletions.
31 changes: 25 additions & 6 deletions sse2rvv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1326,15 +1326,34 @@ FORCE_INLINE int _mm_comineq_ss(__m128 a, __m128 b) {
0x1;
}

// FORCE_INLINE unsigned int _mm_crc32_u16 (unsigned int crc, unsigned short v)
// {}
FORCE_INLINE unsigned int _mm_crc32_u8(unsigned int crc, unsigned char v) {
crc ^= v;
for (int bit = 0; bit < 8; bit++) {
if (crc & 1)
crc = (crc >> 1) ^ UINT32_C(0x82f63b78);
else
crc = (crc >> 1);
}
return crc;
}

// FORCE_INLINE unsigned int _mm_crc32_u32 (unsigned int crc, unsigned int v) {}
FORCE_INLINE unsigned int _mm_crc32_u16(unsigned int crc, unsigned short v) {
crc = _mm_crc32_u8(crc, v & UINT8_MAX);
crc = _mm_crc32_u8(crc, (v >> 8) & UINT8_MAX);
return crc;
}

// FORCE_INLINE unsigned __int64 _mm_crc32_u64 (unsigned __int64 crc, unsigned
// __int64 v) {}
FORCE_INLINE unsigned int _mm_crc32_u32(unsigned int crc, unsigned int v) {
crc = _mm_crc32_u16(crc, v & UINT16_MAX);
crc = _mm_crc32_u16(crc, (v >> 16) & UINT16_MAX);
return crc;
}

// FORCE_INLINE unsigned int _mm_crc32_u8 (unsigned int crc, unsigned char v) {}
FORCE_INLINE __int64 _mm_crc32_u64(__int64 crc, __int64 v) {
crc = _mm_crc32_u32((uint32_t)(crc), v & UINT32_MAX);
crc = _mm_crc32_u32((uint32_t)(crc), (v >> 32) & UINT32_MAX);
return crc;
}

FORCE_INLINE __m128 _mm_cvt_pi2ps(__m128 a, __m64 b) {
vfloat32m1_t _a = vreinterpretq_m128_f32(a);
Expand Down
64 changes: 32 additions & 32 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10877,51 +10877,51 @@ result_t test_mm_cmpistrz(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
}

result_t test_mm_crc32_u16(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// uint32_t crc = *(const uint32_t *)impl.test_cases_int_pointer1;
// uint16_t v = iter;
// uint32_t result = _mm_crc32_u16(crc, v);
// ASSERT_RETURN(result == canonical_crc32_u16(crc, v));
// return TEST_SUCCESS;
// #else
#ifdef ENABLE_TEST_ALL
uint32_t crc = *(const uint32_t *)impl.test_cases_int_pointer1;
uint16_t v = iter;
uint32_t result = _mm_crc32_u16(crc, v);
ASSERT_RETURN(result == canonical_crc32_u16(crc, v));
return TEST_SUCCESS;
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

result_t test_mm_crc32_u32(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// uint32_t crc = *(const uint32_t *)impl.test_cases_int_pointer1;
// uint32_t v = *(const uint32_t *)impl.test_cases_int_pointer2;
// uint32_t result = _mm_crc32_u32(crc, v);
// ASSERT_RETURN(result == canonical_crc32_u32(crc, v));
// return TEST_SUCCESS;
// #else
#ifdef ENABLE_TEST_ALL
uint32_t crc = *(const uint32_t *)impl.test_cases_int_pointer1;
uint32_t v = *(const uint32_t *)impl.test_cases_int_pointer2;
uint32_t result = _mm_crc32_u32(crc, v);
ASSERT_RETURN(result == canonical_crc32_u32(crc, v));
return TEST_SUCCESS;
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

result_t test_mm_crc32_u64(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// uint64_t crc = *(const uint64_t *)impl.test_cases_int_pointer1;
// uint64_t v = *(const uint64_t *)impl.test_cases_int_pointer2;
// uint64_t result = _mm_crc32_u64(crc, v);
// ASSERT_RETURN(result == canonical_crc32_u64(crc, v));
// return TEST_SUCCESS;
// #else
#ifdef ENABLE_TEST_ALL
uint64_t crc = *(const uint64_t *)impl.test_cases_int_pointer1;
uint64_t v = *(const uint64_t *)impl.test_cases_int_pointer2;
uint64_t result = _mm_crc32_u64(crc, v);
ASSERT_RETURN(result == canonical_crc32_u64(crc, v));
return TEST_SUCCESS;
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

result_t test_mm_crc32_u8(const SSE2RVV_TEST_IMPL &impl, uint32_t iter) {
// #ifdef ENABLE_TEST_ALL
// uint32_t crc = *(const uint32_t *)impl.test_cases_int_pointer1;
// uint8_t v = iter;
// uint32_t result = _mm_crc32_u8(crc, v);
// ASSERT_RETURN(result == canonical_crc32_u8(crc, v));
// return TEST_SUCCESS;
// #else
#ifdef ENABLE_TEST_ALL
uint32_t crc = *(const uint32_t *)impl.test_cases_int_pointer1;
uint8_t v = iter;
uint32_t result = _mm_crc32_u8(crc, v);
ASSERT_RETURN(result == canonical_crc32_u8(crc, v));
return TEST_SUCCESS;
#else
return TEST_UNIMPL;
// #endif // ENABLE_TEST_ALL
#endif // ENABLE_TEST_ALL
}

/* AES */
Expand Down
8 changes: 4 additions & 4 deletions tests/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,10 @@
/*_(mm_cmpistro) */ \
/*_(mm_cmpistrs) */ \
/*_(mm_cmpistrz) */ \
/*_(mm_crc32_u16) */ \
/*_(mm_crc32_u32) */ \
/*_(mm_crc32_u64) */ \
/*_(mm_crc32_u8) */ \
_(mm_crc32_u16) \
_(mm_crc32_u32) \
_(mm_crc32_u64) \
_(mm_crc32_u8) \
/* AES */ \
_(mm_aesenc_si128) \
_(mm_aesdec_si128) \
Expand Down

0 comments on commit 53f6600

Please sign in to comment.