Merge branch 'add_rvv_support' of https://github.com/anthony-zy/snappy into add_rvv_support

This commit is contained in:
anthony-zy
2025-08-28 20:42:49 +08:00

View File

@@ -1288,42 +1288,43 @@ void MemCopy64(char* dst, const void* src, size_t size) {
data = _mm256_lddqu_si256(static_cast<const __m256i *>(src) + 1); data = _mm256_lddqu_si256(static_cast<const __m256i *>(src) + 1);
_mm256_storeu_si256(reinterpret_cast<__m256i *>(dst) + 1, data); _mm256_storeu_si256(reinterpret_cast<__m256i *>(dst) + 1, data);
} }
#else // RVV acceleration available on RISC-V when compiled with -march=rv64gcv
#ifdef SNAPPY_HAVE_RVV #elif defined(__riscv) & SNAPPY_HAVE_RVV
uint8_t* dst_u8 = (uint8_t*)dst; uint8_t* dst_u8 = (uint8_t*)dst;
const uint8_t* src_u8 = (const uint8_t*)src; const uint8_t* src_u8 = (const uint8_t*)src;
if (src_u8 < dst_u8 && dst_u8 < src_u8 + size) { //overlap bwd copy //overlap bwd copy
size_t offset = size; if (src_u8 < dst_u8 && dst_u8 < src_u8 + size) {
while (offset > 0) { size_t offset = size;
size_t vl = VSETVL_E8M1(offset); while (offset > 0) {
offset -= vl; size_t vl = VSETVL_E8M1(offset);
vuint8m1_t vec = VLE8_V_U8M1(src_u8 + offset, vl); offset -= vl;
VSE8_V_U8M1(dst_u8 + offset, vec, vl); vuint8m1_t vec = VLE8_V_U8M1(src_u8 + offset, vl);
} VSE8_V_U8M1(dst_u8 + offset, vec, vl);
} else { }
size_t vl = VSETVL_E8M1(size); } else {
if (vl < size) { // if size >vl,use the max_vlen copy size_t vl = VSETVL_E8M1(size);
size_t offset = 0; // if size >vl,use the max_vlen copy
while (offset < size) { if (vl < size) {
vl = VSETVL_E8M1(size - offset); size_t offset = 0;
vuint8m1_t vec = VLE8_V_U8M1(src_u8 + offset, vl); while (offset < size) {
VSE8_V_U8M1(dst_u8 + offset, vec, vl); vl = VSETVL_E8M1(size - offset);
offset += vl; vuint8m1_t vec = VLE8_V_U8M1(src_u8 + offset, vl);
} VSE8_V_U8M1(dst_u8 + offset, vec, vl);
} else { // copy the leaft offset += vl;
vuint8m1_t vec = VLE8_V_U8M1(src_u8, vl); }
VSE8_V_U8M1(dst_u8, vec, vl); } else {
// Copy the rest
vuint8m1_t vec = VLE8_V_U8M1(src_u8, vl);
VSE8_V_U8M1(dst_u8, vec, vl);
}
} }
}
#else #else
std::memmove(dst, src, kShortMemCopy); std::memmove(dst, src, kShortMemCopy);
//Profiling shows that nearly all copies are short. //Profiling shows that nearly all copies are short.
if (SNAPPY_PREDICT_FALSE(size > kShortMemCopy)) { if (SNAPPY_PREDICT_FALSE(size > kShortMemCopy)) {
std::memmove(dst + kShortMemCopy, std::memmove(dst + kShortMemCopy,
static_cast<const uint8_t*>(src) + kShortMemCopy, static_cast<const uint8_t*>(src) + kShortMemCopy,
64 - kShortMemCopy);} 64 - kShortMemCopy);}
#endif
#endif #endif
} }