Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example can one have an executable that uses features for Core 2 processors and then selectively use other features for an older processor? Or is it a requirement to compile a different executable? And if no, is that true for all cases?

share|improve this question
In short, yes. You would have multiple code paths depending on existing feature sets (like MMX, SSE, ...). You could also compile different versions of the executable, one that requires the feature set and one that doesn't, then you could remove the feature check from the inner code path. – Oliver Salzburg Mar 18 '13 at 22:35

It is entirely possible, depending on the features you are referring to the approach is slightly different.

For example, for a math application, you can detect the number of processors and / or cores and then have each core handle a different parts of the calculation. The hard part then is making sure the data data is synchronous or asynchronous depending on the task at hand.

And, as stated before things like MMX, SSE2 can be checked for, and then either run via different code paths, something like:

if (CPU.Supports SSE2) {then use SSE2 Libraries}
else if (CPU.Supports SSE) {Then use SSE Libraries}
else {use pre-SSE LIbraries}

Also, for things like architechture (x86 vs x64) there are few ways that can be handled. If you use JAVA, or C# for example the JIT compiler can optimize the code for either architecture when the application launches, it is likely not as fast as a native and well optimized C++ application, but the trade off is that with C++ you would have to have a x64 and a x86 version separate.

share|improve this answer

You can have one executable which run-time detects which CPU is used, and then selects the best way to use them. Ofc. each of these 'best ways' is precompiled. So you are basically using a program which has been prepared to optimally use a selective few processors/instruction sets.

There are not many programs which seem to do that, or at least not many which tell the user about it. Still, there are at least a few of them, e.g. the dnetc executable.

If you want you can compare it to a book or leaflet, with an index stating:
page 10-20: English
page 21-42: Dutch
page 43-54: US english
page 55-70: Danish

You will have to write, in the appropriate language/instruction set for each of those.

share|improve this answer
Doesn't .net do this, but instead of multiple precompiled executables, use a proprietary format to encapsulate the source code in, and compile it on the fly? – MarcusJ Mar 18 '13 at 23:46
It can only do this for certain things. If you import SSE2 for example, .NET cannot always know how to use SSE, there might be new classes / methods in the newer library. And on the flip side, the new version might cut out deprecated methods from the original SSE. – AthomSfere Mar 18 '13 at 23:54
Mplayer has some CPU detection features and tells the user about it. – Ярослав Рахматуллин Mar 19 '13 at 8:00

The Linux kernel uses scary techniques like patching the running kernel to select the best algorithm for some much-used functions.

share|improve this answer
When you compile the Linux kernel on X86 you also have the option to select a destination CPU. (E.g. 386, P6, ... ). That way part of the kernel is already optimised before you run it, – Hennes Mar 19 '13 at 13:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.