From 727f5b3fc6bb10da6a9803ec6bdd21fe78a83b4f Mon Sep 17 00:00:00 2001 From: anthony-zy Date: Mon, 10 Nov 2025 10:37:19 +0800 Subject: [PATCH] add zbb check macro --- snappy-stubs-internal.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/snappy-stubs-internal.h b/snappy-stubs-internal.h index 526c38b..0b0e726 100644 --- a/snappy-stubs-internal.h +++ b/snappy-stubs-internal.h @@ -304,7 +304,10 @@ class Bits { void operator=(const Bits&); }; -#if HAVE_BUILTIN_CTZ +// Check if the built-in __builtin_ctz (count trailing zeros) is available. +// Require either a non-RISC-V target, or a RISC-V core that implements +// the Zbb bit-manipulation extension where ctz is guaranteed. +#if HAVE_BUILTIN_CTZ && (!defined(__riscv) || defined(__riscv_zbb)) inline int Bits::Log2FloorNonZero(uint32_t n) { assert(n != 0); @@ -393,7 +396,10 @@ inline int Bits::FindLSBSetNonZero(uint32_t n) { #endif // End portable versions. -#if HAVE_BUILTIN_CTZ +// Check if the built-in __builtin_ctz (count trailing zeros) is available. +// Require either a non-RISC-V target, or a RISC-V core that implements +// the Zbb bit-manipulation extension where ctz is guaranteed. +#if HAVE_BUILTIN_CTZ && (!defined(__riscv) || defined(__riscv_zbb)) inline int Bits::FindLSBSetNonZero64(uint64_t n) { assert(n != 0);