Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/butil/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,19 +814,41 @@ static bool isSSE42() {

typedef uint32_t (*Function)(uint32_t, const char*, size_t);

#if defined(__riscv) && (__riscv_xlen == 64) && defined(__riscv_zbc) && defined(__riscv_zvbc)
// Both Zbc and Zvbc: scalar is cheaper for small inputs, the vector fold
// wins from ~256 B on.
static constexpr size_t kRiscvVclmulThresholdBytes = 256;
static uint32_t RiscvExtend(uint32_t crc, const char* buf, size_t size) {
return (size >= kRiscvVclmulThresholdBytes ? rv_crc32c_vclmul : rv_crc32c_clmul)(crc, buf, size);
}
#endif

static inline Function Choose_Extend() {
#ifdef __SSE4_2__
if (isSSE42()) {
return (Function)ExtendImpl<FastCRC32Functor>;
}
#endif
#if defined(__riscv) && (__riscv_xlen == 64) && (defined(__riscv_zbc) || defined(__riscv_zvbc))
#if defined(__riscv_zvbc)
#if defined(__riscv_zbc) && defined(__riscv_zvbc)
{
static const bool has_zbc = is_zbc();
static const bool has_zvbc = is_zvbc();
if (has_zbc && has_zvbc) {
return (Function)RiscvExtend;
}
if (has_zvbc) {
return (Function)rv_crc32c_vclmul;
}
if (has_zbc) {
return (Function)rv_crc32c_clmul;
}
}
#elif defined(__riscv_zvbc)

@Felix-Gong Felix-Gong Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to #elif defined(__riscv_zbc). The outer condition already requires zbc or zvbc, so behavior is unchanged, but writing it out makes the intent clear if that condition is ever edited.

if (is_zvbc()) {
return (Function)rv_crc32c_vclmul;
}
#endif
#if defined(__riscv_zbc)
#elif defined(__riscv_zbc)
if (is_zbc()) {
return (Function)rv_crc32c_clmul;
}
Expand Down
Loading