diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-04-21 15:02:27 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-04-21 15:02:27 +0300 |
commit | fbe1ba9d472dea87bfb6874f9e08cc3beec99bce (patch) | |
tree | cbc2b30ea0a4908ed4a53c678035a84b3fb1593a /src/microhttpd/mhd_bithelpers.h | |
parent | 9e68caa3d70f482d374d5b55d91a72f6a47a0936 (diff) | |
download | libmicrohttpd-fbe1ba9d472dea87bfb6874f9e08cc3beec99bce.tar.gz libmicrohttpd-fbe1ba9d472dea87bfb6874f9e08cc3beec99bce.zip |
mhd_bithelpers.h: used MSVC built-ins to speed-up VC-compiled code
Diffstat (limited to 'src/microhttpd/mhd_bithelpers.h')
-rw-r--r-- | src/microhttpd/mhd_bithelpers.h | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h index 6c4f0fea..caa24846 100644 --- a/src/microhttpd/mhd_bithelpers.h +++ b/src/microhttpd/mhd_bithelpers.h | |||
@@ -28,24 +28,52 @@ | |||
28 | 28 | ||
29 | #include "mhd_byteorder.h" | 29 | #include "mhd_byteorder.h" |
30 | #include <stdint.h> | 30 | #include <stdint.h> |
31 | #if defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) | ||
32 | /* Declarations for VC & Clang/C2 built-ins */ | ||
33 | #include <intrin.h> | ||
34 | #endif /* _MSC_FULL_VER */ | ||
35 | |||
36 | #ifndef __has_builtin | ||
37 | /* Avoid precompiler errors with non-clang */ | ||
38 | # define __has_builtin(x) 0 | ||
39 | #endif | ||
31 | 40 | ||
32 | 41 | ||
33 | #ifdef MHD_HAVE___BUILTIN_BSWAP32 | 42 | #ifdef MHD_HAVE___BUILTIN_BSWAP32 |
34 | #define _MHD_BYTES_SWAP32(value32) \ | 43 | #define _MHD_BYTES_SWAP32(value32) \ |
35 | ((uint32_t)__builtin_bswap32((uint32_t)value32)) | 44 | ((uint32_t)__builtin_bswap32((uint32_t)value32)) |
36 | #else /* ! MHD_HAVE___BUILTIN_BSWAP32 */ | 45 | #elif defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) |
46 | /* Clang/C2 may not inline this function if optimizations are turned off. */ | ||
47 | #ifndef __clang__ | ||
48 | #pragma intrinsic(_byteswap_ulong) | ||
49 | #endif /* ! __clang__ */ | ||
50 | #define _MHD_BYTES_SWAP32(value32) \ | ||
51 | ((uint32_t)_byteswap_ulong((uint32_t)value32)) | ||
52 | #elif __has_builtin(__builtin_bswap32) | ||
53 | #define _MHD_BYTES_SWAP32(value32) \ | ||
54 | ((uint32_t)__builtin_bswap32((uint32_t)value32)) | ||
55 | #else /* ! __has_builtin(__builtin_bswap32) */ | ||
37 | #define _MHD_BYTES_SWAP32(value32) \ | 56 | #define _MHD_BYTES_SWAP32(value32) \ |
38 | ( (((uint32_t)(value32)) << 24) | \ | 57 | ( (((uint32_t)(value32)) << 24) | \ |
39 | ((((uint32_t)(value32)) & ((uint32_t)0x0000FF00)) << 8) | \ | 58 | ((((uint32_t)(value32)) & ((uint32_t)0x0000FF00)) << 8) | \ |
40 | ((((uint32_t)(value32)) & ((uint32_t)0x00FF0000)) >> 8) | \ | 59 | ((((uint32_t)(value32)) & ((uint32_t)0x00FF0000)) >> 8) | \ |
41 | (((uint32_t)(value32)) >> 24) ) | 60 | (((uint32_t)(value32)) >> 24) ) |
42 | #endif /* ! MHD_HAVE___BUILTIN_BSWAP32 */ | 61 | #endif /* ! __has_builtin(__builtin_bswap32) */ |
43 | |||
44 | 62 | ||
45 | #ifdef MHD_HAVE___BUILTIN_BSWAP64 | 63 | #ifdef MHD_HAVE___BUILTIN_BSWAP64 |
46 | #define _MHD_BYTES_SWAP64(value64) \ | 64 | #define _MHD_BYTES_SWAP64(value64) \ |
47 | ((uint64_t)__builtin_bswap64((uint64_t)value64)) | 65 | ((uint64_t)__builtin_bswap64((uint64_t)value64)) |
48 | #else /* ! MHD_HAVE___BUILTIN_BSWAP64 */ | 66 | #elif defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) |
67 | /* Clang/C2 may not inline this function if optimizations are turned off. */ | ||
68 | #ifndef __clang__ | ||
69 | #pragma intrinsic(_byteswap_uint64) | ||
70 | #endif /* ! __clang__ */ | ||
71 | #define _MHD_BYTES_SWAP64(value64) \ | ||
72 | ((uint64_t)_byteswap_uint64((uint64_t)value64)) | ||
73 | #elif __has_builtin(__builtin_bswap64) | ||
74 | #define _MHD_BYTES_SWAP64(value64) \ | ||
75 | ((uint64_t)__builtin_bswap64((uint64_t)value64)) | ||
76 | #else /* ! __has_builtin(__builtin_bswap64) */ | ||
49 | #define _MHD_BYTES_SWAP64(value64) \ | 77 | #define _MHD_BYTES_SWAP64(value64) \ |
50 | ( (((uint64_t)(value64)) << 56) | \ | 78 | ( (((uint64_t)(value64)) << 56) | \ |
51 | ((((uint64_t)(value64)) & ((uint64_t)0x000000000000FF00)) << 40) | \ | 79 | ((((uint64_t)(value64)) & ((uint64_t)0x000000000000FF00)) << 40) | \ |
@@ -55,7 +83,8 @@ | |||
55 | ((((uint64_t)(value64)) & ((uint64_t)0x0000FF0000000000)) >> 24) | \ | 83 | ((((uint64_t)(value64)) & ((uint64_t)0x0000FF0000000000)) >> 24) | \ |
56 | ((((uint64_t)(value64)) & ((uint64_t)0x00FF000000000000)) >> 40) | \ | 84 | ((((uint64_t)(value64)) & ((uint64_t)0x00FF000000000000)) >> 40) | \ |
57 | (((uint64_t)(value64)) >> 56) ) | 85 | (((uint64_t)(value64)) >> 56) ) |
58 | #endif /* ! MHD_HAVE___BUILTIN_BSWAP64 */ | 86 | #endif /* ! __has_builtin(__builtin_bswap64) */ |
87 | |||
59 | 88 | ||
60 | /* _MHD_PUT_64BIT_LE (addr, value64) | 89 | /* _MHD_PUT_64BIT_LE (addr, value64) |
61 | * put native-endian 64-bit value64 to addr | 90 | * put native-endian 64-bit value64 to addr |
@@ -184,11 +213,23 @@ | |||
184 | ((uint32_t) (((uint8_t*)addr)[3])) ) | 213 | ((uint32_t) (((uint8_t*)addr)[3])) ) |
185 | #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ | 214 | #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */ |
186 | 215 | ||
216 | |||
187 | /** | 217 | /** |
188 | * Rotate right 32-bit value by number of bits. | 218 | * Rotate right 32-bit value by number of bits. |
189 | * bits parameter must be more than zero and must be less than 32. | 219 | * bits parameter must be more than zero and must be less than 32. |
190 | * Defined in form which modern compiler could optimize. | ||
191 | */ | 220 | */ |
192 | #define _MHD_ROTR32(value32, bits) ((value32) >> (bits) | (value32) << (32 - bits)) | 221 | #if defined(_MSC_FULL_VER) && (!defined(__clang__) || (defined(__c2__) && defined(__OPTIMIZE__))) |
222 | /* Clang/C2 do not inline this function if optimizations are turned off. */ | ||
223 | #ifndef __clang__ | ||
224 | #pragma intrinsic(_rotr) | ||
225 | #endif /* ! __clang__ */ | ||
226 | #define _MHD_ROTR32(value32, bits) \ | ||
227 | ((uint32_t)_rotr((uint32_t)(value32),(bits))) | ||
228 | #else /* ! _MSC_FULL_VER */ | ||
229 | /* Defined in form which modern compiler could optimize. */ | ||
230 | #define _MHD_ROTR32(value32, bits) \ | ||
231 | (((uint32_t)(value32)) >> (bits) | ((uint32_t)(value32)) << (32 - bits)) | ||
232 | #endif /* ! _MSC_FULL_VER */ | ||
233 | |||
193 | 234 | ||
194 | #endif /* ! MHD_BITHELPERS_H */ | 235 | #endif /* ! MHD_BITHELPERS_H */ |