From: Yann Collet Date: Tue, 22 Oct 2024 22:12:46 +0000 (-0700) Subject: made ZSTD_isPower2() an inline function X-Git-Tag: v1.5.7^2~71^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bad787d8bcae57cf0bdcbca00b3f106ae557b75;p=thirdparty%2Fzstd.git made ZSTD_isPower2() an inline function --- diff --git a/lib/common/compiler.h b/lib/common/compiler.h index f4caeb5c0..b6cbcee03 100644 --- a/lib/common/compiler.h +++ b/lib/common/compiler.h @@ -278,7 +278,11 @@ * Alignment check *****************************************************************/ -#define ZSTD_IS_POWER_2(a) (((a) & ((a)-1)) == 0) +/* @return 1 if @u is a 2^n value, 0 otherwise + * useful to check a value is valid for alignment restrictions */ +MEM_STATIC int ZSTD_isPower2(size_t u) { + return (u & (u-1)) == 0; +} /* this test was initially positioned in mem.h, * but this file is removed (or replaced) for linux kernel diff --git a/lib/compress/zstd_cwksp.h b/lib/compress/zstd_cwksp.h index dc0142098..77715e22e 100644 --- a/lib/compress/zstd_cwksp.h +++ b/lib/compress/zstd_cwksp.h @@ -208,7 +208,7 @@ MEM_STATIC void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp* ws) { */ MEM_STATIC size_t ZSTD_cwksp_align(size_t size, size_t align) { size_t const mask = align - 1; - assert(ZSTD_IS_POWER_2(align)); + assert(ZSTD_isPower2(align)); return (size + mask) & ~mask; } @@ -266,7 +266,7 @@ MEM_STATIC size_t ZSTD_cwksp_slack_space_required(void) { MEM_STATIC size_t ZSTD_cwksp_bytes_to_align_ptr(void* ptr, const size_t alignBytes) { size_t const alignBytesMask = alignBytes - 1; size_t const bytes = (alignBytes - ((size_t)ptr & (alignBytesMask))) & alignBytesMask; - assert(ZSTD_IS_POWER_2(alignBytes)); + assert(ZSTD_isPower2(alignBytes)); assert(bytes < alignBytes); return bytes; } @@ -536,7 +536,7 @@ MEM_STATIC void* ZSTD_cwksp_reserve_object_aligned(ZSTD_cwksp* ws, size_t byteSi void* const start = ZSTD_cwksp_reserve_object(ws, byteSize + surplus); if (start == NULL) return NULL; if (surplus == 0) return start; - assert(ZSTD_IS_POWER_2(alignment)); + assert(ZSTD_isPower2(alignment)); return (void*)(((size_t)start + surplus) & ~mask); }