x64_cpu_info.cpp 2.8 KB

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