diff options
author | Raymaekers Luca <luca@spacehb.net> | 2025-06-16 20:08:40 +0200 |
---|---|---|
committer | Raymaekers Luca <luca@spacehb.net> | 2025-06-16 20:09:36 +0200 |
commit | 8417b6057464d5201e9f411735cae759fdf91c66 (patch) | |
tree | 238145ec68f0d0355ca138e81d2fa67439b63f9d /code/handmade_intrinsics.h |
checkpoint
Diffstat (limited to 'code/handmade_intrinsics.h')
-rw-r--r-- | code/handmade_intrinsics.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/code/handmade_intrinsics.h b/code/handmade_intrinsics.h new file mode 100644 index 0000000..2a3a69e --- /dev/null +++ b/code/handmade_intrinsics.h @@ -0,0 +1,103 @@ +/* date = May 13th 2025 1:41 pm */ + +#ifndef HANDMADE_INTRINSICS_H +#define HANDMADE_INTRINSICS_H + +// +// TODO(casey): Remove math.h +// +#include <math.h> + +inline s32 +RoundReal32ToInt32(r32 Real32) +{ + s32 Result = (s32)(roundf(Real32)); + return Result; +} + +inline u32 +RoundReal32ToUInt32(r32 Real32) +{ + u32 Result = (u32)(roundf(Real32)); + return Result; +} + +inline u32 +TruncateReal32ToUInt32(r32 Real32) +{ + u32 Result = (u32)Real32; + return Result; +} + +inline s32 +TruncateReal32ToInt32(r32 Real32) +{ + s32 Result = (s32)Real32; + return Result; +} + +inline s32 +FloorReal32ToInt32(r32 Real32) +{ + s32 Result = (s32)floorf(Real32); + return Result; +} + +inline r32 +Sin(r32 Angle) +{ + r32 Result = sinf(Angle); + return Result; +} + +inline r32 +Cos(r32 Angle) +{ + r32 Result = cosf(Angle); + return Result; +} + +inline r32 +Atan2(r32 Y, r32 X) +{ + r32 Result = atan2f(Y, X); + return Result; +} + +struct bit_scan_result +{ + b32 Found; + u32 Index; +}; + +internal inline bit_scan_result +FindLeastSignificantSetBit(u32 Value) +{ + bit_scan_result Result = {}; + +#if 0 +#elif COMPILER_GNU + Result.Index = __builtin_ffs(Value); + if(Result.Index) + { + Result.Found = true; + 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 //HANDMADE_INTRINSICS_H |