Half of day 38 complete.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
math.h. */
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h> // memset
|
||||
|
||||
S32 RoundF32toS32(F32 Real32)
|
||||
{
|
||||
@@ -36,5 +37,38 @@ F32 ATan2(F32 Y, F32 X)
|
||||
return Result;
|
||||
}
|
||||
|
||||
typedef struct bit_scan_result {
|
||||
B32 Found;
|
||||
U32 Index;
|
||||
} bit_scan_result;
|
||||
|
||||
static bit_scan_result FindLeastSignificantSetBit(U32 Value)
|
||||
{
|
||||
bit_scan_result Result;
|
||||
memset(&Result, 0, sizeof(Result));
|
||||
|
||||
#if COMPILER_MSVC
|
||||
Result.Found = _BitScanForward(&Result.Index, Value); // TODO: I have not tested this.
|
||||
#elif COMPILER_CLANG
|
||||
Result.Index = __builtin_ffsll(Value); // NOTE: It is a GCC function, but is supported by clang compiler.
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Bit-Operation-Builtins.html
|
||||
if(Result.Index) {
|
||||
Result.Found = TRUE;
|
||||
if(Result.Index > 0)
|
||||
Result.Index--;
|
||||
}
|
||||
#else
|
||||
for(U32 Test = 0; Test < 32; Test++) {
|
||||
if(Value & (1 << Test)) {
|
||||
Result.Index = Test;
|
||||
Result.Found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user