MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / bitScanReverse

Function bitScanReverse

src/Core/src/Numerics.cpp:39–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 }
38
39 int32_t bitScanReverse(uint32_t source)
40 {
41#if defined(_MSC_VER) && (_MSC_VER >= 1400) // Visual Studio 2005
42 unsigned long i;
43 uint8_t success = _BitScanReverse(&i, source);
44 return success != 0 ? i : -1;
45#elif defined(__GNUC__)
46 auto result = source == 0 ? -1 : __builtin_clz(source) ^ 31;
47 return result;
48#else
49#pragma message "Falling back to iterative bitscan reverse, consider using intrinsics"
50 if (source != 0)
51 {
52 for (int32_t i = 31; i > -1; i--)
53 {
54 if (source & (1u << i))
55 {
56 return i;
57 }
58 }
59 }
60 return -1;
61#endif
62 }
63}

Callers 8

drawScrollFunction · 0.85
updateBuildingColoursFunction · 0.85
updateTreeColoursFunction · 0.85
drawTreeThumbFunction · 0.85
drawIndustryMethod · 0.85
drawPreviewImageMethod · 0.85
drawPreviewImageMethod · 0.85
TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68