diff options
author | frosch <frosch@openttd.org> | 2021-12-12 17:35:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-12 17:35:41 +0100 |
commit | bc22e9333e838c73ce27eff6db7a812fab93e638 (patch) | |
tree | ece39b4a4ff778e8eaa260daf1064370813dac5d /src | |
parent | 762b656b53680f64a1d48d8c17d18570ed7b82b1 (diff) | |
download | openttd-bc22e9333e838c73ce27eff6db7a812fab93e638.tar.xz |
Fix: if vehicles only refit to cargo-slots >= 32, the default cargo was wrong. (#9744)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/bitmath_func.cpp | 15 | ||||
-rw-r--r-- | src/core/bitmath_func.hpp | 2 |
2 files changed, 9 insertions, 8 deletions
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); /** |