CPUFeatures plug-in: Difference between revisions
LoRd MuldeR (talk | contribs) No edit summary |
LoRd MuldeR (talk | contribs) No edit summary |
||
(17 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
This very simple plug-in can detect the supported CPU features (MMX, 3DNow!, SSE''x'', AVX''x'', FMA''x'', etc) at runtime. | This very simple plug-in can detect the supported CPU features (MMX, 3DNow!, SSE''x'', AVX''x'', FMA''x'', etc) at runtime. | ||
Furthermore the number of available CPU's (aka "CPU cores") as well as the CPU | Furthermore the number of available CPU's (aka "CPU cores") as well as the CPU vendor (Intel, AMD, other) can be reported. | ||
'''ANSI and Unicode builds available. Support operating systems: Windows 2000 and later.''' | |||
''' | ''Acknowledgement:'' This plug-in is based on CPU detection code from the [http://www.videolan.org/developers/x264.html x264] project. Please see [http://git.videolan.org/gitweb.cgi?p=x264.git;a=blob;f=common/cpu.c cpu.c] for details! | ||
== Supported functions == | |||
* Query CPU feature flags<br><tt>${CPUFeatures.GetFlags} out_var</tt><br>Result: Integer value as Hex string | |||
* Get number of processors (CPU cores)<br><tt>${CPUFeatures.GetCount} out_var</tt><br>Result: Positive Integer number or "error" | |||
* Query all supported CPU features<br><tt>${CPUFeatures.GetFeatures} out_var</tt><br>Result: Comma-separated list of all supported features | |||
* Query CPU vendor:<br><tt>${CPUFeatures.GetVendor} out_var</tt><br>Result: "Intel", "AMD" or "Other" | |||
* Check for a single CPU feature<br><tt>${CPUFeatures.CheckFeature} feature out_var</tt><br>Result: "yes" (supported), "no" (unsupported) or "error" (invalid parameter) | |||
* Check for multiple CPU features (comma-separated list)<br><tt>${CPUFeatures.CheckFeature} feature_list out_var</tt><br>Result: "yes" (all are supported), "no" (at least one is unsupported) or "error" (invalid parameter) | |||
=== LogicLib support === | |||
* Evaluates to <i>TRUE</i> iff specified CPU features is supported<br><tt><font color="grey">${If}</font> ${CPUSupports} <feature> <font color="grey">... ${EndIf}</font></tt> | |||
* Evaluates to <i>TRUE</i> iff all specified CPU features are supported<br><tt><font color="grey">${If}</font> ${CPUSupportsAll} <feature_list> <font color="grey">... ${EndIf}</font></tt> | |||
* Evaluates to <i>TRUE</i> iff running on an Intel processor<br><tt><font color="grey">${If}</font> ${CPUIsIntel} <font color="grey">... ${EndIf}</font></tt> | |||
* Evaluates to <i>TRUE</i> iff running on an AMD processor<br><tt><font color="grey">${If}</font> ${CPUIsAMD} <font color="grey">... ${EndIf}</font></tt> | |||
== Supported CPU Flags == | |||
* <tt>MMX1</tt> - MMX supported | |||
* <tt>MMX2</tt> - MMX2 aka MMXEX aka Integer-SSE supported | |||
* <tt>SSE1</tt> - SSE supported | |||
* <tt>SSE2</tt> - SSE2 supported | |||
* <tt>SSE2_SLOW</tt> - Most SSE2 functions are SLOW (e.g. Athlon64) | |||
* <tt>SSE2_FAST</tt> - Some SSE2 functions are only faster on specific CPU's (Core2 and Phenom) | |||
* <tt>SSE3</tt> - SSE3 supported | |||
* <tt>SSSE3</tt> - SSSE3 supported | |||
* <tt>FAST_SHUFFLE</tt> - Penryn, Nehalem, and Phenom have fast shuffle units | |||
* <tt>STACK_MOD4</tt> - Stack is only mod4, not mod16 | |||
* <tt>SSE4</tt> - SSE4.1 supported | |||
* <tt>SSE4.2</tt> - SSE4.2 supported | |||
* <tt>SSE_MISALIGN</tt> - Phenom support for misaligned SSE instruction arguments | |||
* <tt>LZCNT</tt> - Phenom support for "leading zero count" instruction | |||
* <tt>SLOW_CTZ</tt> - BSR/BSF x86 instructions are really slow | |||
* <tt>SLOW_ATOM</tt> - Intel Atom ("the Atom just sucks") | |||
* <tt>AVX1</tt> - AVX supported, also by the OS (AVX requires OS support even if YMM registers aren't used) | |||
* <tt>XOP</tt> - AMD XOP supported | |||
* <tt>FMA4</tt> - AMD FMA4 supported | |||
* <tt>AVX2</tt> - AVX2 supported | |||
* <tt>FMA3</tt> - Intel FMA3 supported | |||
* <tt>3DNOW</tt> - AMD 3DNow! supported | |||
* <tt>3DNOW_EX</tt> - AMD 3DNow!+ (aka Enhanced 3DNow!) supported | |||
== Example == | == Example == | ||
Line 13: | Line 55: | ||
How to use the CPUFeatures plug-in: | How to use the CPUFeatures plug-in: | ||
<highlight-nsis>!include "CPUFeatures.nsh" | <highlight-nsis>!include "LogicLib.nsh" | ||
!include "CPUFeatures.nsh" | |||
RequestExecutionLevel user | RequestExecutionLevel user | ||
ShowInstDetails show | ShowInstDetails show | ||
; | ; Query basic CPU information | ||
Section | Section | ||
${CPUFeatures.GetFlags} $0 | ${CPUFeatures.GetFlags} $0 | ||
Line 25: | Line 68: | ||
${CPUFeatures.GetCount} $0 | ${CPUFeatures.GetCount} $0 | ||
DetailPrint "CPU Count: $0" | DetailPrint "CPU Count: $0" | ||
${CPUFeatures.GetFeatures} $0 | ${CPUFeatures.GetFeatures} $0 | ||
DetailPrint "CPU Features: $0" | DetailPrint "CPU Features: $0" | ||
Line 101: | Line 141: | ||
${CPUFeatures.CheckAllFeatures} "MMX1,SSE1,SSE2,SSE3,SSSE3,SSE7" $0 | ${CPUFeatures.CheckAllFeatures} "MMX1,SSE1,SSE2,SSE3,SSSE3,SSE7" $0 | ||
DetailPrint "Has MMX+SSE+SSE2+SSE3+SSSE3+SSE7: $0" | DetailPrint "Has MMX+SSE+SSE2+SSE3+SSSE3+SSE7: $0" | ||
SectionEnd | |||
; Use LogicLib to check CPU features | |||
Section | |||
${If} ${CPUSupports} "MMX1" | |||
DetailPrint "This CPU spports MMX" | |||
${EndIf} | |||
${If} ${CPUSupports} "SSE1" | |||
DetailPrint "This CPU spports SSE" | |||
${EndIf} | |||
${If} ${CPUSupports} "SSSE3" | |||
DetailPrint "This CPU spports SSSE3" | |||
${EndIf} | |||
${If} ${CPUSupports} "3DNOW" | |||
DetailPrint "This CPU spports SSSE3" | |||
${EndIf} | |||
${If} ${CPUSupports} "AVX1" | |||
DetailPrint "This CPU spports AVX" | |||
${EndIf} | |||
${If} ${CPUSupportsAll} "MMX1,SSE1" | |||
DetailPrint "This CPU spports MMX+SSE" | |||
${EndIf} | |||
${If} ${CPUSupportsAll} "MMX1,3DNOW" | |||
DetailPrint "This CPU spports MMX+3DNOW" | |||
${EndIf} | |||
${If} ${CPUSupportsAll} "MMX1,SSSE3" | |||
DetailPrint "This CPU spports MMX+SSSE3" | |||
${EndIf} | |||
${If} ${CPUSupportsAll} "MMX1,AVX1" | |||
DetailPrint "This CPU spports MMX+AVX" | |||
${EndIf} | |||
${If} ${CPUIsIntel} | |||
DetailPrint "This CPU is an Intel" | |||
${EndIf} | |||
${If} ${CPUIsAMD} | |||
DetailPrint "This CPU is an AMD" | |||
${EndIf} | |||
SectionEnd</highlight-nsis> | SectionEnd</highlight-nsis> | ||
Line 127: | Line 206: | ||
== Download == | == Download == | ||
'''Download current version:'''<br><attach>CPUFeatures.2013-02- | '''Download current version:'''<br><attach>CPUFeatures.2013-02-26.zip</attach> | ||
=== Source Code === | === Source Code === |
Latest revision as of 01:28, 26 February 2013
Author: LoRd MuldeR (talk, contrib) |
This very simple plug-in can detect the supported CPU features (MMX, 3DNow!, SSEx, AVXx, FMAx, etc) at runtime.
Furthermore the number of available CPU's (aka "CPU cores") as well as the CPU vendor (Intel, AMD, other) can be reported.
ANSI and Unicode builds available. Support operating systems: Windows 2000 and later.
Acknowledgement: This plug-in is based on CPU detection code from the x264 project. Please see cpu.c for details!
Supported functions
- Query CPU feature flags
${CPUFeatures.GetFlags} out_var
Result: Integer value as Hex string - Get number of processors (CPU cores)
${CPUFeatures.GetCount} out_var
Result: Positive Integer number or "error" - Query all supported CPU features
${CPUFeatures.GetFeatures} out_var
Result: Comma-separated list of all supported features - Query CPU vendor:
${CPUFeatures.GetVendor} out_var
Result: "Intel", "AMD" or "Other" - Check for a single CPU feature
${CPUFeatures.CheckFeature} feature out_var
Result: "yes" (supported), "no" (unsupported) or "error" (invalid parameter) - Check for multiple CPU features (comma-separated list)
${CPUFeatures.CheckFeature} feature_list out_var
Result: "yes" (all are supported), "no" (at least one is unsupported) or "error" (invalid parameter)
LogicLib support
- Evaluates to TRUE iff specified CPU features is supported
${If} ${CPUSupports} <feature> ... ${EndIf} - Evaluates to TRUE iff all specified CPU features are supported
${If} ${CPUSupportsAll} <feature_list> ... ${EndIf} - Evaluates to TRUE iff running on an Intel processor
${If} ${CPUIsIntel} ... ${EndIf} - Evaluates to TRUE iff running on an AMD processor
${If} ${CPUIsAMD} ... ${EndIf}
Supported CPU Flags
- MMX1 - MMX supported
- MMX2 - MMX2 aka MMXEX aka Integer-SSE supported
- SSE1 - SSE supported
- SSE2 - SSE2 supported
- SSE2_SLOW - Most SSE2 functions are SLOW (e.g. Athlon64)
- SSE2_FAST - Some SSE2 functions are only faster on specific CPU's (Core2 and Phenom)
- SSE3 - SSE3 supported
- SSSE3 - SSSE3 supported
- FAST_SHUFFLE - Penryn, Nehalem, and Phenom have fast shuffle units
- STACK_MOD4 - Stack is only mod4, not mod16
- SSE4 - SSE4.1 supported
- SSE4.2 - SSE4.2 supported
- SSE_MISALIGN - Phenom support for misaligned SSE instruction arguments
- LZCNT - Phenom support for "leading zero count" instruction
- SLOW_CTZ - BSR/BSF x86 instructions are really slow
- SLOW_ATOM - Intel Atom ("the Atom just sucks")
- AVX1 - AVX supported, also by the OS (AVX requires OS support even if YMM registers aren't used)
- XOP - AMD XOP supported
- FMA4 - AMD FMA4 supported
- AVX2 - AVX2 supported
- FMA3 - Intel FMA3 supported
- 3DNOW - AMD 3DNow! supported
- 3DNOW_EX - AMD 3DNow!+ (aka Enhanced 3DNow!) supported
Example
How to use the CPUFeatures plug-in:
!include "LogicLib.nsh" !include "CPUFeatures.nsh" RequestExecutionLevel user ShowInstDetails show ; Query basic CPU information Section ${CPUFeatures.GetFlags} $0 DetailPrint "CPU Flags: $0" ${CPUFeatures.GetCount} $0 DetailPrint "CPU Count: $0" ${CPUFeatures.GetFeatures} $0 DetailPrint "CPU Features: $0" ${CPUFeatures.GetVendor} $0 DetailPrint "CPU Vendor: $0" SectionEnd ; Check individual feature flags ; Find a list of supported feature flags in CPUFeatures.nsh! Section ${CPUFeatures.CheckFeature} "MMX1" $0 DetailPrint "Has MMX: $0" ${CPUFeatures.CheckFeature} "MMX2" $0 DetailPrint "Has MMX2: $0" ${CPUFeatures.CheckFeature} "SSE1" $0 DetailPrint "Has SSE: $0" ${CPUFeatures.CheckFeature} "SSE2" $0 DetailPrint "Has SSE2: $0" ${CPUFeatures.CheckFeature} "SSE3" $0 DetailPrint "Has SSE3: $0" ${CPUFeatures.CheckFeature} "SSSE3" $0 DetailPrint "Has SSSE3: $0" ${CPUFeatures.CheckFeature} "SSE4.2" $0 DetailPrint "Has SSE4.2: $0" ${CPUFeatures.CheckFeature} "AVX1" $0 DetailPrint "Has AVX: $0" ${CPUFeatures.CheckFeature} "AVX2" $0 DetailPrint "Has AVX2: $0" ${CPUFeatures.CheckFeature} "3DNOW" $0 DetailPrint "Has 3DNOW: $0" ${CPUFeatures.CheckFeature} "3DNOW_EX" $0 DetailPrint "Has 3DNOW_EX: $0" ${CPUFeatures.CheckFeature} "FMA3" $0 DetailPrint "Has FMA3: $0" ${CPUFeatures.CheckFeature} "FMA4" $0 DetailPrint "Has FMA4: $0" ; Next call is supposed to fail! ${CPUFeatures.CheckFeature} "SSE7" $0 DetailPrint "Has SSE7: $0" SectionEnd ; Check multiple features at once ; Returns only "yes", if *all* features are supported Section ${CPUFeatures.CheckAllFeatures} "MMX1,SSE1" $0 DetailPrint "Has MMX+SSE: $0" ${CPUFeatures.CheckAllFeatures} "MMX1,3DNOW" $0 DetailPrint "Has MMX1+3DNOW: $0" ${CPUFeatures.CheckAllFeatures} "MMX1,SSE1,SSE2,SSE3,SSSE3" $0 DetailPrint "Has MMX+SSE+SSE2+SSE3+SSSE3: $0" ${CPUFeatures.CheckAllFeatures} "MMX1,SSE1,SSE2,SSE3,SSSE3,SSE4" $0 DetailPrint "Has MMX+SSE+SSE2+SSE3+SSSE3+SSE4: $0" ; Next call is supposed to fail! ${CPUFeatures.CheckAllFeatures} "MMX1,SSE1,SSE2,SSE3,SSSE3,SSE7" $0 DetailPrint "Has MMX+SSE+SSE2+SSE3+SSSE3+SSE7: $0" SectionEnd ; Use LogicLib to check CPU features Section ${If} ${CPUSupports} "MMX1" DetailPrint "This CPU spports MMX" ${EndIf} ${If} ${CPUSupports} "SSE1" DetailPrint "This CPU spports SSE" ${EndIf} ${If} ${CPUSupports} "SSSE3" DetailPrint "This CPU spports SSSE3" ${EndIf} ${If} ${CPUSupports} "3DNOW" DetailPrint "This CPU spports SSSE3" ${EndIf} ${If} ${CPUSupports} "AVX1" DetailPrint "This CPU spports AVX" ${EndIf} ${If} ${CPUSupportsAll} "MMX1,SSE1" DetailPrint "This CPU spports MMX+SSE" ${EndIf} ${If} ${CPUSupportsAll} "MMX1,3DNOW" DetailPrint "This CPU spports MMX+3DNOW" ${EndIf} ${If} ${CPUSupportsAll} "MMX1,SSSE3" DetailPrint "This CPU spports MMX+SSSE3" ${EndIf} ${If} ${CPUSupportsAll} "MMX1,AVX1" DetailPrint "This CPU spports MMX+AVX" ${EndIf} ${If} ${CPUIsIntel} DetailPrint "This CPU is an Intel" ${EndIf} ${If} ${CPUIsAMD} DetailPrint "This CPU is an AMD" ${EndIf} SectionEnd
License
CPUFeatures plug-in for NSIS Copyright (C) 2013 LoRd_MuldeR <mulder2@gmx.de> Copyright (C) 2003-2013 x264 project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Please see the GNU General Public License for details!
Download
Download current version:
CPUFeatures.2013-02-26.zip (90 KB)
Source Code
Public Git Repository:
git://github.com/lordmulder/CPUFeaturesLib.git (Browse)
Public SVN Repository:
http://code.google.com/p/mulder/source/browse/trunk/Utils/CPUFeatures/
Support
Discussion:
http://forums.winamp.com/showthread.php?t=355951
E-Mail:
MuldeR2 (at) gmx (dot) de