Stefano Tommesani

  • Increase font size
  • Default font size
  • Decrease font size
Home Programming Detecting MMX and SSE

Detecting MMX and SSE

The MMX instructions are supported by every x86 processor introduced in the market after the venerable Intel Pentium MMX, so it should be fairly safe to assume that the processor that your code is running on has MMX instructions. But checking for MMX instructions is really simple and it avoids embarassing crashes due to unsupported opcodes!
The following C function checks for MMX:

bool isMMXSupported()
  int fSupported;
   mov eax,1 // CPUID level 1
   cpuid  // EDX = feature flag
   and edx,0x800000 // test bit 23 of feature flag
   mov fSupported,edx // != 0 if MMX is supported
  if (fSupported != 0)
   return true;
   return false;

I call ISSE the integer subset of the SSE instruction set that enhances MMX. Click here to see what processors support ISSE.
The following C function works on both Intel and AMD chips:

bool isISSESupported()
   int processor;
   int features;
   int ext_features = 0;
   __asm {
    mov eax,1
    mov processor,eax     // Store processor family/model/step
    mov features,edx      // Store features bits

    mov eax,080000000h
    // Check which extended functions can be called
    cmp eax,080000001h      // Extended Feature Bits
    jb  no_features         // jump if not supported

    mov eax,080000001h      // Select function 0x80000001
    mov ext_features,edx  // Store extended features bits

   if (((features >> 25) & 1) != 0)
    return true;
    if (((ext_features >> 22) & 1) != 0)
     return true;
     return false;

Quote this article on your site

To create link towards this article on your website,
copy and paste the text below in your page.

Preview :

Detecting MMX and SSE
Tuesday, 25 April 2000

Powered by QuoteThis © 2008
View Stefano Tommesani's profile on LinkedIn

Latest Articles

Fixing Git pull errors in SourceTree 10 April 2017, 01.44 Software
Fixing Git pull errors in SourceTree
If you encounter the following error when pulling a repository in SourceTree: VirtualAlloc pointer is null, Win32 error 487 it is due to to the Cygwin system failing to allocate a 5 MB large chunk of memory for its heap at
Castle on the hill of crappy audio quality 19 March 2017, 01.53 Audio
Castle on the hill of crappy audio quality
As the yearly dynamic range day is close (March 31st), let's have a look at one of the biggest audio massacres of the year, Ed Sheeran's "Castle on the hill". First time I heard the song, I thought my headphones just got
Necessary evil: testing private methods 29 January 2017, 21.41 Testing
Necessary evil: testing private methods
Some might say that testing private methods should be avoided because it means not testing the contract, that is the interface implemented by the class, but the internal implementation of the class itself. Still, not all
I am right and you are wrong 28 December 2016, 14.23 Web
I am right and you are wrong
Have you ever convinced anyone that disagreed with you about a deeply held belief? Better yet, have you changed your mind lately on an important topic after discussing with someone else that did not share your point of
How Commercial Insight changes R&D 06 November 2016, 01.21 Web
How Commercial Insight changes R&D
The CEB's Commercial Insight is based on three pillars: Be credible/relevant – Demonstrate an understanding of the customer’s world, substantiating claims with real-world evidence. Be frame-breaking – Disrupt the