CPUFeatures plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
Line 130: Line 130:
${If} ${CPUSupportsAll} "MMX1,AVX1"
${If} ${CPUSupportsAll} "MMX1,AVX1"
DetailPrint "This CPU spports MMX+AVX"
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}
${EndIf}
SectionEnd</highlight-nsis>
SectionEnd</highlight-nsis>

Revision as of 23:15, 25 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!

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-25.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