Top
Best
New

Posted by chrka 6 hours ago

Your code is fast – if you're lucky(tiki.li)
109 points | 74 commentspage 2
IshKebab 4 hours ago|
Wow that is quite surprising. Almost seems like it could be a compiler bug tbh. Very fragile optimisation if not!
adgjlsfhk1 3 hours ago|
it's arguably more of a cpu bug than a computer bug. The problem is that predictable data determined whether a cmov or a branch is faster. cmov is only faster than if when the branch is unpredictable. Summer the compiler doesn't know what values your program will be called with, it can only pick and hope. To fix this, cpus could have an instruction like cmov but that learns whether speculation would be profitable and converts to treat it like a branch if better.
delamon 3 hours ago|||
You can, in fact, give compiler a hint wether the branch will be predictable or not. E.g. clang has __builtin_unpredictable().
astrobe_ 2 hours ago|||
tbh, I'm not sure if we need "more clever" CPUs since they cause more and more unpredictable performance outcome -- and more pressing issues like Spectre. Besides, looking at the evolution of technology tells us that performance increases mainly comes from parallelism, like multicore and GPUs. Which doesn't apply to "annoyingly not parallel" problems of course. But besides "gambling" approaches like branch prediction, there's not much you can do about them in the general case.
matchbok3 3 hours ago||
[dead]