From 5699dfd895e98a20061b1a6dee197b5377565525 Mon Sep 17 00:00:00 2001 From: affggh <46290091+affggh@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:49:09 +0800 Subject: [PATCH] kptools: Fix shift overflow warning on windows (#57) * kptools: Force use ull on all platforms * kptools: Use GENMASK_ULL macro define on windows platform --- tools/fls_ffs.h | 12 ++++++------ tools/insn.c | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/fls_ffs.h b/tools/fls_ffs.h index 3367b1a3..de0c0a0e 100644 --- a/tools/fls_ffs.h +++ b/tools/fls_ffs.h @@ -45,28 +45,28 @@ static inline uint64_t __fls(uint64_t word) int num = BITS_PER_LONG - 1; #if BITS_PER_LONG == 64 - if (!(word & (~0ul << 32))) { + if (!(word & (~0ull << 32))) { num -= 32; word <<= 32; } #endif - if (!(word & (~0ul << (BITS_PER_LONG - 16)))) { + if (!(word & (~0ull << (BITS_PER_LONG - 16)))) { num -= 16; word <<= 16; } - if (!(word & (~0ul << (BITS_PER_LONG - 8)))) { + if (!(word & (~0ull << (BITS_PER_LONG - 8)))) { num -= 8; word <<= 8; } - if (!(word & (~0ul << (BITS_PER_LONG - 4)))) { + if (!(word & (~0ull << (BITS_PER_LONG - 4)))) { num -= 4; word <<= 4; } - if (!(word & (~0ul << (BITS_PER_LONG - 2)))) { + if (!(word & (~0ull << (BITS_PER_LONG - 2)))) { num -= 2; word <<= 2; } - if (!(word & (~0ul << (BITS_PER_LONG - 1)))) num -= 1; + if (!(word & (~0ull << (BITS_PER_LONG - 1)))) num -= 1; return num; } diff --git a/tools/insn.c b/tools/insn.c index 6679a11e..e025cfa7 100644 --- a/tools/insn.c +++ b/tools/insn.c @@ -106,7 +106,12 @@ static inline uint64_t hweight64(u64 w) * position @h. For example * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. */ +#ifndef _WIN32 #define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) +#else +#define GENMASK GENMASK_ULL +#define BITS_PER_LONG_LONG 64 +#endif #define GENMASK_ULL(h, l) (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) /*