The lost art of compiling programs for specific CPUs

kranky

Elite Member
Oct 9, 1999
21,014
137
106
There was a day when you compiled programs specifically for certain CPUs. If the Pentium X performed better on certain instructions than the Pentium Z, you told the compiler you were going to use the Pentium X, and the compiler would adjust. That meant it probably wouldn't run on the Z, but it was worth it to squeeze out that extra performance. We did this with Unix kernels.

These days, programs are compiled for the lowest common denominator because no one knows what x86 CPU you might be using. It's obviously impractical for software vendors to carry multiple versions, and in most situations it wouldn't even matter.

With open source software and a good compiler, you could take care of things yourself if you had an application which needed every bit of speed (processing audio/video, or CAD applications).

Does anyone have an idea about how much of a boost you could get from a program if it was compiled specifically for, say, a P4 vs. the generic x86?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Damn... why wont this copy of OS X install on my Athlon? I mean, it's complied to run on any CPU, right?
 

kranky

Elite Member
Oct 9, 1999
21,014
137
106
I'm doubtful they could be completely optimized for P4s if they still have to run on lesser CPUs. Of course, the compilers have to be well-written also to do the best job.
 

beer

Lifer
Jun 27, 2000
11,169
1
0
Originally posted by: kranky
There was a day when you compiled programs specifically for certain CPUs. If the Pentium X performed better on certain instructions than the Pentium Z, you told the compiler you were going to use the Pentium X, and the compiler would adjust. That meant it probably wouldn't run on the Z, but it was worth it to squeeze out that extra performance. We did this with Unix kernels.

These days, programs are compiled for the lowest common denominator because no one knows what x86 CPU you might be using. It's obviously impractical for software vendors to carry multiple versions, and in most situations it wouldn't even matter.

With open source software and a good compiler, you could take care of things yourself if you had an application which needed every bit of speed (processing audio/video, or CAD applications).

Does anyone have an idea about how much of a boost you could get from a program if it was compiled specifically for, say, a P4 vs. the generic x86?

I remember reading a study somewhere where Gentoo was approximately 1% faster with P4 optimizations than i386. Of course, i don't have a link....
 

Aves

Lifer
Feb 7, 2001
12,232
29
101
Originally posted by: notfred
Damn... why wont this copy of OS X install on my Athlon? I mean, it's complied to run on any CPU, right?

If you read the post it's quite obvious he's referring to the x86 architecture.
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
i dunno, there are somethings i just wouldn't want to compile... like visual studio .net....
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: aves2k
Originally posted by: notfred
Damn... why wont this copy of OS X install on my Athlon? I mean, it's complied to run on any CPU, right?

If you read the post it's quite obvious he's referring to the x86 architecture.

I know, but they're all basically the same CPU. I was jsut pointing out that stuff is compiled for specific processors when the instruction set differs. The entire reason that x86 has stuck around so long is because it means programs don't have to be recompiled each time a new chip came out. If that was true, I'm sure intel would have moved to something better by now.
 

NogginBoink

Diamond Member
Feb 17, 2002
5,322
0
0
Depends on what the program does.

For a word processor, I would expect 0% improvement.

For a program that does lots of matrix math, I'd expect good improvement by using MMX instructions.

So the answer to this question, as is true with almos all performance questions, is "it depends."

BTW... I wouldn't say this is a lost art. There's not much "art" in checking a checkbox when you do a compile. ;)
 

kranky

Elite Member
Oct 9, 1999
21,014
137
106
notfred, compiling a program for a 386 with math co-processor could allow it to run on a P4, but that's not to say a P4-specific version wouldn't be a better performer. The x86 being upward-compatible doesn't mean it couldn't make a difference. We used a Fairchild-based CPU years ago for running a Unix variant and compiling the kernal specifically for the newer processor made a difference, although it would run either way.

NogginBoink, agreed, it only matters if the program is very CPU-intensive. But I read about programs that convert video formats that run for hours, and that got me wondering - if there was a big increase in performance for P4-specific versions, vendors could take advantage of that by offering such versions for download even if they don't offer it at retail. But if there's little difference, it's not worth the effort.

And "checking a box"? Sorry, I'm a command-line compiler guy. ;)
 

ElFenix

Elite Member
Super Moderator
Mar 20, 2000
102,414
8,356
126
Originally posted by: notfred
Originally posted by: ElFenix
most things are for p4 these days.

Name one program that will run on a P4 but not a P3.

theres plenty of programs that have p4 specific optimizations... anything with SSE2, for instance. they still run on other processors
rolleye.gif
 

Reel

Diamond Member
Jul 14, 2001
4,484
0
76
Originally posted by: kranky
And "checking a box"? Sorry, I'm a command-line compiler guy. ;)

Yeah seriously. What are some examples of GUI compilers?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: kranky
notfred, compiling a program for a 386 with math co-processor could allow it to run on a P4, but that's not to say a P4-specific version wouldn't be a better performer. The x86 being upward-compatible doesn't mean it couldn't make a difference. We used a Fairchild-based CPU years ago for running a Unix variant and compiling the kernal specifically for the newer processor made a difference, although it would run either way.

I know that the 386 version would run on the P4. ElFenix said most stuff was compiled for the P4, I said to show me an example of something compiled specifically for the P4.
 

arcain

Senior member
Oct 9, 1999
932
0
0
There are also ways of optimizing for certain CPUs without breaking compatibility with other CPUs (-mcpu option with GCC). This optimizes for a certain CPUs pipline, without using any unique instructions. It will run on other CPUs, but often with some performance degradation. The -march option in GCC takes full advantage of the instruction set for a CPU, and thus breaks compatibility with older CPUs.

And many programs have varying code paths that can take advantage of various features of CPUs (games, image processing, etc).

 

beer

Lifer
Jun 27, 2000
11,169
1
0
Originally posted by: ReelC00L
Originally posted by: kranky
And "checking a box"? Sorry, I'm a command-line compiler guy. ;)

Yeah seriously. What are some examples of GUI compilers?

I dunno, I just press the 'play' button in my IDE and some stuff happens and then a console appears with my program :)