x64_cpu_info.cpp
1 /* This file is part of the dynarmic project. 2 * Copyright (c) 2020 MerryMage 3 * SPDX-License-Identifier: 0BSD 4 */ 5 6 #include <array> 7 #include <cstddef> 8 #include <cstdint> 9 #include <cstdio> 10 #include <cstring> 11 #include <utility> 12 13 #include <catch2/catch_test_macros.hpp> 14 #include <xbyak/xbyak_util.h> 15 16 TEST_CASE("Host CPU supports", "[a64]") { 17 using Cpu = Xbyak::util::Cpu; 18 Cpu cpu_info; 19 20 std::array<std::uint32_t, 4> cpu_name; 21 for (std::uint32_t i = 2; i < 5; ++i) { 22 cpu_info.getCpuid(0x80000000 | i, cpu_name.data()); 23 std::printf("%.16s", reinterpret_cast<const char*>(cpu_name.data())); 24 } 25 std::putchar('\n'); 26 27 cpu_info.putFamily(); 28 const std::array types{ 29 #define X(NAME) std::make_pair(Cpu::Type{Cpu::NAME}, &#NAME[1]) 30 X(t3DN), 31 X(tADX), 32 X(tAESNI), 33 X(tAMD), 34 X(tAMX_BF16), 35 X(tAMX_INT8), 36 X(tAMX_TILE), 37 X(tAVX), 38 X(tAVX2), 39 X(tAVX512_4FMAPS), 40 X(tAVX512_4VNNIW), 41 X(tAVX512_BF16), 42 X(tAVX512_BITALG), 43 X(tAVX512_FP16), 44 X(tAVX512_IFMA), 45 X(tAVX512_VBMI), 46 X(tAVX512_VBMI2), 47 X(tAVX512_VNNI), 48 X(tAVX512_VP2INTERSECT), 49 X(tAVX512_VPOPCNTDQ), 50 X(tAVX512BW), 51 X(tAVX512CD), 52 X(tAVX512DQ), 53 X(tAVX512ER), 54 X(tAVX512F), 55 X(tAVX512IFMA), 56 X(tAVX512PF), 57 X(tAVX512VBMI), 58 X(tAVX512VL), 59 X(tAVX_VNNI), 60 X(tBMI1), 61 X(tBMI2), 62 X(tCLDEMOTE), 63 X(tCLFLUSHOPT), 64 X(tCLZERO), 65 X(tCMOV), 66 X(tE3DN), 67 X(tENHANCED_REP), 68 X(tF16C), 69 X(tFMA), 70 X(tGFNI), 71 X(tHLE), 72 X(tINTEL), 73 X(tLZCNT), 74 X(tMMX), 75 X(tMMX2), 76 X(tMOVBE), 77 X(tMOVDIR64B), 78 X(tMOVDIRI), 79 X(tMPX), 80 X(tOSXSAVE), 81 X(tPCLMULQDQ), 82 X(tPOPCNT), 83 X(tPREFETCHW), 84 X(tPREFETCHWT1), 85 X(tRDRAND), 86 X(tRDSEED), 87 X(tRDTSCP), 88 X(tRTM), 89 X(tSHA), 90 X(tSMAP), 91 X(tSSE), 92 X(tSSE2), 93 X(tSSE3), 94 X(tSSE41), 95 X(tSSE42), 96 X(tSSSE3), 97 X(tVAES), 98 X(tVPCLMULQDQ), 99 X(tWAITPKG), 100 #undef X 101 }; 102 103 constexpr std::size_t line_max = 80; 104 std::size_t line_length = 0; 105 for (const auto& [type, name] : types) { 106 if (cpu_info.has(type)) { 107 const std::size_t name_length = std::strlen(name) + 1; 108 if ((line_length + name_length) >= line_max) { 109 line_length = name_length; 110 std::putchar('\n'); 111 } else if (line_length) { 112 std::putchar(' '); 113 } 114 std::fputs(name, stdout); 115 line_length += name_length; 116 } 117 } 118 std::putchar('\n'); 119 }