سؤال

Can I create a universal binary for Mac OS X that contains two versions of my app, one that is compiled with SSE4.2 and one that compiled with SSE3?

In this case I would the version compiled with SSE4.2 to be loaded automatically for CPU that support SSE4.2.

If no, I would like to get suggestions to run my app on old CPUs that do not support SSE4.2 but utilize SSE4.2 on CPU that support it.

Note that I target to the Mac AppStore, if that matter. I use Clang with Xcode 4.5.

هل كانت مفيدة؟

المحلول

This is not supported by the Mach-O format, which is used by Mac OS X. The format allows binaries for different architectures. There is a subtype field, but there are only values defined for different generations of processors, not their abilities.

There are a couple of ways to work around this. One would be to have both SSE4.2 and code for older processors built into the same binary, using different function names. Your code would determine whether or not SSE4.2 is supported, then call the proper function.

Another option would be to build two libraries, one with SSE4.2 and one without, and ship both of them in your application bundle, but not link to them. When it is first loaded, your code would determine whether or not SSE4.2 is supported and then load the right library.

Using the first method, you don't have to worry about loading a library and connecting all of the functions, but you will always load extra code which does not get executed, and you will have to check a variable before each of those function calls. Using the second method, you can simply call the functions without checking anything every time, but loading the library and connecting all of the functions is more work than simply comparing a variable each time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top