title: How can I use AES-NI intrinsics on a Mac?
body: <p>I'm trying to compile a C application on a Mac. I use SSE4 and  AES-NI intrinsics. </p>
  
  <p>In Linux, I just call gcc with the -msse4 and -maes flags and include the <em>wmmintrin.h</em> header and I can call SSE intrinsics like <code>_mm_add_epi64(a,b)</code> or AES-NI intrinsics like <code>_mm_aesenc_si128(a, b)</code> and everything works fine.</p>
  
  <p>On the Mac, it's harder, because Apple replaces GCC with llvm-gcc which does not support AES-NI yet. So SSE4 intrinsics work fine, but not the AES ones.
  Even inline assembly calls to the AES instructions are not recognized.</p>
  
  <p>Intel has <a href="http://software.intel.com/en-us/articles/intel-advanced-encryption-standard-instructions-aes-ni/">lots of AES example code</a> on their website, but it's for Linux and Windows only. </p>
  
  <p>I did notice the RDRAND instruction is also unsupported by llvm-gcc but Intel provides a workaround for that by using a C macro which expands into raw machine byte code. (<a href="http://software.intel.com/en-us/articles/user-manual-for-the-rdrand-library-linux-version">See the rdrand.h example file in this Intel library</a>) </p>
  
  <p>Unfortunately there is no similar provided workaround for the AES-NI instructions, probably because the instructions have arguments and can't be evaluated as static machine code bytes.</p>
  
  <p>Programs do exist that use AES-NI on the Mac, including Apple's own File Vault, so there must be some method that works!</p>
  
  <p>To make my question concrete, how would I get the following simple call to compile using the latest Mac gcc-llvm 4.2 (latest public release in Mountain Lion xcode 4.4.1):</p>
  
  <pre><code> __m128i A, B, C;
    /* A, B, C initialized here... */
    A = _mm_aesenc_si128(B, C);   
  </code></pre>
  
  <p>Thanks for any help!</p>