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

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

Most Popular Programming Stories

More for Developers

RSS Feeds

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