News for hackers. Stuff that matters.
Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by vardump on Friday December 26, 2014 @09:53PM (#8801488)
That's why I feel dynamic code generation is the future. JIT. It's madness to write high performance code to take CPU [1] and DRAM [2] specifics into account.

It's easy to write something that performs well on one system.

[1]: 32-bit or 64-bit -> how many registers are available. SSE2, SSE 4.1, AVX2, etc. Different prefetchers, cache configurations. Different instruction level limitations and performance. Differing amounts of cache with rather variable latencies.

[2]: Different number of memory channels, different distance between DRAM page changes.

Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by iopq on Friday December 26, 2014 @10:19PM (#8801546)
Compilers generate static code that will branch to the correct code path based on your architecture. You don't need to JIT until there are so many paths your executable becomes too big.
Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by grogers on Friday December 26, 2014 @11:11PM (#8801654)
Do the branches happen at run time or are the optimized routines selected at install time (or something else?)
Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by gsg on Friday December 26, 2014 @11:55PM (#8801738)
At load time. gcc's approach is to substitute an entry in the PLT, the CPU dispatch logic being run at that time to select the contents of the entry.
Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by vardump on Friday December 26, 2014 @10:26PM (#8801557)
Any references about this compiler?
Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by tmurray on Friday December 26, 2014 @11:52PM (#8801734)
https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Function-Attrib... and http://pasky.or.cz/dev/glibc/ifunc.c

look up the target attribute and the ifunc attribute--it's basically a way to compile multiple versions of a function for different targets in a single source file and then use the dynamic linker to determine which one to resolve at runtime. obvious use is for things like optimized memcpy implementations.

Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by vardump on Saturday December 27, 2014 @12:26AM (#8801795)
So, it's otherwise automatic, except I just have to write a selector routine that tries to decide the best performing routine to run at runtime and implementation for each individual case with varying hardware support.
Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by nkurz on Saturday December 27, 2014 @02:19AM (#8801954)
You only need to go to all that trouble if you want high performance across a variety of machines. If you are merely after bragging rights or trying to satisfy someone else's requirement, the theory is that you can compile the exact same piece of high level code using different optimization targets, and the compiler will do all the work for you, providing maximum performance for each instruction set practically for free...

Even more practically, Agner has a typically excellent description of the strengths and weaknesses of the dispatch strategies used by different compilers in Section 13 (p. 122) here: http://www.agner.org/optimize/optimizing_cpp.pdf

Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by awalton on Thursday January 01, 2015 @01:30AM (#8822327)
Well, you can write that code that tries to decide, or you can let GCC emit that code for you: https://gcc.gnu.org/wiki/FunctionMultiVersioning

All you need to do is figure out what's the best version of that function to write for that target, and let GCC do the rest of the heavy lifting.

Re:Sandy bridge, Ivy bridge, Haswell and the mess of Intel p... by nitrogen on Friday December 26, 2014 @10:37PM (#8801591)
icc does this, as an example. It got Intel into trouble because they changed the compiler at one point to use the slowest path on AMD processors.