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

  • In the competitive marketplace that surrounds us today, customers shouldn't have to settle for legacy desktop or application delivery simply because they've relied on a certain vendor in the past. This white paper reviews how three customers decided to partner with VMware, and how they benefited from the latest VDI and app trends to improve the end-user experience, increase productivity, reliability and stability to deliver better SLAs - with lower cost and less time needed to manage end users.

  • This paper introduces IBM Java on the IBM PowerLinux 7R2 server and describes IBM's implementation of the Java platform, which includes IBM's Java Virtual Machine and development toolkit.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds