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

  • Today, users, applications, and data exist in more places than ever before, creating an unprecedented challenge for IT. How can IT achieve the flexibility and agility it needs to offer multiple types of applications in multiple locations? To better serve business demands for information everywhere, enterprises must develop new strategies for optimizing multiple kinds of networks. Read this white paper to learn how hybrid networks provide an unprecedented level of network dynamism, enterprise agility, and the …

  • Who can you trust? Learn from the IBM X-Force team in this new quarterly report how the Internet of Things and IP reputation tracking are transforming the security landscape.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date