SIMD Detector

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

Codeguru Editor's note: Searching on Codeguru, you'll also find Three Ways to Retrieve Processor Information by Marius Bancila.

The SIMD Class

Here is the class declaration. This class uses the __cpuid intrinsic in intrin.h to do its work. All of the SIMD types available on the running machine are determined in its constructor. Because it is simple to sue, there is no need for sample code.

class SIMD
{
  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();
  	  bool HasSSE4a();
      bool HasSSE5();
};

Alternative Solution

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, for example, 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 SIMD class 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." Otherwise, 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



About the Author

Wong Shao Voon

I guess I'll write here what I does in my free time, than to write an accolade of skills which I currently possess. I believe the things I does in my free time, say more about me.

When I am not working, I like to watch Japanese anime. I am also writing some movie script, hoping to see my own movie on the big screen one day.

I like to jog because it makes me feel good, having done something meaningful in the morning before the day starts.

I also writes articles for CodeGuru; I have a few ideas to write about but never get around writing because of hectic schedule.

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds