diff options
Diffstat (limited to 'src/microhttpd/mhd_bithelpers.h')
-rw-r--r-- | src/microhttpd/mhd_bithelpers.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h index 5a201537..94f4e1ab 100644 --- a/src/microhttpd/mhd_bithelpers.h +++ b/src/microhttpd/mhd_bithelpers.h | |||
@@ -230,6 +230,31 @@ _MHD_PUT_64BIT_BE_SAFE (void *dst, uint64_t value) | |||
230 | } | 230 | } |
231 | 231 | ||
232 | 232 | ||
233 | /* _MHD_GET_64BIT_BE (addr) | ||
234 | * load 64-bit value located at addr in big endian mode. | ||
235 | */ | ||
236 | #if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN | ||
237 | #define _MHD_GET_64BIT_BE(addr) \ | ||
238 | (*(const uint64_t*) (addr)) | ||
239 | #elif _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN | ||
240 | #define _MHD_GET_64BIT_BE(addr) \ | ||
241 | _MHD_BYTES_SWAP64 (*(const uint64_t*) (addr)) | ||
242 | #else /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ | ||
243 | /* Endianness was not detected or non-standard like PDP-endian */ | ||
244 | #define _MHD_GET_64BIT_BE(addr) \ | ||
245 | ( (((uint64_t) (((const uint8_t*) addr)[0])) << 56) \ | ||
246 | | (((uint64_t) (((const uint8_t*) addr)[1])) << 48) \ | ||
247 | | (((uint64_t) (((const uint8_t*) addr)[2])) << 40) \ | ||
248 | | (((uint64_t) (((const uint8_t*) addr)[3])) << 32) \ | ||
249 | | (((uint64_t) (((const uint8_t*) addr)[4])) << 24) \ | ||
250 | | (((uint64_t) (((const uint8_t*) addr)[5])) << 16) \ | ||
251 | | (((uint64_t) (((const uint8_t*) addr)[6])) << 8) \ | ||
252 | | ((uint64_t) (((const uint8_t*) addr)[7])) ) | ||
253 | /* Indicate that _MHD_GET_64BIT_BE does not need aligned pointer */ | ||
254 | #define _MHD_GET_64BIT_BE_ALLOW_UNALIGNED 1 | ||
255 | #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ | ||
256 | |||
257 | |||
233 | /* _MHD_PUT_32BIT_BE (addr, value32) | 258 | /* _MHD_PUT_32BIT_BE (addr, value32) |
234 | * put native-endian 32-bit value32 to addr | 259 | * put native-endian 32-bit value32 to addr |
235 | * in big-endian mode. | 260 | * in big-endian mode. |
@@ -333,6 +358,37 @@ _MHD_ROTL32 (uint32_t value32, int bits) | |||
333 | 358 | ||
334 | #endif /* ! __builtin_rotateleft32 */ | 359 | #endif /* ! __builtin_rotateleft32 */ |
335 | 360 | ||
361 | |||
362 | /** | ||
363 | * Rotate right 64-bit value by number of bits. | ||
364 | * bits parameter must be more than zero and must be less than 64. | ||
365 | */ | ||
366 | #if defined(_MSC_FULL_VER) && (! defined(__clang__) || (defined(__c2__) && \ | ||
367 | defined(__OPTIMIZE__))) | ||
368 | /* Clang/C2 do not inline this function if optimisations are turned off. */ | ||
369 | #ifndef __clang__ | ||
370 | #pragma intrinsic(_rotr64) | ||
371 | #endif /* ! __clang__ */ | ||
372 | #define _MHD_ROTR64(value64, bits) \ | ||
373 | ((uint64_t) _rotr64 ((uint64_t) (value64),(bits))) | ||
374 | #elif __has_builtin (__builtin_rotateright64) | ||
375 | #define _MHD_ROTR64(value64, bits) \ | ||
376 | ((uint64_t) __builtin_rotateright64 ((value64), (bits))) | ||
377 | #else /* ! __builtin_rotateright64 */ | ||
378 | _MHD_static_inline uint64_t | ||
379 | _MHD_ROTR64 (uint64_t value64, int bits) | ||
380 | { | ||
381 | bits %= 64; | ||
382 | if (0 == bits) | ||
383 | return value64; | ||
384 | /* Defined in form which modern compiler could optimise. */ | ||
385 | return (value64 >> bits) | (value64 << (64 - bits)); | ||
386 | } | ||
387 | |||
388 | |||
389 | #endif /* ! __builtin_rotateright64 */ | ||
390 | |||
391 | |||
336 | #ifdef _MHD_has_builtin_dummy | 392 | #ifdef _MHD_has_builtin_dummy |
337 | /* Remove macro function replacement to avoid misdetection in files which | 393 | /* Remove macro function replacement to avoid misdetection in files which |
338 | * include this header */ | 394 | * include this header */ |