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

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Live Event Date: November 18, 2014 @ 11:00 a.m. EST As you embrace the hybrid world of on-premise and cloud applications, often accessed via mobile devices, you now have to be concerned that cybercriminals have yet another vehicle to attack your business. In fact, the average cost of cybercrime has increased over 10% in the last year, and this applies to businesses of all sizes. Attend this webinar to hear David Monahan, Security Research Director at EMA, and Dana Epp, recognized security luminary from …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds