Guest User

Untitled

a guest
Oct 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. /*
  2. ========================================================================
  3. File: sz_cpuhelpers.h
  4. Date: Wed Oct 18 19:09:13 2017
  5. Creator: Zakary Strange
  6.  
  7. Notice: (C) Copyright 2017 by StrangeDev, LLC. All Rights Reserved
  8. ========================================================================
  9. */
  10.  
  11. typedef enum
  12. {
  13. INTEL,
  14. AMD,
  15. CENTUAR,
  16. CYRIX,
  17. TRANSMETA,
  18. NATIONAL_SEMICONDUCTOR,
  19. NEXGEN,
  20. RISE,
  21. SIS,
  22. UMC,
  23. VIA,
  24. VORTEX
  25. } cpu_vendor;
  26.  
  27. // We probably can do this faster
  28. static cpu_vendor GetCPUVendor(void)
  29. {
  30. cpu_vendor Result;
  31.  
  32. int Info[4] = {0};
  33. char Vendor[13];
  34. __cpuid(Info, 0);
  35.  
  36. memcpy(Vendor, &Info[1], 4);
  37. memcpy(Vendor+4, &Info[2], 4);
  38. memcpy(Vendor+8, &Info[3], 4);
  39. Vendor[12] = "\0";
  40.  
  41. // Lets check if intel and amd first, then we will check all of other
  42. // lesser known vendors
  43. if(strcmp(Vendor, "GenuineIntel") == 0)
  44. {
  45. Result = INTEL;
  46. }
  47. else if(Vendor, "AuthenticAMD") == 0)
  48. {
  49. Result = AMD;
  50. }
  51. else if(Vendor, "CentaurHauls") == 0)
  52. {
  53. Result = CENTUAR;
  54. }
  55. else if(Vendor, "CyrixInstead") == 0)
  56. {
  57. Result = CyrixInstead;
  58. }
  59. else if(Vendor, "TransmetaCPU") == 0)
  60. {
  61. Result = TRANSMETA;
  62. }
  63. else if(Vendor, "GenuineTMx86") == 0)
  64. {
  65. Result = TRANSMETA;
  66. }
  67. else if(Vendor, "Geode by NSC") == 0)
  68. {
  69. Result = NATIONAL_SEMICONDUCTOR;
  70. }
  71. else if(Vendor, "NexGenDriven") == 0)
  72. {
  73. Result = NEXGEN;
  74. }
  75. else if(Vendor, "RiseRiseRise") == 0)
  76. {
  77. Result = RISE;
  78. }
  79. else if(Vendor, "SiS SiS SiS ") == 0)
  80. {
  81. Result = SIS;
  82. }
  83. else if(Vendor, "UMC UMC UMC ") == 0)
  84. {
  85. Result = UMC;
  86. }
  87. else if(Vendor, "VIA VIA VIA ") == 0)
  88. {
  89. Result = VIA;
  90. }
  91. else if(Vendor, "Vortex86 SoC") == 0)
  92. {
  93. Result = VORTEX;
  94. }
  95.  
  96. else if (CPUBrandString);
  97. }
  98.  
  99. static bool IsSSESupported(void)
  100. {
  101. int Info[4];
  102. __cpuid(Info, 1);
  103. return((Info[3] >> 25) & 1) != 0;
  104. }
  105.  
  106. static bool IsSSE2Supported(void)
  107. {
  108. int Info[4];
  109. __cpuid(Info, 1);
  110. return((Info[3] >> 26) & 1) != 0;
  111. }
  112.  
  113. static bool IsSSE3Supported(void)
  114. {
  115. int Info[4];
  116. __cpuid(Info, 1);
  117. return((Info[2] >> 0) & 1) != 0;
  118. }
  119.  
  120.  
  121. // SSE 4A
  122. static bool IsSSE4Supported(void)
  123. {
  124. int Info[4];
  125. __cpuid(Info, 1);
  126. return((Info[2] >> 6) & 1) != 0;
  127. }
  128.  
  129.  
  130. // SSE 4_1
  131. static bool IsSSE41Supported(void)
  132. {
  133. int Info[4];
  134. __cpuid(Info, 1);
  135. return((Info[2] >> 19) & 1) != 0;
  136. }
  137.  
  138.  
  139. // SSE 4_2
  140. static bool IsSSE42Supported(void)
  141. {
  142. int Info[4];
  143. __cpuid(Info, 1);
  144. return((Info[2] >> 20) & 1) != 0;
  145. }
  146.  
  147. // AVX
  148. static bool IsAVXSupported(void)
  149. {
  150. int Info[4];
  151. __cpuid(Info, 1);
  152. return((Info[2] >> 28) & 1) != 0;
  153. }
  154.  
  155.  
  156. // AVX 512
  157. static bool IsAVX512Supported(void)
  158. {
  159. // TODO(zak): Implement
  160. // i think this is a group of bits we will have to compare
  161. }
  162.  
  163. static bool IsHyperThreadingSupported(void)
  164. {
  165. int Info[4];
  166. __cpuid(Info, 1);
  167. return((Info[3] >> 28) & 1) != 0;
  168. }
Add Comment
Please, Sign In to add comment