28 static inline FXushort swap16(FXushort x){
29 #if ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) 30 return __builtin_bswap16(x);
31 #elif (_MSC_VER >= 1500) 32 return _byteswap_ushort(x);
34 return (x>>8) | (x<<8);
40 static inline FXshort swap16(FXshort x){
41 return (FXushort)swap16((FXushort)x);
46 static inline FXuint swap32(FXuint x){
47 #if ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) 48 return __builtin_bswap32(x);
49 #elif (_MSC_VER >= 1500) 50 return _byteswap_ulong(x);
52 x=((x<<8)&0xFF00FF00)|((x>>8)&0x00FF00FF);
53 return (x>>16)|(x<<16);
59 static inline FXint swap32(FXint x){
60 return (FXint)swap32((FXuint)x);
65 static inline FXfloat swap32(FXfloat x){
66 union { FXfloat f; FXuint n; } xx={x};
73 static inline FXulong swap64(FXulong x){
74 #if ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) 75 return __builtin_bswap64(x);
76 #elif (_MSC_VER >= 1500) 77 return _byteswap_uint64(x);
79 x=((x<< 8)&FXULONG(0xFF00FF00FF00FF00))|((x>> 8)&FXULONG(0x00FF00FF00FF00FF));
80 x=((x<<16)&FXULONG(0xFFFF0000FFFF0000))|((x>>16)&FXULONG(0x0000FFFF0000FFFF));
81 return (x>>32)|(x<<32);
87 static inline FXlong swap64(FXlong x){
88 return (FXlong)swap64((FXulong)x);
93 static inline FXdouble swap64(FXdouble x){
94 union { FXdouble d; FXulong n; } xx={x};
101 static inline FXuchar reverse8(FXuchar x){
102 x=((x<<1)&0xAA) | ((x>>1)&0x55);
103 x=((x<<2)&0xCC) | ((x>>2)&0x33);
104 return (x<<4) | (x>>4);
109 static inline FXushort reverse16(FXushort x){
110 x=((x<<1)&0xAAAA) | ((x>>1)&0x5555);
111 x=((x<<2)&0xCCCC) | ((x>>2)&0x3333);
112 x=((x<<4)&0xF0F0) | ((x>>4)&0x0F0F);
118 static inline FXuint reverse32(FXuint x){
119 x=((x<<1)&0xAAAAAAAA) | ((x>>1)&0x55555555);
120 x=((x<<2)&0xCCCCCCCC) | ((x>>2)&0x33333333);
121 x=((x<<4)&0xF0F0F0F0) | ((x>>4)&0x0F0F0F0F);
127 static inline FXulong reverse64(FXulong x){
128 x=((x<< 1)&FXULONG(0xAAAAAAAAAAAAAAAA)) | ((x>> 1)&FXULONG(0x5555555555555555));
129 x=((x<< 2)&FXULONG(0xCCCCCCCCCCCCCCCC)) | ((x>> 2)&FXULONG(0x3333333333333333));
130 x=((x<< 4)&FXULONG(0xF0F0F0F0F0F0F0F0)) | ((x>> 4)&FXULONG(0x0F0F0F0F0F0F0F0F));
136 static inline FXuint lsb32(FXuint x){
137 return FXuint(x&(-FXint(x)));
142 static inline FXulong lsb64(FXulong x){
143 return FXulong(x&(-FXlong(x)));
148 static inline FXuint msb32(FXuint x){
159 static inline FXulong msb64(FXulong x){
171 static inline FXuint pop32(FXuint x){
172 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))) 173 return __builtin_popcount(x);
174 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) 177 x=x-((x>>1)&0x55555555);
178 x=(x&0x33333333)+((x>>2)&0x33333333);
179 return (((x+(x>>4))&0x0F0F0F0F)*0x01010101)>>24;
185 static inline FXulong pop64(FXulong x){
186 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))) 187 #if defined(__LP64__) || defined(_LP64) || (__WORDSIZE == 64) 188 return __builtin_popcountl(x);
190 return __builtin_popcountll(x);
192 #elif defined(_MSC_VER) && (defined(_M_X64)) 193 return __popcnt64(x);
195 x=x-((x>>1)&FXULONG(0x5555555555555555));
196 x=(x&FXULONG(0x3333333333333333))+((x>>2)&FXULONG(0x3333333333333333));
197 return (((x+(x>>4))&FXULONG(0xf0f0f0f0f0f0f0f))*FXULONG(0x101010101010101))>>56;
203 static inline FXuint clz32(FXuint x){
204 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))) 205 return __builtin_clz(x);
206 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) 207 unsigned long result;
208 _BitScanReverse(&result,x);
212 f=(((FXint)(x-0x00010000))>>31)&16; x<<=f;
213 e=(((FXint)(x-0x01000000))>>31)&8; x<<=e;
214 d=(((FXint)(x-0x10000000))>>31)&4; x<<=d;
215 c=(((FXint)(x-0x40000000))>>31)&2; x<<=c;
216 b=(((FXint)(x-0x80000000))>>31)&1;
223 static inline FXulong clz64(FXulong x){
224 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))) 225 #if defined(__LP64__) || defined(_LP64) || (__WORDSIZE == 64) 226 return __builtin_clzl(x);
228 return __builtin_clzll(x);
230 #elif defined(_MSC_VER) && defined(_M_X64) 231 unsigned long result;
232 _BitScanReverse64(&result,x);
236 g=(((FXlong)(x-FXULONG(0x0000000100000000)))>>63)&32; x<<=g;
237 f=(((FXlong)(x-FXULONG(0x0001000000000000)))>>63)&16; x<<=f;
238 e=(((FXlong)(x-FXULONG(0x0100000000000000)))>>63)&8; x<<=e;
239 d=(((FXlong)(x-FXULONG(0x1000000000000000)))>>63)&4; x<<=d;
240 c=(((FXlong)(x-FXULONG(0x4000000000000000)))>>63)&2; x<<=c;
241 b=(((FXlong)(x-FXULONG(0x8000000000000000)))>>63)&1;
248 static inline FXuint ctz32(FXuint x){
249 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))) 250 return __builtin_ctz(x);
251 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) 252 unsigned long result;
253 _BitScanForward(&result,x);
256 return 31-clz32(x&-x);
262 static inline FXulong ctz64(FXulong x){
263 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))) 264 #if defined(__LP64__) || defined(_LP64) || (__WORDSIZE == 64) 265 return __builtin_ctzl(x);
267 return __builtin_ctzll(x);
269 #elif defined(_MSC_VER) && defined(_M_X64) 270 unsigned long result;
271 _BitScanForward64(&result,x);
274 return FXULONG(63)-clz64(x&-x);
280 static inline FXuint rol32(FXuint value,FXuint count){
281 return (value<<count) | (value>>(32-count));
285 static inline FXuint ror32(FXuint value,FXuint count){
286 return (value>>count) | (value<<(32-count));
291 static inline FXulong rol64(FXulong value,FXulong count){
292 return (value<<count) | (value>>(FXULONG(64)-count));
296 static inline FXulong ror64(FXulong value,FXulong count){
297 return (value>>count) | (value<<(FXULONG(64)-count));
302 static inline FXuint shl32(FXuint value,FXuint count){
303 return (value<<count);
307 static inline FXuint shr32(FXuint value,FXuint count){
308 return (value>>count);
312 static inline FXuint sar32(FXuint value,FXuint count){
313 return (FXuint)(((FXint)value)>>count);
318 static inline FXulong shl64(FXulong value,FXulong count){
319 return (value<<count);
323 static inline FXulong shr64(FXulong value,FXulong count){
324 return (value>>count);
328 static inline FXulong sar64(FXulong value,FXulong count){
329 return (FXulong)(((FXlong)value)>>count);
334 static inline FXuint hash32(FXuint x){
335 x=((x>>16)^x)*0x21F0AAAD;
336 x=((x>>15)^x)*0x735A2D97;
343 static inline FXuint unhash32(FXuint x){
344 x=((x>>15)^(x>>30)^x)*0x97132227;
345 x=((x>>15)^(x>>30)^x)*0x333C4925;
352 static inline FXulong hash64(FXulong x){
353 x=(x^(x>>30))*FXULONG(0xBF58476D1CE4E5B9);
354 x=(x^(x>>27))*FXULONG(0x94D049BB133111EB);
361 static inline FXulong unhash64(FXulong x){
362 x=(x^(x>>31)^(x>>62))*FXULONG(0x319642B2D24D8EC3);
363 x=(x^(x>>27)^(x>>54))*FXULONG(0x96DE1B173F119089);
370 static inline FXuint hash32(FXfloat x){
371 return x!=0.0f ? hash32(Math::fpBits(x)) : 0;
376 static inline FXulong hash64(FXdouble x){
377 return x!=0.0 ? hash64(Math::fpBits(x)) : 0;
Definition: FX4Splitter.h:28