0

For a project I intend to compile various *NIX OSs and their relative packages with different CPUs in order to maximize optimization and performance for specific systems. In order to save time and money I'd like to know if there really is a difference between compiling code with similar architectures.

For example: If I compile Debian GNU/Linux + all the packages of the default repos with an Intel Core i7-8700 and use the OS on a system with an Intel Core i7-8650U, will it perform the same as if I compiled everything with the i7-8650U or would I lose some performance? (I don't care about the percentage, I'd like to know even if it were 1%)

To put it shortly is there an amount of worth grater than zero (0) in compiling code on different CPU models of the same generation? Because if that wasn't the case I'd just take one CPU from every generation from every manufacturer and call it a day for all the other models.

2 Answers 2

1

If you are truly intending to maximize optimizations, then you'll be using target-specific optimizations, including those that rely on knowing the cache sizes of the processor. This means you'll almost certainly want one compile per processor, though you can compile on the fastest available processor for any of the others with appropriate -march and -mtune settings.

2
  • Do you know of a compiler which issues different code for two systems which differ only in cache size?
    – rici
    Commented Sep 21, 2018 at 3:00
  • IIRC, one of the compilers on my Solaris SPARC machine (if not GCC it'd be Sun/Oracle's offering) allows you to specify the cache sizes as command line options. I assume these are taken into account in code generation, but don't know for sure
    – Fox
    Commented Sep 21, 2018 at 7:33
1

You seem to be conflating two different issues. The architecture on which you compile code doesn't necessarily imply anything about the code that is generated by the compiler. For example, consider:

$ gcc -o hello hello.c

For a given version of gcc, this will likely generate the same code for a given hardware architecture no matter what underlying CPU you have.

There are some exceptions. For example, the -march=native flag will cause the compiler to emit code that might take advantage of features on the local machine's CPU. But even then, you can explicitly specify a value for march that differs from your machine's CPU architecture and the compiler will emit code that might not run on your machine.

1
  • Well, I asked a pretty specific question. If I take two Intel processors from the same generation, for example one aimed at desktop use and the other one being the laptop version, will the performance of the programs compiled by one of them and run on both of them be equal or will there be an actual difference making it worth to compile natively?
    – user749317
    Commented Sep 20, 2018 at 22:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .