News for hackers. Stuff that matters.
Re:Outperforming LAPACK with C++ metaprogramming by pkaye on Monday January 29, 2018 @12:46PM (#16259157)
You should check out this presentation done by Matt Godbolt about compiler internals. He talks about what kind of optimizations are being done by GCC and Clang. Pretty amazing stuff. For example, the compiler will figure out you are trying to write a pop count in high level code and replace it with a single popcount instruction.

https://www.youtube.com/watch?v=bSkpMdDe4g4

Re:Outperforming LAPACK with C++ metaprogramming by dpwm on Monday January 29, 2018 @08:02PM (#16262075)
That talk really revealed some brilliant optimizations that Clang does. In addition to what you mentioned, the bit where Clang recognises the summation loop, removes the loop and replaces it with a closed-form solution feels intuitively more like the operations that only some cutting edge research-language compiler should be able to do. To see this for C and C++ is very impressive.
Re:Outperforming LAPACK with C++ metaprogramming by mpweiher on Monday January 29, 2018 @01:51PM (#16259667)
Amazing, yes. Scary, also.

If you're going to figure this out, please output a warning and ask me to call the optimized intrinsic or something.

Re:Outperforming LAPACK with C++ metaprogramming by bigcheesegs on Monday January 29, 2018 @07:41PM (#16261964)
Why? The intrinsics aren't portable, the other code is.
Re:Outperforming LAPACK with C++ metaprogramming by dpwm on Monday January 29, 2018 @08:21PM (#16262159)
Even with intrinsics that do have a degree of portability, I prefer the more explicit form of the bit counting just for readability. Nobody has to learn what popcnt means.

These optimizations really mean that as software writers we can declare our intent and have the compiler do safe optimizations.

It seems like these optimizations of Clang are also quite insensitive to the many different ways of writing the same thing that C++ has earned notoriety for.

Re:Outperforming LAPACK with C++ metaprogramming by mpweiher on Tuesday January 30, 2018 @04:26AM (#16263988)
> I prefer the more explicit form

Huh? It's not explicit, the purpose is implicit. You are writing down an algorithm that implements a popcount algorithm. The compiler than has to infer the fact that you actually wanted popcount (maybe you just wanted to waste a bit of time in a timing loop?) and then substitute something based on that inference.

I am all for it being explicit, i.e. some library function that has a name that somewhere mentions "popcount" or some such. Then have the compiler generate whatever code it needs for that function.

Re:Outperforming LAPACK with C++ metaprogramming by pkaye on Monday January 29, 2018 @08:20PM (#16262151)
What is your concern?