30 #ifndef CRYPTOPP_CPU_H 31 #define CRYPTOPP_CPU_H 36 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 37 # pragma GCC diagnostic push 38 # pragma GCC diagnostic ignored "-Wconversion" 39 # pragma GCC diagnostic ignored "-Wsign-conversion" 43 #if defined(CRYPTOPP_LLVM_CLANG_VERSION) || defined(CRYPTOPP_APPLE_CLANG_VERSION) || defined(CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER) 45 #define INTEL_PREFIX ".intel_syntax;" 46 #define INTEL_NOPREFIX ".intel_syntax;" 47 #define ATT_PREFIX ".att_syntax;" 48 #define ATT_NOPREFIX ".att_syntax;" 49 #elif defined(__GNUC__) 51 #define INTEL_PREFIX ".intel_syntax prefix;" 52 #define INTEL_NOPREFIX ".intel_syntax noprefix;" 53 #define ATT_PREFIX ".att_syntax prefix;" 54 #define ATT_NOPREFIX ".att_syntax noprefix;" 58 #define INTEL_NOPREFIX 63 #ifdef CRYPTOPP_GENERATE_X64_MASM 65 #define CRYPTOPP_X86_ASM_AVAILABLE 66 #define CRYPTOPP_BOOL_X64 1 67 #define CRYPTOPP_SSE2_ASM_AVAILABLE 1 76 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 || CRYPTOPP_DOXYGEN_PROCESSING 78 #define CRYPTOPP_CPUID_AVAILABLE 1 81 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 83 extern CRYPTOPP_DLL
bool g_x86DetectionDone;
84 extern CRYPTOPP_DLL
bool g_hasSSE2;
85 extern CRYPTOPP_DLL
bool g_hasSSSE3;
86 extern CRYPTOPP_DLL
bool g_hasSSE41;
87 extern CRYPTOPP_DLL
bool g_hasSSE42;
88 extern CRYPTOPP_DLL
bool g_hasAESNI;
89 extern CRYPTOPP_DLL
bool g_hasCLMUL;
90 extern CRYPTOPP_DLL
bool g_hasSHA;
91 extern CRYPTOPP_DLL
bool g_hasADX;
92 extern CRYPTOPP_DLL
bool g_isP4;
93 extern CRYPTOPP_DLL
bool g_hasRDRAND;
94 extern CRYPTOPP_DLL
bool g_hasRDSEED;
95 extern CRYPTOPP_DLL
bool g_hasPadlockRNG;
96 extern CRYPTOPP_DLL
bool g_hasPadlockACE;
97 extern CRYPTOPP_DLL
bool g_hasPadlockACE2;
98 extern CRYPTOPP_DLL
bool g_hasPadlockPHE;
99 extern CRYPTOPP_DLL
bool g_hasPadlockPMM;
100 extern CRYPTOPP_DLL word32 g_cacheLineSize;
102 CRYPTOPP_DLL
void CRYPTOPP_API DetectX86Features();
103 CRYPTOPP_DLL
bool CRYPTOPP_API CpuId(word32 func, word32 subfunc, word32 output[4]);
104 #endif // CRYPTOPP_DOXYGEN_PROCESSING 116 #if CRYPTOPP_BOOL_X64 119 if (!g_x86DetectionDone)
131 if (!g_x86DetectionDone)
142 if (!g_x86DetectionDone)
153 if (!g_x86DetectionDone)
164 if (!g_x86DetectionDone)
175 if (!g_x86DetectionDone)
186 if (!g_x86DetectionDone)
197 if (!g_x86DetectionDone)
208 if (!g_x86DetectionDone)
219 if (!g_x86DetectionDone)
230 if (!g_x86DetectionDone)
241 if (!g_x86DetectionDone)
243 return g_hasPadlockRNG;
252 if (!g_x86DetectionDone)
254 return g_hasPadlockACE;
263 if (!g_x86DetectionDone)
265 return g_hasPadlockACE2;
274 if (!g_x86DetectionDone)
276 return g_hasPadlockPHE;
285 if (!g_x86DetectionDone)
287 return g_hasPadlockPMM;
300 if (!g_x86DetectionDone)
302 return g_cacheLineSize;
306 #endif // CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 310 #if CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64 || CRYPTOPP_DOXYGEN_PROCESSING 313 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 314 extern bool g_ArmDetectionDone;
315 extern bool g_hasNEON, g_hasPMULL, g_hasCRC32, g_hasAES, g_hasSHA1, g_hasSHA2;
316 void CRYPTOPP_API DetectArmFeatures();
317 #endif // CRYPTOPP_DOXYGEN_PROCESSING 332 #if defined(__aarch32__) || defined(__aarch64__) 335 if (!g_ArmDetectionDone)
350 #if defined(__aarch32__) || defined(__aarch64__) 351 if (!g_ArmDetectionDone)
369 #if defined(__aarch32__) || defined(__aarch64__) 370 if (!g_ArmDetectionDone)
388 #if defined(__aarch32__) || defined(__aarch64__) 389 if (!g_ArmDetectionDone)
407 #if defined(__aarch32__) || defined(__aarch64__) 408 if (!g_ArmDetectionDone)
426 #if defined(__aarch32__) || defined(__aarch64__) 427 if (!g_ArmDetectionDone)
437 #endif // CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64 441 #if CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64 || CRYPTOPP_DOXYGEN_PROCESSING 444 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 445 extern bool g_PowerpcDetectionDone;
446 extern bool g_hasAltivec, g_hasPower7, g_hasPower8, g_hasAES, g_hasSHA256, g_hasSHA512;
447 extern word32 g_cacheLineSize;
448 void CRYPTOPP_API DetectPowerpcFeatures();
449 #endif // CRYPTOPP_DOXYGEN_PROCESSING 466 if (!g_PowerpcDetectionDone)
467 DetectPowerpcFeatures();
483 if (!g_PowerpcDetectionDone)
484 DetectPowerpcFeatures();
500 if (!g_PowerpcDetectionDone)
501 DetectPowerpcFeatures();
514 if (!g_PowerpcDetectionDone)
515 DetectPowerpcFeatures();
528 if (!g_PowerpcDetectionDone)
529 DetectPowerpcFeatures();
542 if (!g_PowerpcDetectionDone)
543 DetectPowerpcFeatures();
557 if (!g_PowerpcDetectionDone)
558 DetectPowerpcFeatures();
559 return g_cacheLineSize;
564 #endif // CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64 569 #if !(CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) 580 return CRYPTOPP_L1_CACHE_LINE_SIZE;
582 #endif // Non-Intel systems 584 #endif // CRYPTOPP_GENERATE_X64_MASM 588 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 590 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 592 #ifdef CRYPTOPP_GENERATE_X64_MASM 593 #define AS1(x) x*newline* 594 #define AS2(x, y) x, y*newline* 595 #define AS3(x, y, z) x, y, z*newline* 596 #define ASS(x, y, a, b, c, d) x, y, a*64+b*16+c*4+d*newline* 597 #define ASL(x) label##x:*newline* 598 #define ASJ(x, y, z) x label##y*newline* 599 #define ASC(x, y) x label##y*newline* 600 #define AS_HEX(y) 0##y##h 601 #elif defined(_MSC_VER) || defined(__BORLANDC__) 602 #define AS1(x) __asm {x} 603 #define AS2(x, y) __asm {x, y} 604 #define AS3(x, y, z) __asm {x, y, z} 605 #define ASS(x, y, a, b, c, d) __asm {x, y, (a)*64+(b)*16+(c)*4+(d)} 606 #define ASL(x) __asm {label##x:} 607 #define ASJ(x, y, z) __asm {x label##y} 608 #define ASC(x, y) __asm {x label##y} 609 #define CRYPTOPP_NAKED __declspec(naked) 610 #define AS_HEX(y) 0x##y 613 #define GNU_AS1(x) #x ";" NEW_LINE 614 #define GNU_AS2(x, y) #x ", " #y ";" NEW_LINE 615 #define GNU_AS3(x, y, z) #x ", " #y ", " #z ";" NEW_LINE 616 #define GNU_ASL(x) "\n" #x ":" NEW_LINE 617 #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE 618 #define AS1(x) GNU_AS1(x) 619 #define AS2(x, y) GNU_AS2(x, y) 620 #define AS3(x, y, z) GNU_AS3(x, y, z) 621 #define ASS(x, y, a, b, c, d) #x ", " #y ", " #a "*64+" #b "*16+" #c "*4+" #d ";" 622 #define ASL(x) GNU_ASL(x) 623 #define ASJ(x, y, z) GNU_ASJ(x, y, z) 624 #define ASC(x, y) #x " " #y ";" 625 #define CRYPTOPP_NAKED 626 #define AS_HEX(y) 0x##y 632 #ifdef CRYPTOPP_GENERATE_X64_MASM 633 #define ASM_MOD(x, y) ((x) MOD (y)) 634 #define XMMWORD_PTR XMMWORD PTR 637 #define ASM_MOD(x, y) ((x)-((x)/(y))*(y)) 642 #if CRYPTOPP_BOOL_X86 650 #define AS_REG_1d ecx 651 #define AS_REG_2d edx 652 #define AS_REG_3d esi 653 #define AS_REG_4d edi 654 #define AS_REG_5d eax 655 #define AS_REG_6d ebx 656 #define AS_REG_7d ebp 658 #define WORD_REG(x) e##x 659 #define WORD_PTR DWORD PTR 660 #define AS_PUSH_IF86(x) AS1(push e##x) 661 #define AS_POP_IF86(x) AS1(pop e##x) 662 #define AS_JCXZ jecxz 663 #elif CRYPTOPP_BOOL_X32 669 #define AS_REG_6 r10d 670 #define AS_REG_7 r11d 671 #define AS_REG_1d ecx 672 #define AS_REG_2d edx 673 #define AS_REG_3d r8d 674 #define AS_REG_4d r9d 675 #define AS_REG_5d eax 676 #define AS_REG_6d r10d 677 #define AS_REG_7d r11d 679 #define WORD_REG(x) e##x 680 #define WORD_PTR DWORD PTR 681 #define AS_PUSH_IF86(x) AS1(push r##x) 682 #define AS_POP_IF86(x) AS1(pop r##x) 683 #define AS_JCXZ jecxz 684 #elif CRYPTOPP_BOOL_X64 685 #ifdef CRYPTOPP_GENERATE_X64_MASM 693 #define AS_REG_1d ecx 694 #define AS_REG_2d edx 695 #define AS_REG_3d r8d 696 #define AS_REG_4d r9d 697 #define AS_REG_5d eax 698 #define AS_REG_6d r10d 699 #define AS_REG_7d r11d 708 #define AS_REG_1d edi 709 #define AS_REG_2d esi 710 #define AS_REG_3d edx 711 #define AS_REG_4d ecx 712 #define AS_REG_5d r8d 713 #define AS_REG_6d r9d 714 #define AS_REG_7d r10d 717 #define WORD_REG(x) r##x 718 #define WORD_PTR QWORD PTR 719 #define AS_PUSH_IF86(x) 720 #define AS_POP_IF86(x) 721 #define AS_JCXZ jrcxz 725 #define AS_XMM_OUTPUT4(labelPrefix, inputPtr, outputPtr, x0, x1, x2, x3, t, p0, p1, p2, p3, increment)\ 726 AS2( test inputPtr, inputPtr)\ 727 ASC( jz, labelPrefix##3)\ 728 AS2( test inputPtr, 15)\ 729 ASC( jnz, labelPrefix##7)\ 730 AS2( pxor xmm##x0, [inputPtr+p0*16])\ 731 AS2( pxor xmm##x1, [inputPtr+p1*16])\ 732 AS2( pxor xmm##x2, [inputPtr+p2*16])\ 733 AS2( pxor xmm##x3, [inputPtr+p3*16])\ 734 AS2( add inputPtr, increment*16)\ 735 ASC( jmp, labelPrefix##3)\ 737 AS2( movdqu xmm##t, [inputPtr+p0*16])\ 738 AS2( pxor xmm##x0, xmm##t)\ 739 AS2( movdqu xmm##t, [inputPtr+p1*16])\ 740 AS2( pxor xmm##x1, xmm##t)\ 741 AS2( movdqu xmm##t, [inputPtr+p2*16])\ 742 AS2( pxor xmm##x2, xmm##t)\ 743 AS2( movdqu xmm##t, [inputPtr+p3*16])\ 744 AS2( pxor xmm##x3, xmm##t)\ 745 AS2( add inputPtr, increment*16)\ 747 AS2( test outputPtr, 15)\ 748 ASC( jnz, labelPrefix##8)\ 749 AS2( movdqa [outputPtr+p0*16], xmm##x0)\ 750 AS2( movdqa [outputPtr+p1*16], xmm##x1)\ 751 AS2( movdqa [outputPtr+p2*16], xmm##x2)\ 752 AS2( movdqa [outputPtr+p3*16], xmm##x3)\ 753 ASC( jmp, labelPrefix##9)\ 755 AS2( movdqu [outputPtr+p0*16], xmm##x0)\ 756 AS2( movdqu [outputPtr+p1*16], xmm##x1)\ 757 AS2( movdqu [outputPtr+p2*16], xmm##x2)\ 758 AS2( movdqu [outputPtr+p3*16], xmm##x3)\ 760 AS2( add outputPtr, increment*16) 762 #endif // CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 764 #endif // Not CRYPTOPP_DOXYGEN_PROCESSING 769 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 770 # pragma GCC diagnostic pop 773 #endif // CRYPTOPP_CPU_H bool HasSHA()
Determines SHA availability.
bool HasAltivec()
Determine if a PowerPC processor has Altivec available.
bool HasCRC32()
Determine if an ARM processor has CRC32 available.
bool HasSSSE3()
Determines SSSE3 availability.
bool HasADX()
Determines ADX availability.
bool HasPadlockRNG()
Determines Padlock RNG availability.
bool HasAES()
Determine if an ARM processor has AES available.
bool IsP4()
Determines if the CPU is an Intel P4.
Library configuration file.
int GetCacheLineSize()
Provides the cache line size.
bool HasRDRAND()
Determines RDRAND availability.
bool HasPower7()
Determine if a PowerPC processor has Power8 available.
bool HasSHA256()
Determine if a PowerPC processor has SHA256 available.
bool HasPower8()
Determine if a PowerPC processor has Power8 available.
bool HasRDSEED()
Determines RDSEED availability.
bool HasCLMUL()
Determines Carryless Multiply availability.
bool HasSHA1()
Determine if an ARM processor has SHA1 available.
bool HasSHA512()
Determine if a PowerPC processor has SHA512 available.
bool HasPadlockACE2()
Determines Padlock ACE2 availability.
bool HasPadlockPHE()
Determines Padlock PHE availability.
bool HasPadlockPMM()
Determines Padlock PMM availability.
bool HasAESNI()
Determines AES-NI availability.
bool HasSSE2()
Determines SSE2 availability.
bool HasSHA2()
Determine if an ARM processor has SHA2 available.
bool HasSSE41()
Determines SSE4.1 availability.
Crypto++ library namespace.
bool HasPadlockACE()
Determines Padlock ACE availability.
bool HasSSE42()
Determines SSE4.2 availability.
bool HasPMULL()
Determine if an ARM processor provides Polynomial Multiplication.
bool HasNEON()
Determine if an ARM processor has Advanced SIMD available.