]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Always use zng_ctz32 for W_BITS calculation
authorNathan Moinvaziri <nathan@nathanm.com>
Mon, 26 Jan 2026 08:43:10 +0000 (00:43 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 6 Feb 2026 13:52:54 +0000 (14:52 +0100)
deflate.h

index 5235ce9d187f983ecc1871c6cb8f06a9ef07d8f4..92d3d2269cf4b37b189963be84fa0b86903e20a0 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -392,27 +392,7 @@ static inline void put_uint64(deflate_state *s, uint64_t lld) {
 #define W_MASK(s)  ((s)->w_size - 1)
 /* Window mask: w_size is always a power of 2, so w_mask = w_size - 1 */
 
-#ifdef HAVE_BUILTIN_CTZ
-#  define W_BITS(s)  ((unsigned int)__builtin_ctz((s)->w_size))
-#else
-/* Fallback for w_size which is always a power of 2 between 256 and 32768 */
-static inline unsigned int compute_w_bits(unsigned int w_size) {
-    /* Switch ordered by likelihood - most common first (MAX_WBITS=15 -> 32768) */
-    switch (w_size) {
-        case 32768: return 15;  /* MAX_WBITS default */
-        case 16384: return 14;
-        case  8192: return 13;
-        case  4096: return 12;
-        case  2048: return 11;
-        case  1024: return 10;
-        case   512: return  9;
-        case   256: return  8;
-    }
-    Assert(w_size >= 256 && w_size <= 32768, "invalid w_size");
-    return 0;
-}
-#  define W_BITS(s)  compute_w_bits((s)->w_size)
-#endif
+#define W_BITS(s)  zng_ctz32((s)->w_size)
 /* Window bits: log2(w_size), computed from w_size since w_size is a power of 2 */
 
 #define WIN_INIT STD_MAX_MATCH