From a3f2091bcdf5a5843b2c5a1706b5739609b8d015 Mon Sep 17 00:00:00 2001 From: weidai Date: Thu, 29 Jul 2010 08:51:39 +0000 Subject: [PATCH] fix compile on GCC 4.4 and greater --- Doxyfile | 4 +-- GNUmakefile | 2 +- cpu.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++-- gcm.cpp | 15 ++-------- rijndael.cpp | 5 ---- 5 files changed, 86 insertions(+), 22 deletions(-) diff --git a/Doxyfile b/Doxyfile index 1fb9d81e..3dc34887 100644 --- a/Doxyfile +++ b/Doxyfile @@ -369,13 +369,13 @@ QUIET = NO # generated by doxygen. Possible values are YES and NO. If left blank # NO is used. -WARNINGS = No +WARNINGS = NO # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings # for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. -WARN_IF_UNDOCUMENTED = No +WARN_IF_UNDOCUMENTED = NO # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some diff --git a/GNUmakefile b/GNUmakefile index b6d1c830..164ed7d0 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -34,7 +34,7 @@ ifneq ($(GCC42_OR_LATER),0) ifeq ($(UNAME),Darwin) CXXFLAGS += -arch x86_64 -arch i386 else -CXXFLAGS += -march=native -mtune=native +CXXFLAGS += -march=native endif endif diff --git a/cpu.h b/cpu.h index 9a6ee223..79d612e0 100755 --- a/cpu.h +++ b/cpu.h @@ -12,8 +12,86 @@ #include "config.h" -#ifdef CRYPTOPP_MSVC6PP_OR_LATER - #include +#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE +#include +#endif + +#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE +#if !defined(__GNUC__) || defined(__SSSE3__) +#include +#else +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_shuffle_epi8 (__m128i a, __m128i b) +{ + asm ("pshufb %1, %0" : "+x"(a) : "xm"(b)); + return a; +} +#endif +#if !defined(__GNUC__) || defined(__SSE4_1__) +#include +#else +__inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_extract_epi32 (__m128i a, const int i) +{ + int r; + asm ("pextrd %2, %1, %0" : "=rm"(r) : "x"(a), "i"(i)); + return r; +} +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_insert_epi32 (__m128i a, int b, const int i) +{ + asm ("pinsrd %2, %1, %0" : "+x"(a) : "rm"(b), "i"(i)); + return a; +} +#endif +#if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) +#include +#else +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_clmulepi64_si128 (__m128i a, __m128i b, const int i) +{ + asm ("pclmulqdq %2, %1, %0" : "+x"(a) : "xm"(b), "i"(i)); + return a; +} +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_aeskeygenassist_si128 (__m128i a, const int i) +{ + __m128i r; + asm ("aeskeygenassist %2, %1, %0" : "=x"(r) : "xm"(a), "i"(i)); + return r; +} +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_aesimc_si128 (__m128i a) +{ + __m128i r; + asm ("aesimc %1, %0" : "=x"(r) : "xm"(a)); + return r; +} +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_aesenc_si128 (__m128i a, __m128i b) +{ + asm ("aesenc %1, %0" : "+x"(a) : "xm"(b)); + return a; +} +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_aesenclast_si128 (__m128i a, __m128i b) +{ + asm ("aesenclast %1, %0" : "+x"(a) : "xm"(b)); + return a; +} +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_aesdec_si128 (__m128i a, __m128i b) +{ + asm ("aesdec %1, %0" : "+x"(a) : "xm"(b)); + return a; +} +__inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +_mm_aesdeclast_si128 (__m128i a, __m128i b) +{ + asm ("aesdeclast %1, %0" : "+x"(a) : "xm"(b)); + return a; +} +#endif #endif NAMESPACE_BEGIN(CryptoPP) diff --git a/gcm.cpp b/gcm.cpp index 84f6f918..237325d9 100644 --- a/gcm.cpp +++ b/gcm.cpp @@ -10,15 +10,6 @@ #include "gcm.h" #include "cpu.h" -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE -#include -#endif - -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE -#include -#include -#endif - NAMESPACE_BEGIN(CryptoPP) word16 GCM_Base::s_reductionTable[256]; @@ -88,9 +79,9 @@ inline static void Xor16(byte *a, const byte *b, const byte *c) #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE static CRYPTOPP_ALIGN_DATA(16) const word64 s_clmulConstants64[] = { - 0xe100000000000000, 0xc200000000000000, - 0x08090a0b0c0d0e0f, 0x0001020304050607, - 0x0001020304050607, 0x08090a0b0c0d0e0f}; + W64LIT(0xe100000000000000), W64LIT(0xc200000000000000), + W64LIT(0x08090a0b0c0d0e0f), W64LIT(0x0001020304050607), + W64LIT(0x0001020304050607), W64LIT(0x08090a0b0c0d0e0f)}; static const __m128i *s_clmulConstants = (const __m128i *)s_clmulConstants64; static const unsigned int s_clmulTableSizeInBlocks = 8; diff --git a/rijndael.cpp b/rijndael.cpp index 9a779024..608b9d30 100644 --- a/rijndael.cpp +++ b/rijndael.cpp @@ -73,11 +73,6 @@ being unloaded from L1 cache, until that round is finished. #include "misc.h" #include "cpu.h" -#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE -#include -#include -#endif - NAMESPACE_BEGIN(CryptoPP) #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS