Click here to Skip to main content
6,292,811 members and growing! (11,584 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Beginner License: The Code Project Open License (CPOL)

Identify the Types of SIMD Instructions

By Shao Voon Wong

Identify the types of SIMD instructions which the Processor has
C++, Windows, Dev
Version:3 (See All)
Posted:29 Aug 2008
Updated:18 Mar 2009
Views:5,882
Bookmarked:11 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
11 votes for this article.
Popularity: 2.08 Rating: 2.00 out of 5
8 votes, 72.7%
1

2
1 vote, 9.1%
3
1 vote, 9.1%
4
1 vote, 9.1%
5
Demo

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:
// Intel SIMD
    bool HasMMX()
    bool HasSSE()
    bool HasSSE2()
    bool HasSSE3()
    bool HasSSSE3()
    bool HasSSE41()
    bool HasSSE42()
// AMD SIMD
    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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Shao Voon Wong


Member
I am currently working as a software developer in a company specialized in 3D modelling software. My wish is to write a article on GUI since I am specialized in GUI.

Like many Singaporeans, my hobbies include reading, karaoke, watching movies and anime, play games and jogging.

I wish I have more time to write articles for CodeProject since I have a few ideas(long overdue) to write about. And I always explain the working behind the code in my articles. I hope you like my articles on CodeProject!
Occupation: Software Developer
Location: Singapore Singapore

Other popular C / C++ Language articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
General3DNow, 3DNow+ and MMX+ detection bug PinmemberLeonardo Tazzini14:13 29 Aug '08  
GeneralRe: 3DNow, 3DNow+ and MMX+ detection bug PinmemberCBasicNet16:47 29 Aug '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 Mar 2009
Editor: Sean Ewington
Copyright 2008 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project