48 #if !defined( BFR_UNIT )
62 #if 1 && !defined( USE_INLINING )
69 #if defined( _MSC_VER )
73 # pragma intrinsic(memset)
74 # pragma intrinsic(memcpy)
77 # define rotl64 _rotl64
78 # define rotr64 _rotl64
79 # define bswap_32(x) _byteswap_ulong(x)
80 # define bswap_64(x) _byteswap_uint64(x)
82 # define rotl32 _lrotl
83 # define rotr32 _lrotr
88 # define NEED_UINT_64T
95 #if defined( USE_INLINING )
96 # if defined( _MSC_VER )
97 # define mh_inline __inline
98 # elif defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
99 # define mh_inline static inline
101 # define mh_inline static
105 #if defined(__cplusplus)
109 #define ui8_ptr(x) ptr_cast(x, 8)
110 #define ui16_ptr(x) ptr_cast(x, 16)
111 #define ui32_ptr(x) ptr_cast(x, 32)
112 #define ui64_ptr(x) ptr_cast(x, 64)
113 #define unit_ptr(x) ptr_cast(x, BFR_UNIT)
115 #define BUF_INC (BFR_UNIT >> 3)
116 #define BUF_ADRMASK ((BFR_UNIT >> 3) - 1)
124 #if defined( mh_inline )
126 #if !defined( rotl32 ) // NOTE: 0 <= n <= 32 ASSUMED
129 return (((x) << n) | ((x) >> (32 - n)));
133 #if !defined( rotr32 ) // NOTE: 0 <= n <= 32 ASSUMED
136 return (((x) >> n) | ((x) << (32 - n)));
140 #if !defined( rotl64 ) // NOTE: 0 <= n <= 64 ASSUMED
143 return (((x) << n) | ((x) >> (64 - n)));
147 #if !defined( rotr64 ) // NOTE: 0 <= n <= 64 ASSUMED
150 return (((x) >> n) | ((x) << (64 - n)));
156 #if !defined(bswap_32)
159 return ((
rotr32((x), 24) & 0x00ff00ff) | (
rotr32((x), 8) & 0xff00ff00));
163 #if !defined(bswap_64)
166 return bswap_32((uint_32t)(x >> 32)) | ((uint_64t)
bswap_32((uint_32t)x) << 32);
173 ((uint_32t*)d)[n] =
bswap_32(((uint_32t*)s)[n]);
179 ((uint_64t*)d)[n] =
bswap_64(((uint_64t*)s)[n]);
184 #if !defined( rotl32 ) // NOTE: 0 <= n <= 32 ASSUMED
185 # define rotl32(x,n) (((x) << n) | ((x) >> (32 - n)))
188 #if !defined( rotr32 ) // NOTE: 0 <= n <= 32 ASSUMED
189 # define rotr32(x,n) (((x) >> n) | ((x) << (32 - n)))
192 #if !defined( rotl64 ) // NOTE: 0 <= n <= 64 ASSUMED
193 # define rotl64(x,n) (((x) << n) | ((x) >> (64 - n)))
196 #if !defined( rotr64 ) // NOTE: 0 <= n <= 64 ASSUMED
197 # define rotr64(x,n) (((x) >> n) | ((x) << (64 - n)))
200 #if !defined(bswap_32)
201 # define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00))
204 #if !defined(bswap_64)
205 # define bswap_64(x) (bswap_32((uint_32t)(x >> 32)) | ((uint_64t)bswap_32((uint_32t)x) << 32))
208 #define bswap32_block(d,s,n) \
209 { int _i = (n); while(_i--) ui32_ptr(d)[_i] = bswap_32(ui32_ptr(s)[_i]); }
211 #define bswap64_block(d,s,n) \
212 { int _i = (n); while(_i--) ui64_ptr(d)[_i] = bswap_64(ui64_ptr(s)[_i]); }
218 #if defined( mh_inline )
263 #define move_block(p,q) memcpy((p), (q), 16)
266 # define move_block_aligned(p,q) \
267 ui64_ptr(p)[0] = ui64_ptr(q)[0], ui64_ptr(p)[1] = ui64_ptr(q)[1]
269 # define move_block_aligned(p,q) \
270 ui32_ptr(p)[0] = ui32_ptr(q)[0], ui32_ptr(p)[1] = ui32_ptr(q)[1], \
271 ui32_ptr(p)[2] = ui32_ptr(q)[2], ui32_ptr(p)[3] = ui32_ptr(q)[3]
273 # define move_block_aligned(p,q) move_block(p,q)
276 #define xor_block(p,q) \
277 ui8_ptr(p)[ 0] ^= ui8_ptr(q)[ 0], ui8_ptr(p)[ 1] ^= ui8_ptr(q)[ 1], \
278 ui8_ptr(p)[ 2] ^= ui8_ptr(q)[ 2], ui8_ptr(p)[ 3] ^= ui8_ptr(q)[ 3], \
279 ui8_ptr(p)[ 4] ^= ui8_ptr(q)[ 4], ui8_ptr(p)[ 5] ^= ui8_ptr(q)[ 5], \
280 ui8_ptr(p)[ 6] ^= ui8_ptr(q)[ 6], ui8_ptr(p)[ 7] ^= ui8_ptr(q)[ 7], \
281 ui8_ptr(p)[ 8] ^= ui8_ptr(q)[ 8], ui8_ptr(p)[ 9] ^= ui8_ptr(q)[ 9], \
282 ui8_ptr(p)[10] ^= ui8_ptr(q)[10], ui8_ptr(p)[11] ^= ui8_ptr(q)[11], \
283 ui8_ptr(p)[12] ^= ui8_ptr(q)[12], ui8_ptr(p)[13] ^= ui8_ptr(q)[13], \
284 ui8_ptr(p)[14] ^= ui8_ptr(q)[14], ui8_ptr(p)[15] ^= ui8_ptr(q)[15]
287 # define xor_block_aligned(p,q) \
288 ui64_ptr(p)[0] ^= ui64_ptr(q)[0], ui64_ptr(p)[1] ^= ui64_ptr(q)[1]
290 # define xor_block_aligned(p,q) \
291 ui32_ptr(p)[0] ^= ui32_ptr(q)[0], ui32_ptr(p)[1] ^= ui32_ptr(q)[1], \
292 ui32_ptr(p)[2] ^= ui32_ptr(q)[2], ui32_ptr(p)[3] ^= ui32_ptr(q)[3]
294 # define xor_block_aligned(p,q) xor_block(p,q)
301 #if PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN
302 # define uint_32t_to_le(x) (x) = bswap_32((x))
303 # define uint_64t_to_le(x) (x) = bswap_64((x))
304 # define uint_32t_to_be(x)
305 # define uint_64t_to_be(x)
307 # define uint_32t_to_le(x)
308 # define uint_64t_to_le(x)
309 # define uint_32t_to_be(x) (x) = bswap_32((x))
310 # define uint_64t_to_be(x) (x) = bswap_64((x))
313 #if defined(__cplusplus)