News for hackers. Stuff that matters.
Re:Why is this C++ code faster than my hand-written assembly... by bachmeier on Tuesday August 22, 2017 @11:20AM (#15073242)
> you understand what the code intends, and the compiler does not

It seems to me that the best approach to this would be to feed more information to the compiler rather than writing assembly yourself. Otherwise you give up portability.

Re:Why is this C++ code faster than my hand-written assembly... by ktRolster on Tuesday August 22, 2017 @03:33PM (#15075648)
You are right. A lot of times you can rearrange the code in various ways, and the compiler will happily generate more efficient code.

When that's not possible, the way to keep it portable is by writing a generic C function, then writing an optimized version of the same function that will be compiled when that architecture is available.

At work it's rare to need to compile the same code for various architectures, but sometimes it happens.

Re:Why is this C++ code faster than my hand-written assembly... by mikeash on Tuesday August 22, 2017 @11:46AM (#15073516)
That's generally better when it's possible, but it's not always possible.

If you do start writing assembly, you usually want to have it exist next to a higher-level version of the code that you can toggle on and off. This lets you maintain portability (just compile the higher-level version on platforms where you don't yet have assembly) and makes it easy to try out new optimizations that wouldn't require assembly.

Re:Why is this C++ code faster than my hand-written assembly... by carussell on Tuesday August 22, 2017 @03:06PM (#15075438)