A collection of basic/generally desirable code I use across multiple C++ projects.
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.

149 lines
4.0 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "types.h"
  2. #include "string.h"
  3. #include "print.h"
  4. static const char* szFeatures[] = {
  5. "x87 FPU On Chip",
  6. "Virtual-8086 Mode Enhancement",
  7. "Debugging Extensions",
  8. "Page Size Extensions",
  9. "Time Stamp Counter",
  10. "RDMR and WRMSR Support",
  11. "Physical Address Extensions",
  12. "Machine Check Exception",
  13. "CMPXCHG8B Instruction",
  14. "APIC On Chip",
  15. "Unknown1",
  16. "SYSENTER and SYSEXIT",
  17. "Memory Type Range Registers",
  18. "PTE Global Bit",
  19. "Machine Check Architecture",
  20. "Conditional Move/Compare Instruction",
  21. "Page Attribute Table",
  22. "36-bit Page Size Extension",
  23. "Processor Serial Number",
  24. "CFLUSH Extension",
  25. "Unknown2",
  26. "Debug Store",
  27. "ThermalMonitor and Clock Ctrl",
  28. "MMX Technology",
  29. "FXSAVE/FXRSTOR",
  30. "SSE Extensions",
  31. "SSE2 Extensions",
  32. "Self Snoop",
  33. "Multithreading Technology",
  34. "Thermal Monitor",
  35. "Unknown4",
  36. "Pending Break Enable"
  37. };
  38. #if defined(_WIN32)
  39. // implementation originally from:
  40. // https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/hskdteyh(v=vs.90)?redirectedfrom=MSDN
  41. #include <intrin.h>
  42. void cpuid() {
  43. ULE_TYPES_H_FTAG;
  44. int nSteppingID = 0;
  45. int nModel = 0;
  46. int nFamily = 0;
  47. int nProcessorType = 0;
  48. int nExtendedmodel = 0;
  49. int nExtendedfamily = 0;
  50. int nBrandIndex = 0;
  51. int nCLFLUSHcachelinesize = 0;
  52. int nLogicalProcessors = 0;
  53. int nAPICPhysicalID = 0;
  54. int nFeatureInfo = 0;
  55. int nCacheLineSize = 0;
  56. int nL2Associativity = 0;
  57. int nCacheSizeK = 0;
  58. int nPhysicalAddress = 0;
  59. int nVirtualAddress = 0;
  60. int nRet = 0;
  61. int nCores = 0;
  62. int nCacheType = 0;
  63. int nCacheLevel = 0;
  64. int nMaxThread = 0;
  65. int nSysLineSize = 0;
  66. int nPhysicalLinePartitions = 0;
  67. int nWaysAssociativity = 0;
  68. int nNumberSets = 0;
  69. unsigned nIds, nExIds, i;
  70. bool bSSE3Instructions = false;
  71. bool bMONITOR_MWAIT = false;
  72. bool bCPLQualifiedDebugStore = false;
  73. bool bVirtualMachineExtensions = false;
  74. bool bEnhancedIntelSpeedStepTechnology = false;
  75. bool bThermalMonitor2 = false;
  76. bool bSupplementalSSE3 = false;
  77. bool bL1ContextID = false;
  78. bool bCMPXCHG16B = false;
  79. bool bxTPRUpdateControl = false;
  80. bool bPerfDebugCapabilityMSR = false;
  81. bool bSSE41Extensions = false;
  82. bool bSSE42Extensions = false;
  83. bool bPOPCNT = false;
  84. bool bMultithreading = false;
  85. bool bLAHF_SAHFAvailable = false;
  86. bool bCmpLegacy = false;
  87. bool bSVM = false;
  88. bool bExtApicSpace = false;
  89. bool bAltMovCr8 = false;
  90. bool bLZCNT = false;
  91. bool bSSE4A = false;
  92. bool bMisalignedSSE = false;
  93. bool bPREFETCH = false;
  94. bool bSKINITandDEV = false;
  95. bool bSYSCALL_SYSRETAvailable = false;
  96. bool bExecuteDisableBitAvailable = false;
  97. bool bMMXExtensions = false;
  98. bool bFFXSR = false;
  99. bool b1GBSupport = false;
  100. bool bRDTSCP = false;
  101. bool b64Available = false;
  102. bool b3DNowExt = false;
  103. bool b3DNow = false;
  104. bool bNestedPaging = false;
  105. bool bLBRVisualization = false;
  106. bool bFP128 = false;
  107. bool bMOVOptimization = false;
  108. bool bSelfInit = false;
  109. bool bFullyAssociative = false;
  110. int cpuinfo[4] = { -1 };
  111. __cpuid(cpuinfo, 0);
  112. unsigned count = cpuinfo[0];
  113. char cpustring[0x20];
  114. String::memset((void*) cpustring, '\0', sizeof(cpustring));
  115. *((int*) cpustring) = cpuinfo[1];
  116. *((int*) (cpustring + 4)) = cpuinfo[3];
  117. *((int*) (cpustring + 8)) = cpuinfo[2];
  118. println("CPU Identification String: %s", cpustring);
  119. //for (s32 i = 0; i < count; i++) {
  120. // __cpuid(cpuinfo, i);
  121. // println("info type: %d", i);
  122. // println("cpuinfo[0] = 0x%x", cpuinfo[0]);
  123. // println("cpuinfo[1] = 0x%x", cpuinfo[1]);
  124. // println("cpuinfo[2] = 0x%x", cpuinfo[2]);
  125. // println("cpuinfo[3] = 0x%x", cpuinfo[3]);
  126. //}
  127. }
  128. #else
  129. void cpuid() {
  130. ULE_TYPES_H_FTAG;
  131. }
  132. #endif