News for hackers. Stuff that matters.
Re:Why is this C++ code faster than my hand-written assembly... by santaclaus on Tuesday August 22, 2017 @12:36PM (#15074055)
> For example I try to use ++x instead of x++

++x can be slower, depending on the context -- it introduces a sequence point.

Re:Why is this C++ code faster than my hand-written assembly... by mark-r on Tuesday August 22, 2017 @12:54PM (#15074209)
Really? If you have the time, I'd love an explanation. Or if you can point to some other resource that would be great too.
Re:Why is this C++ code faster than my hand-written assembly... by santaclaus on Tuesday August 22, 2017 @01:29PM (#15074580)
I remember seeing a blog post from Andrei Alexandrescu that I can't seem to dig up, but this SO post seems to be a nice summary [1]. In short, in 99.9999999% of usages post increment is probably better.

[1] https://stackoverflow.com/a/38947878

Re:Why is this C++ code faster than my hand-written assembly... by mark-r on Tuesday August 22, 2017 @04:55PM (#15076308)
Thanks. I guess I'm applying this rule only when the result of the increment isn't being used directly, so there is no dependency on the operation. When the result is used, the semantic difference between ++x and x++ obviously determines the choice.
Re:Why is this C++ code faster than my hand-written assembly... by flamedoge on Tuesday August 22, 2017 @04:05PM (#15075913)
Just look at the liveness of the expression x+1. post-increment means expression has to be alive before whatever uses '++x' whereas pre-increment can delay until next usage of x.