mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-04 21:07:06 +00:00
Assume clz/ctz argument is nonzero in our fallback implementations
This commit is contained in:
+14
-16
@@ -50,42 +50,40 @@ static inline void unreachable_() {
|
|||||||
#pragma intrinsic(_BitScanReverse, _BitScanForward)
|
#pragma intrinsic(_BitScanReverse, _BitScanForward)
|
||||||
|
|
||||||
static inline int ctz(unsigned int x) {
|
static inline int ctz(unsigned int x) {
|
||||||
unsigned long cnt;
|
|
||||||
|
|
||||||
assume(x != 0);
|
assume(x != 0);
|
||||||
_BitScanForward(&cnt, x);
|
unsigned long count;
|
||||||
return cnt;
|
_BitScanForward(&count, x);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int clz(unsigned int x) {
|
static inline int clz(unsigned int x) {
|
||||||
unsigned long cnt;
|
|
||||||
|
|
||||||
assume(x != 0);
|
assume(x != 0);
|
||||||
_BitScanReverse(&cnt, x);
|
unsigned long count;
|
||||||
return 31 - cnt;
|
_BitScanReverse(&count, x);
|
||||||
|
return 31 - count;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
static inline int ctz(unsigned int x) {
|
static inline int ctz(unsigned int x) {
|
||||||
int cnt = 0;
|
assume(x != 0);
|
||||||
|
int count = 0;
|
||||||
while (!(x & 1)) {
|
while (!(x & 1)) {
|
||||||
x >>= 1;
|
x >>= 1;
|
||||||
++cnt;
|
++count;
|
||||||
}
|
}
|
||||||
return cnt;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int clz(unsigned int x) {
|
static inline int clz(unsigned int x) {
|
||||||
int cnt = 0;
|
assume(x != 0);
|
||||||
|
int count = 0;
|
||||||
while (x <= UINT_MAX / 2) {
|
while (x <= UINT_MAX / 2) {
|
||||||
x <<= 1;
|
x <<= 1;
|
||||||
++cnt;
|
++count;
|
||||||
}
|
}
|
||||||
return cnt;
|
return count;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user