Reputation: 8505
I am new to C++. Recently a discussion started in my company around compiling code for different machine architectures such as X86_64 AMD Vs Intel
Now i looked at the gcc flags that we pass to compile our applications, and there is nothing that tells gcc to compile specifically for AMD vs Intel on x86_64.
Can someone please explain in technical terms the dependency between compiled code and machine architecture?
Can i compile code using gcc-86_64 on AMD and run the binary code on intel x86_64?
Upvotes: 0
Views: 1051
Reputation: 23619
After the x86 32-bit processors, Intel wanted to move to 64-bit, and co-operated with HP to develop the 64-bit Itanium processor. Unfortunately, this was not very populare, since the instruction set and the architecture was rather different from x86.
AMD jumped in and extended the know x86 architecture to 64-bit, first calling it EM64T, but then AMD64. Just like AMD had to follow Intel with 32-bit processors, Intel now had to follow AMD with the 64-bit processors, since AMD's 64-bit architecture proved to be much more populare than the Itanium 64-bit processor.
Of course, Intel doesn't like it to be called AMD64, that's why they call it x64, but essentially AMD64 and Intel's x64 are compatible (except for some minor differences, see http://en.wikipedia.org/wiki/X86-64#Differences_between_AMD64_and_Intel_64). If you compile for x64 or AMD64, the generated code will avoid those differences so in practice you can run on both.
In any case, try to avoid generating for Itanium (also called IA-64) because this is a totally different kind of processor.
Upvotes: 2
Reputation: 1806
Specifically Instructions like SSE4A won't run on Intel processors. That's one of these places where things can go wrong.
Upvotes: 0
Reputation: 96109
You can optomize for x86-64 and AMD64 differently but there aren't any (AFAIK) instructions that are missing from one of them - although Intel's Itanium 64bit architecture is different.
Upvotes: 0
Reputation: 516
You can compile for specific architectures/processors using the gcc -march flag. Be warned though, you really shouldn't ever try to run a binary compiled for a different CPU/architecture on your machine though. It may work, but most times it will fail randomly due to how the binary was optimized.
You can use the less aggressive -mtune flag which will optimize it for a specific target CPU, but it will still retain the ability to be run on any CPU.
See these links: What's optimal march & mtune options for gcc for "Pentium4 and above" processors http://en.gentoo-wiki.com/wiki/Safe_Cflags
Upvotes: 1