Question

One thing I lack understanding on is how can code compiled for an Intel CPU work on an AMD CPU.

My base understanding is that if you compile C code, for example, the compiler turns the source code into machine language which will have instructions for a particular processor. So, you need to compile with a compiler for whatever platform you want your application to use. Why don't you require a compiler for AMD versus Intel, and have to buy software for a particular processor?

I know that AMD processors and Intel processors share some compatibility in the older x86 instructions; what I'd like to know is how do they do that? I mean, it's not like AMD or Intel are calling each other up and telling each other their trade secrets, so how can they create instruction sets that are compatible?

Is all compatibility still based on the 386 instruction set, with a bunch of statements like "IF AMD CPU, do this ELSE IF INTEL do that"?

Was it helpful?

Solution

AMD and Intel x86 and x86-64 CPUs are almost entirely compatible. They both implement all of x86 and x86-64. They each have their own extensions (like MMX and 3DNow), but compilers don't generally use them unless you tell them to. Nowadays, AMD and Intel both support almost all of each other's extensions. The only time you may have to worry about the difference is when you are doing really low-level kernel stuff.

By the way, the instruction set isn't really a "trade secret." The implementation is. Both companies produce documentation on the instruction set, so each can copy it. The reason for this is probably that if more companies produce compatible chips, more software will be written for this instruction set, so more people will buy these chips. x86/x86-64 is basically the standard architecture for desktops, guaranteeing that people will continue to buy Intel and AMD chips. Intel and AMD have very different implementations, they just execute the same code.

OTHER TIPS

Actually they do have a cross-licensing agreement. Information and innovation flowed from Intel to AMD back in the 90's when AMD was a second source of 386 and 486 processors, and then from AMD to Intel when Intel adopted the x86-64 extensions.

Remember also that the instruction sets for these processors are publicly documented; typically one vendor will invent a new set of instructions, and a generation or two later the other vendor will implement compatible extensions. As such, rather than IF 386 .... you have something more along the lines of IF SSE4 IS SUPPORTED ..., without regard to the specific vendor.

Both vendors implement the same instruction set, so when your compiled code gets turned into machine instructions, they will work on both chips. However, there are some special instruction sets such as SSE that can be specific to one vendor or another. If you want to improve performance for an application, you can make runtime checks to use these features when available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top