Last active
February 6, 2018 05:09
-
-
Save freeonterminate/c842d26e9e4b2e65e8337cf109d7ccd6 to your computer and use it in GitHub Desktop.
MMX, SSE, SSE2, 3DNow, 3DNow2, CPU Manifacture を取得するクラス
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* MMX, SSE, SSE2, 3DNow, 3DNow2, CPU Manifacture を取得するクラス | |
* Copyright (c) 2018 HOSOKAWA Jun. | |
* | |
* LICENSE: | |
* 本ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、 | |
* 何らの保証もなく提供されます。 | |
* 本ソフトウェアの使用によって生じるいかなる損害についても、 | |
* 作者は一切の責任を負わないものとします。 | |
* | |
* 以下の制限に従う限り、商用アプリケーションを含めて、本ソフトウェアを | |
* 任意の目的に使用し、自由に改変して再頒布することをすべての人に許可します。 | |
* | |
* 1. 本ソフトウェアの出自について虚偽の表示をしてはなりません。 | |
* あなたがオリジナルのソフトウェアを作成したと主張してはなりません。 | |
* あなたが本ソフトウェアを製品内で使用する場合、製品の文書に謝辞を入れて | |
* いただければ幸いですが、必須ではありません。 | |
* | |
* 2. ソースを変更した場合は、そのことを明示しなければなりません。 | |
* オリジナルのソフトウェアであるという虚偽の表示をしてはなりません。 | |
* | |
* 3. ソースの頒布物から、この表示を削除したり、表示の内容を変更したりしては | |
* なりません。 | |
* | |
* This software is provided 'as-is', without any express or implied warranty. | |
* In no event will the authors be held liable for any damages arising from | |
* the use of this software. | |
* | |
* Permission is granted to anyone to use this software for any purpose, | |
* including commercial applications, and to alter it and redistribute | |
* it freely, subject to the following restrictions: | |
* | |
* 1. The origin of this software must not be misrepresented; | |
* you must not claim that you wrote the original software. | |
* If you use this software in a product, an acknowledgment in the product | |
* documentation would be appreciated but is not required. | |
* | |
* 2. Altered source versions must be plainly marked as such, | |
* and must not be misrepresented as being the original software. | |
* | |
* 3. This notice may not be removed or altered from any source distribution. | |
*) | |
unit PK.SSEStatus; | |
interface | |
type | |
TSSEStatus = class | |
private class var | |
FSSEEnabled: Boolean; | |
FAMD3DNowEnabled: Boolean; | |
FCPUManifacture: String; | |
FSSE2Enabled: Boolean; | |
FIsAMD: Boolean; | |
FAMD3DNow2Enabled: Boolean; | |
FMMXEnabled: Boolean; | |
private | |
class procedure CheckCPUAbility; | |
public | |
class property IsAMD: Boolean read FIsAMD; | |
class property MMXEnabled: Boolean read FMMXEnabled; | |
class property SSEEnabled: Boolean read FSSEEnabled; | |
class property SSE2Enabled: Boolean read FSSE2Enabled; | |
class property AMD3DNowEnabled: Boolean read FAMD3DNowEnabled; | |
class property AMD3DNow2Enabled: Boolean read FAMD3DNow2Enabled; | |
class property CPUManifacture: String read FCPUManifacture; | |
end; | |
implementation | |
{ TSSEStatus } | |
class procedure TSSEStatus.CheckCPUAbility; | |
var | |
Manifacture: array [0.. 11] of AnsiChar; | |
begin | |
try | |
asm | |
push esi | |
push edi | |
push ebx | |
// CPU Manifacture Check | |
lea esi, Manifacture | |
mov edi, esi | |
xor eax, eax | |
mov ecx, 12 | |
rep stosb // Clear Manifacture | |
cpuid | |
mov [esi + 0], ebx | |
mov [esi + 4], edx | |
mov [esi + 8], ecx | |
// AMD Check | |
cmp ebx, 'htuA' | |
jnz @@Start | |
cmp edx, 'itne' | |
jnz @@Start | |
cmp ecx, 'DMAc' | |
jnz @@Start | |
// AMD | |
mov FIsAMD, True | |
// SSE Check | |
@@Start: | |
mov eax, 1 | |
cpuid | |
@@MMX: // MMX | |
test edx, 1 shl 23 | |
jz @@SSE | |
mov FMMXEnabled, True | |
@@SSE: // SSE | |
test edx, 1 shl 25 | |
jz @@SSE2 | |
mov FSSEEnabled, True | |
@@SSE2: // SSE2 | |
test edx, 1 shl 26 | |
jz @@3DNow | |
mov FSSE2Enabled, True | |
@@3DNow: // AMD 3D Now! | |
cmp FIsAMD, True | |
jnz @@Exit | |
mov eax, $80000001 | |
cpuid | |
test edx, 1 shl 31 | |
jz @@3DNow2 | |
mov FAMD3DNowEnabled, True | |
@@3DNow2: // AMD 3D Now! 2 | |
test edx, 1 shl 30 | |
jz @@Exit | |
mov FAMD3DNow2Enabled, True | |
@@Exit: | |
pop ebx | |
pop edi | |
pop esi | |
end; | |
except | |
// not supported CPU ID & SSE | |
end; | |
TSSEStatus.FCPUManifacture := AnsiString(Manifacture); | |
end; | |
initialization | |
begin | |
TSSEStatus.CheckCPUAbility; | |
end; | |
finalization | |
begin | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment