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) 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 64 #define PERCENT_PASTE(x) "%" #x 65 #define PERCENT_REG(x) PERCENT_PASTE(x) 67 #ifdef CRYPTOPP_GENERATE_X64_MASM 69 #define CRYPTOPP_X86_ASM_AVAILABLE 70 #define CRYPTOPP_BOOL_X64 1 71 #define CRYPTOPP_SSE2_ASM_AVAILABLE 1 80 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 || CRYPTOPP_DOXYGEN_PROCESSING 82 #define CRYPTOPP_CPUID_AVAILABLE 1 85 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 87 extern CRYPTOPP_DLL
bool g_x86DetectionDone;
88 extern CRYPTOPP_DLL
bool g_hasSSE2;
89 extern CRYPTOPP_DLL
bool g_hasSSSE3;
90 extern CRYPTOPP_DLL
bool g_hasSSE41;
91 extern CRYPTOPP_DLL
bool g_hasSSE42;
92 extern CRYPTOPP_DLL
bool g_hasMOVBE;
93 extern CRYPTOPP_DLL
bool g_hasAESNI;
94 extern CRYPTOPP_DLL
bool g_hasCLMUL;
95 extern CRYPTOPP_DLL
bool g_hasAVX;
96 extern CRYPTOPP_DLL
bool g_hasAVX2;
97 extern CRYPTOPP_DLL
bool g_hasSHA;
98 extern CRYPTOPP_DLL
bool g_hasADX;
99 extern CRYPTOPP_DLL
bool g_isP4;
100 extern CRYPTOPP_DLL
bool g_hasRDRAND;
101 extern CRYPTOPP_DLL
bool g_hasRDSEED;
102 extern CRYPTOPP_DLL
bool g_hasPadlockRNG;
103 extern CRYPTOPP_DLL
bool g_hasPadlockACE;
104 extern CRYPTOPP_DLL
bool g_hasPadlockACE2;
105 extern CRYPTOPP_DLL
bool g_hasPadlockPHE;
106 extern CRYPTOPP_DLL
bool g_hasPadlockPMM;
107 extern CRYPTOPP_DLL
word32 g_cacheLineSize;
111 #endif // CRYPTOPP_DOXYGEN_PROCESSING 122 inline bool HasSSE2()
124 #if (CRYPTOPP_SSE2_ASM_AVAILABLE || CRYPTOPP_SSE2_INTRIN_AVAILABLE) 125 if (!g_x86DetectionDone)
137 inline bool HasSSSE3()
139 #if CRYPTOPP_SSSE3_AVAILABLE 140 if (!g_x86DetectionDone)
152 inline bool HasSSE41()
154 #if CRYPTOPP_SSE41_AVAILABLE 155 if (!g_x86DetectionDone)
167 inline bool HasSSE42()
169 #if CRYPTOPP_SSE42_AVAILABLE 170 if (!g_x86DetectionDone)
183 inline bool HasMOVBE()
185 #if CRYPTOPP_SSE42_AVAILABLE 186 if (!g_x86DetectionDone)
199 inline bool HasAESNI()
201 #if CRYPTOPP_AESNI_AVAILABLE 202 if (!g_x86DetectionDone)
215 inline bool HasCLMUL()
217 #if CRYPTOPP_CLMUL_AVAILABLE 218 if (!g_x86DetectionDone)
233 #if CRYPTOPP_SHANI_AVAILABLE 234 if (!g_x86DetectionDone)
249 #if CRYPTOPP_ADX_AVAILABLE 250 if (!g_x86DetectionDone)
265 #if CRYPTOPP_AVX_AVAILABLE 266 if (!g_x86DetectionDone)
279 inline bool HasAVX2()
281 #if CRYPTOPP_AVX2_AVAILABLE 282 if (!g_x86DetectionDone)
294 inline bool HasRDRAND()
296 #if CRYPTOPP_RDRAND_AVAILABLE 297 if (!g_x86DetectionDone)
309 inline bool HasRDSEED()
311 #if CRYPTOPP_RDSEED_AVAILABLE 312 if (!g_x86DetectionDone)
324 inline bool HasPadlockRNG()
326 #if CRYPTOPP_PADLOCK_RNG_AVAILABLE 327 if (!g_x86DetectionDone)
329 return g_hasPadlockRNG;
339 inline bool HasPadlockACE()
341 #if CRYPTOPP_PADLOCK_ACE_AVAILABLE 342 if (!g_x86DetectionDone)
344 return g_hasPadlockACE;
354 inline bool HasPadlockACE2()
356 #if CRYPTOPP_PADLOCK_ACE2_AVAILABLE 357 if (!g_x86DetectionDone)
359 return g_hasPadlockACE2;
369 inline bool HasPadlockPHE()
371 #if CRYPTOPP_PADLOCK_PHE_AVAILABLE 372 if (!g_x86DetectionDone)
374 return g_hasPadlockPHE;
384 inline bool HasPadlockPMM()
386 #if CRYPTOPP_PADLOCK_PMM_AVAILABLE 387 if (!g_x86DetectionDone)
389 return g_hasPadlockPMM;
401 if (!g_x86DetectionDone)
414 inline int GetCacheLineSize()
416 if (!g_x86DetectionDone)
418 return g_cacheLineSize;
422 #endif // CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 426 #if CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8 || CRYPTOPP_DOXYGEN_PROCESSING 429 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 430 extern bool g_ArmDetectionDone;
431 extern bool g_hasARMv7;
432 extern bool g_hasNEON;
433 extern bool g_hasPMULL;
434 extern bool g_hasCRC32;
435 extern bool g_hasAES;
436 extern bool g_hasSHA1;
437 extern bool g_hasSHA2;
438 extern bool g_hasSHA512;
439 extern bool g_hasSHA3;
440 extern bool g_hasSM3;
441 extern bool g_hasSM4;
443 #endif // CRYPTOPP_DOXYGEN_PROCESSING 453 inline bool HasARMv7()
456 #if defined(__aarch32__) || defined(__aarch64__) 459 if (!g_ArmDetectionDone)
473 inline bool HasNEON()
476 #if defined(CRYPTOPP_ARM_ASIMD_AVAILABLE) 478 #elif defined(CRYPTOPP_ARM_NEON_AVAILABLE) 479 if (!g_ArmDetectionDone)
497 inline bool HasCRC32()
499 #if defined(CRYPTOPP_ARM_CRC32_AVAILABLE) 500 if (!g_ArmDetectionDone)
519 #if defined(CRYPTOPP_ARM_AES_AVAILABLE) 520 if (!g_ArmDetectionDone)
537 inline bool HasPMULL()
539 #if defined(CRYPTOPP_ARM_PMULL_AVAILABLE) 540 if (!g_ArmDetectionDone)
557 inline bool HasSHA1()
559 #if defined(CRYPTOPP_ARM_SHA1_AVAILABLE) 560 if (!g_ArmDetectionDone)
577 inline bool HasSHA2()
579 #if defined(CRYPTOPP_ARM_SHA2_AVAILABLE) 580 if (!g_ArmDetectionDone)
597 inline bool HasSHA3()
599 #if defined(CRYPTOPP_ARM_SHA3_AVAILABLE) 600 if (!g_ArmDetectionDone)
617 inline bool HasSHA512()
619 #if defined(CRYPTOPP_ARM_SHA512_AVAILABLE) 620 if (!g_ArmDetectionDone)
639 #if defined(CRYPTOPP_ARM_SM3_AVAILABLE) 640 if (!g_ArmDetectionDone)
659 #if defined(CRYPTOPP_ARM_SM4_AVAILABLE) 660 if (!g_ArmDetectionDone)
670 #endif // CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARMV8 674 #if CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64 || CRYPTOPP_DOXYGEN_PROCESSING 677 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 678 extern bool g_PowerPcDetectionDone;
679 extern bool g_hasAltivec;
680 extern bool g_hasPower7;
681 extern bool g_hasPower8;
682 extern bool g_hasPower9;
683 extern bool g_hasAES;
684 extern bool g_hasPMULL;
685 extern bool g_hasSHA256;
686 extern bool g_hasSHA512;
687 extern bool g_hasDARN;
688 extern word32 g_cacheLineSize;
690 #endif // CRYPTOPP_DOXYGEN_PROCESSING 702 inline bool HasAltivec()
704 #if CRYPTOPP_ALTIVEC_AVAILABLE 705 if (!g_PowerPcDetectionDone)
706 DetectPowerPcFeatures();
719 inline bool HasPower7()
721 #if CRYPTOPP_POWER7_AVAILABLE 722 if (!g_PowerPcDetectionDone)
723 DetectPowerPcFeatures();
736 inline bool HasPower8()
738 #if CRYPTOPP_POWER8_AVAILABLE 739 if (!g_PowerPcDetectionDone)
740 DetectPowerPcFeatures();
753 inline bool HasPower9()
755 #if CRYPTOPP_POWER9_AVAILABLE 756 if (!g_PowerPcDetectionDone)
757 DetectPowerPcFeatures();
773 #if CRYPTOPP_POWER8_AES_AVAILABLE 774 if (!g_PowerPcDetectionDone)
775 DetectPowerPcFeatures();
789 inline bool HasPMULL()
791 #if CRYPTOPP_POWER8_VMULL_AVAILABLE 792 if (!g_PowerPcDetectionDone)
793 DetectPowerPcFeatures();
807 inline bool HasSHA256()
809 #if CRYPTOPP_POWER8_SHA_AVAILABLE 810 if (!g_PowerPcDetectionDone)
811 DetectPowerPcFeatures();
825 inline bool HasSHA512()
827 #if CRYPTOPP_POWER8_SHA_AVAILABLE 828 if (!g_PowerPcDetectionDone)
829 DetectPowerPcFeatures();
842 inline bool HasDARN()
844 #if CRYPTOPP_POWER9_AVAILABLE 845 if (!g_PowerPcDetectionDone)
846 DetectPowerPcFeatures();
848 # if defined(__ibmxl__) && defined(__linux__) 866 inline int GetCacheLineSize()
868 if (!g_PowerPcDetectionDone)
869 DetectPowerPcFeatures();
870 return g_cacheLineSize;
875 #endif // CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64 880 #if !(CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) 889 inline int GetCacheLineSize()
893 #endif // Non-Intel systems 895 #endif // CRYPTOPP_GENERATE_X64_MASM 899 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 901 #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 903 #ifdef CRYPTOPP_GENERATE_X64_MASM 904 #define AS1(x) x*newline* 905 #define AS2(x, y) x, y*newline* 906 #define AS3(x, y, z) x, y, z*newline* 907 #define ASS(x, y, a, b, c, d) x, y, a*64+b*16+c*4+d*newline* 908 #define ASL(x) label##x:*newline* 909 #define ASJ(x, y, z) x label##y*newline* 910 #define ASC(x, y) x label##y*newline* 911 #define AS_HEX(y) 0##y##h 912 #elif defined(_MSC_VER) || defined(__BORLANDC__) 913 #define AS1(x) __asm {x} 914 #define AS2(x, y) __asm {x, y} 915 #define AS3(x, y, z) __asm {x, y, z} 916 #define ASS(x, y, a, b, c, d) __asm {x, y, (a)*64+(b)*16+(c)*4+(d)} 917 #define ASL(x) __asm {label##x:} 918 #define ASJ(x, y, z) __asm {x label##y} 919 #define ASC(x, y) __asm {x label##y} 920 #define CRYPTOPP_NAKED __declspec(naked) 921 #define AS_HEX(y) 0x##y 924 #define GNU_AS1(x) #x ";" NEW_LINE 925 #define GNU_AS2(x, y) #x ", " #y ";" NEW_LINE 926 #define GNU_AS3(x, y, z) #x ", " #y ", " #z ";" NEW_LINE 927 #define GNU_ASL(x) "\n" #x ":" NEW_LINE 929 #if (CRYPTOPP_LLVM_CLANG_VERSION >= 50000) || (CRYPTOPP_APPLE_CLANG_VERSION >= 90000) 930 #define GNU_ASJ(x, y, z) ATT_PREFIX ";" NEW_LINE #x " " #y #z ";" NEW_LINE INTEL_PREFIX ";" NEW_LINE 932 #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE 934 #define AS1(x) GNU_AS1(x) 935 #define AS2(x, y) GNU_AS2(x, y) 936 #define AS3(x, y, z) GNU_AS3(x, y, z) 937 #define ASS(x, y, a, b, c, d) #x ", " #y ", " #a "*64+" #b "*16+" #c "*4+" #d ";" 938 #define ASL(x) GNU_ASL(x) 939 #define ASJ(x, y, z) GNU_ASJ(x, y, z) 940 #define ASC(x, y) #x " " #y ";" 941 #define CRYPTOPP_NAKED 942 #define AS_HEX(y) 0x##y 948 #ifdef CRYPTOPP_GENERATE_X64_MASM 949 #define ASM_MOD(x, y) ((x) MOD (y)) 950 #define XMMWORD_PTR XMMWORD PTR 953 #define ASM_MOD(x, y) ((x)-((x)/(y))*(y)) 958 #if CRYPTOPP_BOOL_X86 966 #define AS_REG_1d ecx 967 #define AS_REG_2d edx 968 #define AS_REG_3d esi 969 #define AS_REG_4d edi 970 #define AS_REG_5d eax 971 #define AS_REG_6d ebx 972 #define AS_REG_7d ebp 974 #define WORD_REG(x) e##x 975 #define WORD_PTR DWORD PTR 976 #define AS_PUSH_IF86(x) AS1(push e##x) 977 #define AS_POP_IF86(x) AS1(pop e##x) 978 #define AS_JCXZ jecxz 979 #elif CRYPTOPP_BOOL_X32 985 #define AS_REG_6 r10d 986 #define AS_REG_7 r11d 987 #define AS_REG_1d ecx 988 #define AS_REG_2d edx 989 #define AS_REG_3d r8d 990 #define AS_REG_4d r9d 991 #define AS_REG_5d eax 992 #define AS_REG_6d r10d 993 #define AS_REG_7d r11d 995 #define WORD_REG(x) e##x 996 #define WORD_PTR DWORD PTR 997 #define AS_PUSH_IF86(x) AS1(push r##x) 998 #define AS_POP_IF86(x) AS1(pop r##x) 999 #define AS_JCXZ jecxz 1000 #elif CRYPTOPP_BOOL_X64 1001 #ifdef CRYPTOPP_GENERATE_X64_MASM 1002 #define AS_REG_1 rcx 1003 #define AS_REG_2 rdx 1006 #define AS_REG_5 rax 1007 #define AS_REG_6 r10 1008 #define AS_REG_7 r11 1009 #define AS_REG_1d ecx 1010 #define AS_REG_2d edx 1011 #define AS_REG_3d r8d 1012 #define AS_REG_4d r9d 1013 #define AS_REG_5d eax 1014 #define AS_REG_6d r10d 1015 #define AS_REG_7d r11d 1017 #define AS_REG_1 rdi 1018 #define AS_REG_2 rsi 1019 #define AS_REG_3 rdx 1020 #define AS_REG_4 rcx 1023 #define AS_REG_7 r10 1024 #define AS_REG_1d edi 1025 #define AS_REG_2d esi 1026 #define AS_REG_3d edx 1027 #define AS_REG_4d ecx 1028 #define AS_REG_5d r8d 1029 #define AS_REG_6d r9d 1030 #define AS_REG_7d r10d 1033 #define WORD_REG(x) r##x 1034 #define WORD_PTR QWORD PTR 1035 #define AS_PUSH_IF86(x) 1036 #define AS_POP_IF86(x) 1037 #define AS_JCXZ jrcxz 1041 #define AS_XMM_OUTPUT4(labelPrefix, inputPtr, outputPtr, x0, x1, x2, x3, t, p0, p1, p2, p3, increment)\ 1042 AS2( test inputPtr, inputPtr)\ 1043 ASC( jz, labelPrefix##3)\ 1044 AS2( test inputPtr, 15)\ 1045 ASC( jnz, labelPrefix##7)\ 1046 AS2( pxor xmm##x0, [inputPtr+p0*16])\ 1047 AS2( pxor xmm##x1, [inputPtr+p1*16])\ 1048 AS2( pxor xmm##x2, [inputPtr+p2*16])\ 1049 AS2( pxor xmm##x3, [inputPtr+p3*16])\ 1050 AS2( add inputPtr, increment*16)\ 1051 ASC( jmp, labelPrefix##3)\ 1052 ASL(labelPrefix##7)\ 1053 AS2( movdqu xmm##t, [inputPtr+p0*16])\ 1054 AS2( pxor xmm##x0, xmm##t)\ 1055 AS2( movdqu xmm##t, [inputPtr+p1*16])\ 1056 AS2( pxor xmm##x1, xmm##t)\ 1057 AS2( movdqu xmm##t, [inputPtr+p2*16])\ 1058 AS2( pxor xmm##x2, xmm##t)\ 1059 AS2( movdqu xmm##t, [inputPtr+p3*16])\ 1060 AS2( pxor xmm##x3, xmm##t)\ 1061 AS2( add inputPtr, increment*16)\ 1062 ASL(labelPrefix##3)\ 1063 AS2( test outputPtr, 15)\ 1064 ASC( jnz, labelPrefix##8)\ 1065 AS2( movdqa [outputPtr+p0*16], xmm##x0)\ 1066 AS2( movdqa [outputPtr+p1*16], xmm##x1)\ 1067 AS2( movdqa [outputPtr+p2*16], xmm##x2)\ 1068 AS2( movdqa [outputPtr+p3*16], xmm##x3)\ 1069 ASC( jmp, labelPrefix##9)\ 1070 ASL(labelPrefix##8)\ 1071 AS2( movdqu [outputPtr+p0*16], xmm##x0)\ 1072 AS2( movdqu [outputPtr+p1*16], xmm##x1)\ 1073 AS2( movdqu [outputPtr+p2*16], xmm##x2)\ 1074 AS2( movdqu [outputPtr+p3*16], xmm##x3)\ 1075 ASL(labelPrefix##9)\ 1076 AS2( add outputPtr, increment*16) 1078 #endif // CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64 1080 #endif // Not CRYPTOPP_DOXYGEN_PROCESSING 1085 #if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE 1086 # pragma GCC diagnostic pop 1089 #endif // CRYPTOPP_CPU_H #define CRYPTOPP_L1_CACHE_LINE_SIZE
L1 data cache line size.
#define CRYPTOPP_API
Win32 calling convention.
unsigned int word32
32-bit unsigned datatype
Library configuration file.
Crypto++ library namespace.