C/C++ 宏获取当前编译程序工作的CPU指令集平台(综合大全覆盖各类CPU)
参考:https://blog.csdn.net/liulilittle/article/details/126644547?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-126644547-blog-43935465.235%5Ev38%5Epc_relevant_default_base3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-126644547-blog-43935465.235%5Ev38%5Epc_relevant_default_base3&utm_relevant_index=11
可以参考下方连接头文件内的部分代码
GetCipherSuites 函数获取当前缺省SSL/TLS加密算法列表6
ARM64以前跑 chacha20,ARM32的CPU速度快。
const char* GetCipherSuites() noexcept { #if !(defined(__aarch64__) || defined(_M_ARM64)) if (strstr(GetPlatformCode(), "ARM")) { return "TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384"; } #endif return "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"; }
GetPlatformCode 函数获取当前CPU指令集平台
const char* GetPlatformCode() noexcept { #if defined(__x86_64__) || defined(_M_X64) return "x86_64"; #elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) return "x86_32"; #elif defined(__ARM_ARCH_2__) return "ARM2"; #elif defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) return "ARM3"; #elif defined(__ARM_ARCH_4T__) || defined(__TARGET_ARM_4T) return "ARM4T"; #elif defined(__ARM_ARCH_5_) || defined(__ARM_ARCH_5E_) return "ARM5" #elif defined(__ARM_ARCH_6T2_) || defined(__ARM_ARCH_6T2_) return "ARM6T2"; #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) return "ARM6"; #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) return "ARM7"; #elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) return "ARM7A"; #elif defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) return "ARM7R"; #elif defined(__ARM_ARCH_7M__) return "ARM7M"; #elif defined(__ARM_ARCH_7S__) return "ARM7S"; #elif defined(__aarch64__) || defined(_M_ARM64) return "ARM64"; #elif defined(mips) || defined(__mips__) || defined(__mips) return "MIPS"; #elif defined(__sh__) return "SUPERH"; #elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__) || defined(__POWERPC__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC) return "POWERPC"; #elif defined(__PPC64__) || defined(__ppc64__) || defined(_ARCH_PPC64) return "POWERPC64"; #elif defined(__sparc__) || defined(__sparc) return "SPARC"; #elif defined(__m68k__) return "M68K"; #elif defined(__s390x__) return "S390X"; #else return "UNKNOWN"; #endif }
实测有用: