Introduction
I have been learning and writing SSE2 intrinsic instructions but I did not find an article on CodeProject that has sample code for me to identify the presence of SIMD instructions on processor, hence I wrote a simple class to do it. I hope that people who need this information can save some time using this class, without having to roll out their own class.
The HasSIMD Class
Here is the class declaration. This class uses the __cpuid intrinsic in intrin.h to do its work. All the SIMD types available on the running machine is determined in its constructor. I guess there is no need for sample code. It is simple to use.
class HasSIMD
{
public:
bool HasMMX()
bool HasSSE()
bool HasSSE2()
bool HasSSE3()
bool HasSSSE3()
bool HasSSE41()
bool HasSSE42()
bool HasMMXplus()
bool Has3Dnow()
bool Has3DnowExt()
};
Alternative Solution
Alternatively, if you do not want to use my class, you can use the IsProcessorFeaturePresent function in Windows.h. However, there are some limitations with the IsProcessorFeaturePresent function: Some of the newer SIMD detection is not supported on older Windows OS and not all SIMD detection is supported. For example, SSE2 detection is not supported on Windows 2000 and SSE3 detection is not supported on Windows 2000, Windows XP and Windows Server 2003. SSSE3 and SSE4.x detection is not supported at all! IsProcessorFeaturePresent can still be used if say your application uses MMX or/and SSE or/and SSE2 and your application's minimum operating system requirement is defined to be Windows XP or above. One advantage of IsProcessorFeaturePresent over HasSIMD is that you can query for other (non-SIMD related) processor features such as cmpxchg16b(128bit atomic compare and exchange). For more information, please see IsProcessorFeaturePresent.
Important Notes on Symmetric Multiprocessor(SMP) System
Beware of SMP systems, the processors used should be identical, hence the word, "symmetric." Or else, the class may detect that one of the processors supports this SIMD. When it runs this SIMD instruction on another non-identical processor which doesn't supports this SIMD, your program may crash.
References
History
- 13/03/2008: Cleaned up the code and added a 'Alternative Solution' section in the article.
- 01/09/2008: Version 1.1.0 includes bug fix for 3DNow, 3DNow+ and MMX+ detection by Leonardo Tazzini
- 27/08/2008: First release