Guest User

Untitled

a guest
Feb 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. (*
  2. * MMX, SSE, SSE2, 3DNow, 3DNow2, CPU Manifacture を取得するクラス
  3. * Copyright (c) 2018 HOSOKAWA Jun.
  4. *
  5. * LICENSE:
  6. * 本ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、
  7. * 何らの保証もなく提供されます。
  8. * 本ソフトウェアの使用によって生じるいかなる損害についても、
  9. * 作者は一切の責任を負わないものとします。
  10. *
  11. * 以下の制限に従う限り、商用アプリケーションを含めて、本ソフトウェアを
  12. * 任意の目的に使用し、自由に改変して再頒布することをすべての人に許可します。
  13. *
  14. * 1. 本ソフトウェアの出自について虚偽の表示をしてはなりません。
  15. * あなたがオリジナルのソフトウェアを作成したと主張してはなりません。
  16. * あなたが本ソフトウェアを製品内で使用する場合、製品の文書に謝辞を入れて
  17. * いただければ幸いですが、必須ではありません。
  18. *
  19. * 2. ソースを変更した場合は、そのことを明示しなければなりません。
  20. * オリジナルのソフトウェアであるという虚偽の表示をしてはなりません。
  21. *
  22. * 3. ソースの頒布物から、この表示を削除したり、表示の内容を変更したりしては
  23. * なりません。
  24. *
  25. * This software is provided 'as-is', without any express or implied warranty.
  26. * In no event will the authors be held liable for any damages arising from
  27. * the use of this software.
  28. *
  29. * Permission is granted to anyone to use this software for any purpose,
  30. * including commercial applications, and to alter it and redistribute
  31. * it freely, subject to the following restrictions:
  32. *
  33. * 1. The origin of this software must not be misrepresented;
  34. * you must not claim that you wrote the original software.
  35. * If you use this software in a product, an acknowledgment in the product
  36. * documentation would be appreciated but is not required.
  37. *
  38. * 2. Altered source versions must be plainly marked as such,
  39. * and must not be misrepresented as being the original software.
  40. *
  41. * 3. This notice may not be removed or altered from any source distribution.
  42. *)
  43.  
  44. unit PK.SSEStatus;
  45.  
  46. interface
  47.  
  48. type
  49. TSSEStatus = class
  50. private class var
  51. FSSEEnabled: Boolean;
  52. FAMD3DNowEnabled: Boolean;
  53. FCPUManifacture: String;
  54. FSSE2Enabled: Boolean;
  55. FIsAMD: Boolean;
  56. FAMD3DNow2Enabled: Boolean;
  57. FMMXEnabled: Boolean;
  58. private
  59. class procedure CheckCPUAbility;
  60. public
  61. class property IsAMD: Boolean read FIsAMD;
  62. class property MMXEnabled: Boolean read FMMXEnabled;
  63. class property SSEEnabled: Boolean read FSSEEnabled;
  64. class property SSE2Enabled: Boolean read FSSE2Enabled;
  65. class property AMD3DNowEnabled: Boolean read FAMD3DNowEnabled;
  66. class property AMD3DNow2Enabled: Boolean read FAMD3DNow2Enabled;
  67. class property CPUManifacture: String read FCPUManifacture;
  68. end;
  69.  
  70. implementation
  71.  
  72. { TSSEStatus }
  73.  
  74. class procedure TSSEStatus.CheckCPUAbility;
  75. var
  76. Manifacture: array [0.. 11] of AnsiChar;
  77. begin
  78. try
  79. asm
  80. push esi
  81. push edi
  82. push ebx
  83.  
  84. // CPU Manifacture Check
  85. lea esi, Manifacture
  86. mov edi, esi
  87.  
  88. xor eax, eax
  89. mov ecx, 12
  90. rep stosb // Clear Manifacture
  91.  
  92. cpuid
  93.  
  94. mov [esi + 0], ebx
  95. mov [esi + 4], edx
  96. mov [esi + 8], ecx
  97.  
  98. // AMD Check
  99. cmp ebx, 'htuA'
  100. jnz @@Start
  101.  
  102. cmp edx, 'itne'
  103. jnz @@Start
  104.  
  105. cmp ecx, 'DMAc'
  106. jnz @@Start
  107.  
  108. // AMD
  109. mov FIsAMD, True
  110.  
  111. // SSE Check
  112. @@Start:
  113. mov eax, 1
  114. cpuid
  115.  
  116. @@MMX: // MMX
  117. test edx, 1 shl 23
  118. jz @@SSE
  119. mov FMMXEnabled, True
  120.  
  121. @@SSE: // SSE
  122. test edx, 1 shl 25
  123. jz @@SSE2
  124. mov FSSEEnabled, True
  125.  
  126. @@SSE2: // SSE2
  127. test edx, 1 shl 26
  128. jz @@3DNow
  129. mov FSSE2Enabled, True
  130.  
  131. @@3DNow: // AMD 3D Now!
  132. cmp FIsAMD, True
  133. jnz @@Exit
  134.  
  135. mov eax, $80000001
  136. cpuid
  137.  
  138. test edx, 1 shl 31
  139. jz @@3DNow2
  140. mov FAMD3DNowEnabled, True
  141.  
  142. @@3DNow2: // AMD 3D Now! 2
  143. test edx, 1 shl 30
  144. jz @@Exit
  145. mov FAMD3DNow2Enabled, True
  146.  
  147. @@Exit:
  148. pop ebx
  149. pop edi
  150. pop esi
  151. end;
  152. except
  153. // not supported CPU ID & SSE
  154. end;
  155.  
  156. TSSEStatus.FCPUManifacture := AnsiString(Manifacture);
  157. end;
  158.  
  159. initialization
  160. begin
  161. TSSEStatus.CheckCPUAbility;
  162. end;
  163.  
  164. finalization
  165. begin
  166. end;
  167.  
  168. end.
Add Comment
Please, Sign In to add comment