This commit is contained in:
snarmph 2024-11-29 16:10:48 +01:00
parent 82aee127b0
commit a92b119549
99 changed files with 6922 additions and 5723 deletions

34
bits.h Normal file
View file

@ -0,0 +1,34 @@
#pragma once
#include "collatypes.h"
uint32 bitsCtz(uint32 v);
// == INLINE IMPLEMENTATION ==============================================================
#if COLLA_MSVC
#define BITS_WIN 1
#define BITS_LIN 0
#include <intrin.h>
#elif COLLA_GCC || COLLA_CLANG || COLLA_EMC
#define BITS_WIN 0
#define BITS_LIN 1
#else
#error "bits header not supported on this compiler"
#endif
#include "tracelog.h"
inline uint32 bitsCtz(uint32 v) {
#if BITS_LIN
return v ? __builtin_ctz(v) : 0;
#elif BITS_WIN
uint32 trailing = 0;
return _BitScanForward((unsigned long *)&trailing, v) ? trailing : 0;
#else
return 0;
#endif
}
#undef BITS_WIN
#undef BITS_LIN