You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.2 KiB

  1. #define STORMEIGEN_INTERNAL_DEBUG_CACHE_QUERY
  2. #include <iostream>
  3. #include "../StormEigen/Core"
  4. using namespace StormEigen;
  5. using namespace std;
  6. #define DUMP_CPUID(CODE) {\
  7. int abcd[4]; \
  8. abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;\
  9. STORMEIGEN_CPUID(abcd, CODE, 0); \
  10. std::cout << "The code " << CODE << " gives " \
  11. << (int*)(abcd[0]) << " " << (int*)(abcd[1]) << " " \
  12. << (int*)(abcd[2]) << " " << (int*)(abcd[3]) << " " << std::endl; \
  13. }
  14. int main()
  15. {
  16. cout << "Eigen's L1 = " << internal::queryL1CacheSize() << endl;
  17. cout << "Eigen's L2/L3 = " << internal::queryTopLevelCacheSize() << endl;
  18. int l1, l2, l3;
  19. internal::queryCacheSizes(l1, l2, l3);
  20. cout << "Eigen's L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
  21. #ifdef STORMEIGEN_CPUID
  22. int abcd[4];
  23. int string[8];
  24. char* string_char = (char*)(string);
  25. // vendor ID
  26. STORMEIGEN_CPUID(abcd,0x0,0);
  27. string[0] = abcd[1];
  28. string[1] = abcd[3];
  29. string[2] = abcd[2];
  30. string[3] = 0;
  31. cout << endl;
  32. cout << "vendor id = " << string_char << endl;
  33. cout << endl;
  34. int max_funcs = abcd[0];
  35. internal::queryCacheSizes_intel_codes(l1, l2, l3);
  36. cout << "Eigen's intel codes L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
  37. if(max_funcs>=4)
  38. {
  39. internal::queryCacheSizes_intel_direct(l1, l2, l3);
  40. cout << "Eigen's intel direct L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
  41. }
  42. internal::queryCacheSizes_amd(l1, l2, l3);
  43. cout << "Eigen's amd L1, L2, L3 = " << l1 << " " << l2 << " " << l3 << endl;
  44. cout << endl;
  45. // dump Intel direct method
  46. if(max_funcs>=4)
  47. {
  48. l1 = l2 = l3 = 0;
  49. int cache_id = 0;
  50. int cache_type = 0;
  51. do {
  52. abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
  53. STORMEIGEN_CPUID(abcd,0x4,cache_id);
  54. cache_type = (abcd[0] & 0x0F) >> 0;
  55. int cache_level = (abcd[0] & 0xE0) >> 5; // A[7:5]
  56. int ways = (abcd[1] & 0xFFC00000) >> 22; // B[31:22]
  57. int partitions = (abcd[1] & 0x003FF000) >> 12; // B[21:12]
  58. int line_size = (abcd[1] & 0x00000FFF) >> 0; // B[11:0]
  59. int sets = (abcd[2]); // C[31:0]
  60. int cache_size = (ways+1) * (partitions+1) * (line_size+1) * (sets+1);
  61. cout << "cache[" << cache_id << "].type = " << cache_type << "\n";
  62. cout << "cache[" << cache_id << "].level = " << cache_level << "\n";
  63. cout << "cache[" << cache_id << "].ways = " << ways << "\n";
  64. cout << "cache[" << cache_id << "].partitions = " << partitions << "\n";
  65. cout << "cache[" << cache_id << "].line_size = " << line_size << "\n";
  66. cout << "cache[" << cache_id << "].sets = " << sets << "\n";
  67. cout << "cache[" << cache_id << "].size = " << cache_size << "\n";
  68. cache_id++;
  69. } while(cache_type>0 && cache_id<16);
  70. }
  71. // dump everything
  72. std::cout << endl <<"Raw dump:" << endl;
  73. for(int i=0; i<max_funcs; ++i)
  74. DUMP_CPUID(i);
  75. DUMP_CPUID(0x80000000);
  76. DUMP_CPUID(0x80000001);
  77. DUMP_CPUID(0x80000002);
  78. DUMP_CPUID(0x80000003);
  79. DUMP_CPUID(0x80000004);
  80. DUMP_CPUID(0x80000005);
  81. DUMP_CPUID(0x80000006);
  82. DUMP_CPUID(0x80000007);
  83. DUMP_CPUID(0x80000008);
  84. #else
  85. cout << "STORMEIGEN_CPUID is not defined" << endl;
  86. #endif
  87. return 0;
  88. }