1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows: use compiler intrinsic for some functions used in cryptographic primitives to ensure maximum performance.

This commit is contained in:
Mounir IDRASSI
2016-01-02 17:56:29 +01:00
parent 5872be28a2
commit 6e1f5cfe4b

View File

@@ -33,8 +33,13 @@
#define CRYPTOPP_FAST_ROTATE(x) 0 #define CRYPTOPP_FAST_ROTATE(x) 0
#endif #endif
#if defined( _MSC_VER ) && ( _MSC_VER > 800 )
#pragma intrinsic(memcpy,memset)
#endif
#if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER)
// Intel C++ Compiler 10.0 calls a function instead of using the rotate instruction when using these instructions // Intel C++ Compiler 10.0 calls a function instead of using the rotate instruction when using these instructions
#pragma intrinsic(_rotr,_rotl,_rotr64,_rotl64)
#define rotr32(x,n) _rotr(x, n) #define rotr32(x,n) _rotr(x, n)
#define rotl32(x,n) _rotl(x, n) #define rotl32(x,n) _rotl(x, n)
@@ -62,8 +67,10 @@
#else #else
#define bswap_32(x) (rotl32((((x) & 0xFF00FF00) >> 8) | (((x) & 0x00FF00FF) << 8), 16U)) #define bswap_32(x) (rotl32((((x) & 0xFF00FF00) >> 8) | (((x) & 0x00FF00FF) << 8), 16U))
#endif #endif
#ifndef TC_NO_COMPILER_INT64
#define bswap_64(x) rotl64(((((((value & LL(0xFF00FF00FF00FF00)) >> 8) | ((value & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0xFFFF0000FFFF0000)) >> 16) | (((((value & LL(0xFF00FF00FF00FF00)) >> 8) | ((value & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0x0000FFFF0000FFFF)) << 16)), 32U) #define bswap_64(x) rotl64(((((((value & LL(0xFF00FF00FF00FF00)) >> 8) | ((value & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0xFFFF0000FFFF0000)) >> 16) | (((((value & LL(0xFF00FF00FF00FF00)) >> 8) | ((value & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0x0000FFFF0000FFFF)) << 16)), 32U)
#endif #endif
#endif
VC_INLINE uint32 ByteReverseWord32 (uint32 value) VC_INLINE uint32 ByteReverseWord32 (uint32 value)
{ {
@@ -86,6 +93,8 @@ VC_INLINE uint32 ByteReverseWord32 (uint32 value)
#endif #endif
} }
#ifndef TC_NO_COMPILER_INT64
VC_INLINE uint64 ByteReverseWord64(uint64 value) VC_INLINE uint64 ByteReverseWord64(uint64 value)
{ {
#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__) #if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
@@ -110,6 +119,7 @@ VC_INLINE void CorrectEndianess(uint64 *out, const uint64 *in, size_t byteCount)
out[i] = ByteReverseWord64(in[i]); out[i] = ByteReverseWord64(in[i]);
} }
#endif
#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
#define GetAlignmentOf(T) 1 #define GetAlignmentOf(T) 1