12 #ifdef CRYPTOPP_GENERATE_X64_MASM 14 #define CRYPTOPP_X86_ASM_AVAILABLE 15 #define CRYPTOPP_BOOL_X64 1 16 #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1 21 # if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 22 # include <emmintrin.h> 25 #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 26 #if !defined(__GNUC__) || defined(__SSSE3__) || defined(__INTEL_COMPILER) 27 #include <tmmintrin.h> 30 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
31 _mm_shuffle_epi8 (__m128i a, __m128i b)
33 asm (
"pshufb %1, %0" :
"+x"(a) :
"xm"(b));
38 #if !defined(__GNUC__) || defined(__SSE4_1__) || defined(__INTEL_COMPILER) 39 #include <smmintrin.h> 42 __inline
int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
43 _mm_extract_epi32 (__m128i a, const
int i)
46 asm (
"pextrd %2, %1, %0" :
"=rm"(r) :
"x"(a),
"i"(i));
49 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
50 _mm_insert_epi32 (__m128i a,
int b, const
int i)
52 asm (
"pinsrd %2, %1, %0" :
"+x"(a) :
"rm"(b),
"i"(i));
57 #if !defined(__GNUC__) || (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) 58 #include <wmmintrin.h> 61 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
62 _mm_clmulepi64_si128 (__m128i a, __m128i b, const
int i)
64 asm (
"pclmulqdq %2, %1, %0" :
"+x"(a) :
"xm"(b),
"i"(i));
67 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
68 _mm_aeskeygenassist_si128 (__m128i a, const
int i)
71 asm (
"aeskeygenassist %2, %1, %0" :
"=x"(r) :
"xm"(a),
"i"(i));
74 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
75 _mm_aesimc_si128 (__m128i a)
78 asm (
"aesimc %1, %0" :
"=x"(r) :
"xm"(a));
81 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
82 _mm_aesenc_si128 (__m128i a, __m128i b)
84 asm (
"aesenc %1, %0" :
"+x"(a) :
"xm"(b));
87 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
88 _mm_aesenclast_si128 (__m128i a, __m128i b)
90 asm (
"aesenclast %1, %0" :
"+x"(a) :
"xm"(b));
93 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
94 _mm_aesdec_si128 (__m128i a, __m128i b)
96 asm (
"aesdec %1, %0" :
"+x"(a) :
"xm"(b));
99 __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
100 _mm_aesdeclast_si128 (__m128i a, __m128i b)
102 asm (
"aesdeclast %1, %0" :
"+x"(a) :
"xm"(b));
106 #endif // wmmintrin.h 107 #endif // CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 111 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 113 #define CRYPTOPP_CPUID_AVAILABLE 116 extern CRYPTOPP_DLL
bool g_x86DetectionDone;
117 extern CRYPTOPP_DLL
bool g_hasMMX;
118 extern CRYPTOPP_DLL
bool g_hasISSE;
119 extern CRYPTOPP_DLL
bool g_hasSSE2;
120 extern CRYPTOPP_DLL
bool g_hasSSSE3;
121 extern CRYPTOPP_DLL
bool g_hasAESNI;
122 extern CRYPTOPP_DLL
bool g_hasCLMUL;
123 extern CRYPTOPP_DLL
bool g_isP4;
124 extern CRYPTOPP_DLL
bool g_hasRDRAND;
125 extern CRYPTOPP_DLL
bool g_hasRDSEED;
126 extern CRYPTOPP_DLL word32 g_cacheLineSize;
128 CRYPTOPP_DLL
void CRYPTOPP_API DetectX86Features();
129 CRYPTOPP_DLL
bool CRYPTOPP_API CpuId(word32 input, word32 output[4]);
133 #if CRYPTOPP_BOOL_X64 136 if (!g_x86DetectionDone)
142 inline bool HasISSE()
144 #if CRYPTOPP_BOOL_X64 147 if (!g_x86DetectionDone)
153 inline bool HasSSE2()
155 #if CRYPTOPP_BOOL_X64 158 if (!g_x86DetectionDone)
164 inline bool HasSSSE3()
166 if (!g_x86DetectionDone)
171 inline bool HasAESNI()
173 if (!g_x86DetectionDone)
178 inline bool HasCLMUL()
180 if (!g_x86DetectionDone)
187 if (!g_x86DetectionDone)
192 inline bool HasRDRAND()
194 if (!g_x86DetectionDone)
199 inline bool HasRDSEED()
201 if (!g_x86DetectionDone)
206 inline int GetCacheLineSize()
208 if (!g_x86DetectionDone)
210 return g_cacheLineSize;
215 inline int GetCacheLineSize()
217 return CRYPTOPP_L1_CACHE_LINE_SIZE;
224 #ifdef CRYPTOPP_GENERATE_X64_MASM 225 #define AS1(x) x*newline* 226 #define AS2(x, y) x, y*newline* 227 #define AS3(x, y, z) x, y, z*newline* 228 #define ASS(x, y, a, b, c, d) x, y, a*64+b*16+c*4+d*newline* 229 #define ASL(x) label##x:*newline* 230 #define ASJ(x, y, z) x label##y*newline* 231 #define ASC(x, y) x label##y*newline* 232 #define AS_HEX(y) 0##y##h 233 #elif defined(_MSC_VER) || defined(__BORLANDC__) 234 #define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY 235 #define AS1(x) __asm {x} 236 #define AS2(x, y) __asm {x, y} 237 #define AS3(x, y, z) __asm {x, y, z} 238 #define ASS(x, y, a, b, c, d) __asm {x, y, (a)*64+(b)*16+(c)*4+(d)} 239 #define ASL(x) __asm {label##x:} 240 #define ASJ(x, y, z) __asm {x label##y} 241 #define ASC(x, y) __asm {x label##y} 242 #define CRYPTOPP_NAKED __declspec(naked) 243 #define AS_HEX(y) 0x##y 245 #define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 247 #if defined(CRYPTOPP_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) 248 #define NEW_LINE "\n" 249 #define INTEL_PREFIX ".intel_syntax;" 250 #define INTEL_NOPREFIX ".intel_syntax;" 251 #define ATT_PREFIX ".att_syntax;" 252 #define ATT_NOPREFIX ".att_syntax;" 255 #define INTEL_PREFIX ".intel_syntax prefix;" 256 #define INTEL_NOPREFIX ".intel_syntax noprefix;" 257 #define ATT_PREFIX ".att_syntax prefix;" 258 #define ATT_NOPREFIX ".att_syntax noprefix;" 262 #define GNU_AS1(x) #x ";" NEW_LINE 263 #define GNU_AS2(x, y) #x ", " #y ";" NEW_LINE 264 #define GNU_AS3(x, y, z) #x ", " #y ", " #z ";" NEW_LINE 265 #define GNU_ASL(x) "\n" #x ":" NEW_LINE 266 #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE 267 #define AS1(x) GNU_AS1(x) 268 #define AS2(x, y) GNU_AS2(x, y) 269 #define AS3(x, y, z) GNU_AS3(x, y, z) 270 #define ASS(x, y, a, b, c, d) #x ", " #y ", " #a "*64+" #b "*16+" #c "*4+" #d ";" 271 #define ASL(x) GNU_ASL(x) 272 #define ASJ(x, y, z) GNU_ASJ(x, y, z) 273 #define ASC(x, y) #x " " #y ";" 274 #define CRYPTOPP_NAKED 275 #define AS_HEX(y) 0x##y 281 #ifdef CRYPTOPP_GENERATE_X64_MASM 282 #define ASM_MOD(x, y) ((x) MOD (y)) 283 #define XMMWORD_PTR XMMWORD PTR 286 #define ASM_MOD(x, y) ((x)-((x)/(y))*(y)) 291 #if CRYPTOPP_BOOL_X86 299 #define AS_REG_1d ecx 300 #define AS_REG_2d edx 301 #define AS_REG_3d esi 302 #define AS_REG_4d edi 303 #define AS_REG_5d eax 304 #define AS_REG_6d ebx 305 #define AS_REG_7d ebp 307 #define WORD_REG(x) e##x 308 #define WORD_PTR DWORD PTR 309 #define AS_PUSH_IF86(x) AS1(push e##x) 310 #define AS_POP_IF86(x) AS1(pop e##x) 311 #define AS_JCXZ jecxz 312 #elif CRYPTOPP_BOOL_X32 318 #define AS_REG_6 r10d 319 #define AS_REG_7 r11d 320 #define AS_REG_1d ecx 321 #define AS_REG_2d edx 322 #define AS_REG_3d r8d 323 #define AS_REG_4d r9d 324 #define AS_REG_5d eax 325 #define AS_REG_6d r10d 326 #define AS_REG_7d r11d 328 #define WORD_REG(x) e##x 329 #define WORD_PTR DWORD PTR 330 #define AS_PUSH_IF86(x) AS1(push r##x) 331 #define AS_POP_IF86(x) AS1(pop r##x) 332 #define AS_JCXZ jecxz 333 #elif CRYPTOPP_BOOL_X64 334 #ifdef CRYPTOPP_GENERATE_X64_MASM 342 #define AS_REG_1d ecx 343 #define AS_REG_2d edx 344 #define AS_REG_3d r8d 345 #define AS_REG_4d r9d 346 #define AS_REG_5d eax 347 #define AS_REG_6d r10d 348 #define AS_REG_7d r11d 357 #define AS_REG_1d edi 358 #define AS_REG_2d esi 359 #define AS_REG_3d edx 360 #define AS_REG_4d ecx 361 #define AS_REG_5d r8d 362 #define AS_REG_6d r9d 363 #define AS_REG_7d r10d 366 #define WORD_REG(x) r##x 367 #define WORD_PTR QWORD PTR 368 #define AS_PUSH_IF86(x) 369 #define AS_POP_IF86(x) 370 #define AS_JCXZ jrcxz 374 #define AS_XMM_OUTPUT4(labelPrefix, inputPtr, outputPtr, x0, x1, x2, x3, t, p0, p1, p2, p3, increment)\ 375 AS2( test inputPtr, inputPtr)\ 376 ASC( jz, labelPrefix##3)\ 377 AS2( test inputPtr, 15)\ 378 ASC( jnz, labelPrefix##7)\ 379 AS2( pxor xmm##x0, [inputPtr+p0*16])\ 380 AS2( pxor xmm##x1, [inputPtr+p1*16])\ 381 AS2( pxor xmm##x2, [inputPtr+p2*16])\ 382 AS2( pxor xmm##x3, [inputPtr+p3*16])\ 383 AS2( add inputPtr, increment*16)\ 384 ASC( jmp, labelPrefix##3)\ 386 AS2( movdqu xmm##t, [inputPtr+p0*16])\ 387 AS2( pxor xmm##x0, xmm##t)\ 388 AS2( movdqu xmm##t, [inputPtr+p1*16])\ 389 AS2( pxor xmm##x1, xmm##t)\ 390 AS2( movdqu xmm##t, [inputPtr+p2*16])\ 391 AS2( pxor xmm##x2, xmm##t)\ 392 AS2( movdqu xmm##t, [inputPtr+p3*16])\ 393 AS2( pxor xmm##x3, xmm##t)\ 394 AS2( add inputPtr, increment*16)\ 396 AS2( test outputPtr, 15)\ 397 ASC( jnz, labelPrefix##8)\ 398 AS2( movdqa [outputPtr+p0*16], xmm##x0)\ 399 AS2( movdqa [outputPtr+p1*16], xmm##x1)\ 400 AS2( movdqa [outputPtr+p2*16], xmm##x2)\ 401 AS2( movdqa [outputPtr+p3*16], xmm##x3)\ 402 ASC( jmp, labelPrefix##9)\ 404 AS2( movdqu [outputPtr+p0*16], xmm##x0)\ 405 AS2( movdqu [outputPtr+p1*16], xmm##x1)\ 406 AS2( movdqu [outputPtr+p2*16], xmm##x2)\ 407 AS2( movdqu [outputPtr+p3*16], xmm##x3)\ 409 AS2( add outputPtr, increment*16) Library configuration file.
Crypto++ library namespace.