mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #2939 from janisozaur/perf
Use GCC's __builtin_ffs for bitscanforward impl
This commit is contained in:
commit
9fd24651f9
|
@ -158,7 +158,14 @@ int bitscanforward(int source)
|
||||||
#if _MSC_VER >= 1400 // Visual Studio 2005
|
#if _MSC_VER >= 1400 // Visual Studio 2005
|
||||||
uint8 success = _BitScanForward(&i, source);
|
uint8 success = _BitScanForward(&i, source);
|
||||||
return success != 0 ? i : -1;
|
return success != 0 ? i : -1;
|
||||||
|
#elif __GNUC__
|
||||||
|
int success = __builtin_ffs(source);
|
||||||
|
return success - 1;
|
||||||
#else
|
#else
|
||||||
|
#pragma message "Falling back to iterative bitscan forward, consider using intrinsics"
|
||||||
|
// This is a low-hanging optimisation boost, check if your compiler offers
|
||||||
|
// any intrinsic.
|
||||||
|
// cf. https://github.com/OpenRCT2/OpenRCT2/pull/2093
|
||||||
for (i = 0; i < 32; i++)
|
for (i = 0; i < 32; i++)
|
||||||
if (source & (1u << i))
|
if (source & (1u << i))
|
||||||
return i;
|
return i;
|
||||||
|
|
Loading…
Reference in New Issue