RSBinToGroups() use __builtin_clz() instead of manual bsr if available

should be faster.
This commit is contained in:
Daniel Gibson 2016-04-22 19:40:09 +02:00
parent 46353ffc5d
commit c58328d881

View File

@ -499,7 +499,15 @@ static void RSBinToGroups( ScenePolygon *pspoFirst)
);
#else
// emulate x86's bsr opcode...not fast. :/
// emulate x86's bsr opcode...
// GCC and clang have an architecture-independent intrinsic for this
// (it counts leading zeros starting at MSB and is undefined for 0)
#ifdef __GNUC__
INDEX bsr = 31;
if(_ctGroupsCount != 0) bsr -= __builtin_clz(_ctGroupsCount);
else bsr = 0;
#else // another compiler - doing it manually.. not fast. :/
register DWORD val = _ctGroupsCount;
register INDEX bsr = 31;
if (val != 0)
@ -511,6 +519,7 @@ static void RSBinToGroups( ScenePolygon *pspoFirst)
bsr--;
}
}
#endif
_ctGroupsCount = 2 << bsr;
#endif