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

Function bitScanForward

src/Core/src/Numerics.cpp:14–37  ·  view source on GitHub ↗

Finds the first bit set in a 32-bits numeral and returns its index, or -1 if no bit is set.

Source from the content-addressed store, hash-verified

12{
13 // Finds the first bit set in a 32-bits numeral and returns its index, or -1 if no bit is set.
14 int32_t bitScanForward(uint32_t source)
15 {
16#if defined(_MSC_VER) && (_MSC_VER >= 1400) // Visual Studio 2005
17 unsigned long i;
18 uint8_t success = _BitScanForward(&i, source);
19 return success != 0 ? i : -1;
20#elif defined(__GNUC__)
21 auto result = __builtin_ffs(source);
22 return result - 1;
23#else
24#pragma message "Falling back to iterative bitscan forward, consider using intrinsics"
25 if (source != 0)
26 {
27 for (int32_t i = 0; i < 32; i++)
28 {
29 if (source & (1u << i))
30 {
31 return i;
32 }
33 }
34 }
35 return -1;
36#endif
37 }
38
39 int32_t bitScanReverse(uint32_t source)
40 {

Callers 15

updateMonthlyMethod · 0.85
estimateThoughtRevenueFunction · 0.85
setMapPixelsRoutesFunction · 0.85
formatVehicleStringFunction · 0.85
formatIndustryStringFunction · 0.85
getRouteColourFunction · 0.85
assignIndustryColoursFunction · 0.85
assignRouteColoursFunction · 0.85
onRefitButtonFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68