20 #ifndef __SYS_BitUtil__
21 #define __SYS_BitUtil__
34 if (_BitScanForward(&result, v))
37 #elif defined(GCC3) && !defined(ARM64)
42 :
"=r" (
c) :
"r" (v),
"r" (-1));
79 #if defined(_MSC_VER) && defined(AMD64)
81 if (_BitScanForward64(&result, v))
84 #elif defined(GCC3) && defined(ARM64)
86 return __builtin_ctzl(v);
87 #elif defined(GCC4) && defined(AMD64)
92 :
"=r" (
c) :
"r" (v),
"r" (
uint64(-1)));
96 if (v & 0x00000000FFFFFFFFULL)
97 return SYSfirstBitSet(
uint(v));
98 int result = SYSfirstBitSet(
uint(v>>32));
107 return SYSfirstBitSet(
uint(v));
112 return SYSfirstBitSet(
uint64(v));
118 return SYSfirstBitSet(
uint64(v));
124 #if defined(_MSC_VER)
126 if (_BitScanReverse(&result, v))
129 #elif defined(GCC3) && defined(ARM64)
131 return 32 - __builtin_clz(v) - 1;
132 #elif defined(GCC3) && defined(AMD64)
137 :
"=r" (
c) :
"r" (v),
"r" (-1));
174 #if defined(_MSC_VER) && defined(AMD64)
176 if (_BitScanReverse64(&result, v))
179 #elif defined(GCC3) && defined(ARM64)
181 return 64 - __builtin_clzl(v) - 1;
182 #elif defined(GCC4) && defined(AMD64)
187 :
"=r" (
c) :
"r" (v),
"r" (
uint64(-1)));
191 if (v & 0xFFFFFFFF00000000ULL)
192 return SYSlastBitSet(
uint(v>>32)) + 32;
193 return SYSlastBitSet(
uint(v));
199 return SYSlastBitSet(
uint(v));
204 return SYSlastBitSet(
uint64(v));
214 if (bit <= 0 || bit >= std::numeric_limits<T>::digits)
217 int nbit = SYSfirstBitSet(v >> bit);
226 return SYSlastBitSet(
uint64(v));
238 v = (v&0x55555555U) + ((v>>1 )&0x55555555U);
239 v = (v&0x33333333U) + ((v>>2 )&0x33333333U);
240 v = (v&0x0F0F0F0FU) + ((v>>4 )&0x0F0F0F0FU);
245 return ((
int)
v)&0xFF;
250 v = (v&0x5555555555555555ULL) + ((v>>1 )&0x5555555555555555ULL);
251 v = (v&0x3333333333333333ULL) + ((v>>2 )&0x3333333333333333ULL);
252 v = (v&0x0F0F0F0F0F0F0F0FULL) + ((v>>4 )&0x0F0F0F0F0F0F0F0FULL);
258 return ((
int)
v)&0xFF;
262 template <
typename T>
265 return v>0 && !(v&(v-1));
269 template <
typename T>
276 T v2 = (
T(1) << (SYSlastBitSet(v) + 1));
280 template <
typename T>
285 bool isPow2 = SYSisPow2(v);
286 return SYSlastBitSet(v) + !isPow2;
289 template <
typename T>
294 return SYSlastBitSet(v);
299 #define SYS_LOG2F(x) ((((x)>=(1<< 1))?1:0) + (((x)>=(1<< 2))?1:0) + (((x)>=(1<< 3))?1:0) + (((x)>=(1<< 4))?1:0) + \
300 (((x)>=(1<< 5))?1:0) + (((x)>=(1<< 6))?1:0) + (((x)>=(1<< 7))?1:0) + (((x)>=(1<< 8))?1:0))
394 n = ((n >> 1) & 0x55) | ((n << 1) & 0xaa);
395 n = ((n >> 2) & 0x33) | ((n << 2) & 0xcc);
396 n = ((n >> 4) & 0x0f) | ((n << 4) & 0xf0);
400 #define R2(n) n, n + 2*64, n + 1*64, n + 3*64
401 #define R4(n) R2(n), R2(n + 2*16), R2(n + 1*16), R2(n + 3*16)
402 #define R6(n) R4(n), R4(n + 2*4 ), R4(n + 1*4 ), R4(n + 3*4 )
415 n = ((n >> 1) & 0x5555) | ((n << 1) & 0xaaaa);
416 n = ((n >> 2) & 0x3333) | ((n << 2) & 0xcccc);
417 n = ((n >> 4) & 0x0f0f) | ((n << 4) & 0xf0f0);
418 n = ((n >> 8) & 0x00ff) | ((n << 8) & 0xff00);
426 n = ((n >> 1) & 0x55555555) | ((n << 1) & 0xaaaaaaaa);
427 n = ((n >> 2) & 0x33333333) | ((n << 2) & 0xcccccccc);
428 n = ((n >> 4) & 0x0f0f0f0f) | ((n << 4) & 0xf0f0f0f0);
429 n = ((n >> 8) & 0x00ff00ff) | ((n << 8) & 0xff00ff00);
430 n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);
438 n = ((n >> 1) & 0x5555555555555555) | ((n << 1) & 0xaaaaaaaaaaaaaaaa);
439 n = ((n >> 2) & 0x3333333333333333) | ((n << 2) & 0xcccccccccccccccc);
440 n = ((n >> 4) & 0x0f0f0f0f0f0f0f0f) | ((n << 4) & 0xf0f0f0f0f0f0f0f0);
441 n = ((n >> 8) & 0x00ff00ff00ff00ff) | ((n << 8) & 0xff00ff00ff00ff00);
442 n = ((n >> 16) & 0x0000ffff0000ffff) | ((n << 16) & 0xffff0000ffff0000);
443 n = ((n >> 32) & 0x00000000ffffffff) | ((n << 32) & 0xffffffff00000000);
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
**But if you need a result
GLfloat GLfloat GLfloat v2
unsigned long long uint64
GLenum GLenum GLsizei void * table