How can I use the built-in AES-NI features on a Mac?

I am trying to compile C application on Mac. I use the built-in functions of SSE4 and AES-NI.

On Linux, I just call gcc with the -msse4 and -maes flags and include the wmmintrin.h header, and I can call SSE intrinsics like _mm_add_epi64(a,b) or AES-NI intrinsics like _mm_aesenc_si128(a, b) , and everything works fine.

On a Mac, this is more complicated because Apple is replacing GCC with llvm-gcc, which does not yet support AES-NI. Thus, SSE4 functions work fine, but not AES. Even built-in assembly calls to AES commands are not recognized.

Intel has many examples of AES code on its website, but only for Linux and Windows.

I noticed that the RDRAND instruction is also not supported by llvm-gcc, but Intel provides a workaround for this using the C macro, which extends into the original machine byte code. ( See an example rdrand.h file in this Intel library )

Unfortunately, a similar workaround for AES-NI instructions does not exist, probably because the instructions have arguments and cannot be evaluated as bytes of static machine code.

There are programs that use AES-NI on a Mac, including Apple's own proprietary file storage, so there must be some method that works!

To make my question concrete, how do I get the following simple call to compile using the latest version of gcc-llvm 4.2 (latest public release in Mountain Lion xcode 4.4.1):

  __m128i A, B, C; /* A, B, C initialized here... */ A = _mm_aesenc_si128(B, C); 

Thanks for any help!

+8
gcc sse xcode aes llvm-gcc
source share
1 answer

Apple Developer Support has reported that this is not possible with Xcode. (And in fact, their answer was a little ridiculous and implied that AES-NI was not something that the developer should ever use directly, so I should not worry. Sigh, thanks, Apple.)

However, I found two working solutions, just avoiding Apple software. One of them is to use Intel's own commercial C ++ compiler. Another is to download and compile GCC 4.6 or 4.7 from the source and use it directly. This is the option I have chosen. I followed this guide. Compiling and installing GCC (while clean) is still a problem and a workaround for using only one internal processor, but it works, Thanks, GCC team!

+7
source share

All Articles