|
|
|
|
@ -174,14 +174,13 @@ typedef ull uint64;
|
|
|
|
|
#else |
|
|
|
|
inline void *qmemcpy(void *dst, const void *src, size_t cnt) |
|
|
|
|
{ |
|
|
|
|
char *out = (char *)dst; |
|
|
|
|
const char *in = (const char *)src; |
|
|
|
|
while ( cnt > 0 ) |
|
|
|
|
{ |
|
|
|
|
*out++ = *in++; |
|
|
|
|
--cnt; |
|
|
|
|
} |
|
|
|
|
return dst; |
|
|
|
|
char *out = (char *)dst; |
|
|
|
|
const char *in = (const char *)src; |
|
|
|
|
while (cnt > 0) { |
|
|
|
|
*out++ = *in++; |
|
|
|
|
--cnt; |
|
|
|
|
} |
|
|
|
|
return dst; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
@ -196,25 +195,22 @@ template<class T> uint64 __PAIR__(uint32 high, T low) { return (((uint64)high) <
|
|
|
|
|
// rotate left
|
|
|
|
|
template<class T> T __ROL__(T value, int count) |
|
|
|
|
{ |
|
|
|
|
const uint nbits = sizeof(T) * 8; |
|
|
|
|
|
|
|
|
|
if ( count > 0 ) |
|
|
|
|
{ |
|
|
|
|
count %= nbits; |
|
|
|
|
T high = value >> (nbits - count); |
|
|
|
|
if ( T(-1) < 0 ) // signed value
|
|
|
|
|
high &= ~((T(-1) << count)); |
|
|
|
|
value <<= count; |
|
|
|
|
value |= high; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
count = -count % nbits; |
|
|
|
|
T low = value << (nbits - count); |
|
|
|
|
value >>= count; |
|
|
|
|
value |= low; |
|
|
|
|
} |
|
|
|
|
return value; |
|
|
|
|
const uint nbits = sizeof(T) * 8; |
|
|
|
|
|
|
|
|
|
if (count > 0) { |
|
|
|
|
count %= nbits; |
|
|
|
|
T high = value >> (nbits - count); |
|
|
|
|
if (T(-1) < 0) // signed value
|
|
|
|
|
high &= ~((T(-1) << count)); |
|
|
|
|
value <<= count; |
|
|
|
|
value |= high; |
|
|
|
|
} else { |
|
|
|
|
count = -count % nbits; |
|
|
|
|
T low = value << (nbits - count); |
|
|
|
|
value >>= count; |
|
|
|
|
value |= low; |
|
|
|
|
} |
|
|
|
|
return value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline uint16 __ROR2__(uint16 value, int count) { return __ROL__((uint16)value, -count); } |
|
|
|
|
@ -223,30 +219,27 @@ inline uint32 __ROR4__(uint32 value, int count) { return __ROL__((uint32)value,
|
|
|
|
|
// sign flag
|
|
|
|
|
template<class T> int8 __SETS__(T x) |
|
|
|
|
{ |
|
|
|
|
if ( sizeof(T) == 1 ) |
|
|
|
|
return int8(x) < 0; |
|
|
|
|
if ( sizeof(T) == 2 ) |
|
|
|
|
return int16(x) < 0; |
|
|
|
|
if ( sizeof(T) == 4 ) |
|
|
|
|
return int32(x) < 0; |
|
|
|
|
return int64(x) < 0; |
|
|
|
|
if (sizeof(T) == 1) |
|
|
|
|
return int8(x) < 0; |
|
|
|
|
if (sizeof(T) == 2) |
|
|
|
|
return int16(x) < 0; |
|
|
|
|
if (sizeof(T) == 4) |
|
|
|
|
return int32(x) < 0; |
|
|
|
|
return int64(x) < 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// overflow flag of subtraction (x-y)
|
|
|
|
|
template<class T, class U> int8 __OFSUB__(T x, U y) |
|
|
|
|
{ |
|
|
|
|
if ( sizeof(T) < sizeof(U) ) |
|
|
|
|
{ |
|
|
|
|
U x2 = x; |
|
|
|
|
int8 sx = __SETS__(x2); |
|
|
|
|
return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2-y)); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
T y2 = y; |
|
|
|
|
int8 sx = __SETS__(x); |
|
|
|
|
return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x-y2)); |
|
|
|
|
} |
|
|
|
|
if (sizeof(T) < sizeof(U)) { |
|
|
|
|
U x2 = x; |
|
|
|
|
int8 sx = __SETS__(x2); |
|
|
|
|
return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2 - y)); |
|
|
|
|
} else { |
|
|
|
|
T y2 = y; |
|
|
|
|
int8 sx = __SETS__(x); |
|
|
|
|
return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x - y2)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|