From bc22e9333e838c73ce27eff6db7a812fab93e638 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 12 Dec 2021 17:35:41 +0100 Subject: Fix: if vehicles only refit to cargo-slots >= 32, the default cargo was wrong. (#9744) --- src/core/bitmath_func.cpp | 15 ++++++++------- src/core/bitmath_func.hpp | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/core/bitmath_func.cpp b/src/core/bitmath_func.cpp index 803eb9e1c..206c04e54 100644 --- a/src/core/bitmath_func.cpp +++ b/src/core/bitmath_func.cpp @@ -24,7 +24,7 @@ const uint8 _ffb_64[64] = { }; /** - * Search the first set bit in a 32 bit variable. + * Search the first set bit in a 64 bit variable. * * This algorithm is a static implementation of a log * congruence search algorithm. It checks the first half @@ -34,7 +34,7 @@ const uint8 _ffb_64[64] = { * @param x The value to search * @return The position of the first bit set */ -uint8 FindFirstBit(uint32 x) +uint8 FindFirstBit(uint64 x) { if (x == 0) return 0; /* The macro FIND_FIRST_BIT is better to use when your x is @@ -42,11 +42,12 @@ uint8 FindFirstBit(uint32 x) uint8 pos = 0; - if ((x & 0x0000ffff) == 0) { x >>= 16; pos += 16; } - if ((x & 0x000000ff) == 0) { x >>= 8; pos += 8; } - if ((x & 0x0000000f) == 0) { x >>= 4; pos += 4; } - if ((x & 0x00000003) == 0) { x >>= 2; pos += 2; } - if ((x & 0x00000001) == 0) { pos += 1; } + if ((x & 0xffffffffULL) == 0) { x >>= 32; pos += 32; } + if ((x & 0x0000ffffULL) == 0) { x >>= 16; pos += 16; } + if ((x & 0x000000ffULL) == 0) { x >>= 8; pos += 8; } + if ((x & 0x0000000fULL) == 0) { x >>= 4; pos += 4; } + if ((x & 0x00000003ULL) == 0) { x >>= 2; pos += 2; } + if ((x & 0x00000001ULL) == 0) { pos += 1; } return pos; } diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp index be0d8cd54..979d9b73b 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -222,7 +222,7 @@ static inline uint8 FindFirstBit2x64(const int value) } } -uint8 FindFirstBit(uint32 x); +uint8 FindFirstBit(uint64 x); uint8 FindLastBit(uint64 x); /** -- cgit v1.2.3-70-g09d2