there is no evil compiler worst case that is triggered by bad prediction. A branch can be arranged only in two ways. Without hints, it's random, with hints, you can make sure that you are doing better than random (50%).
On Tue, Nov 10, 2015 at 6:48 AM, Barret Rhoden <[email protected]> wrote: > On 2015-11-09 at 15:41 "'Davide Libenzi' via Akaros" > <[email protected]> wrote: > > > > + for (;; dst++, src++) { > > > > + int error = __get_user(dst, src, 1); > > > > > > > > - static_assert(ULIM % PGSIZE == 0 && ULIM != 0); // prevent > > > wrap-around > > > > + if (unlikely(error)) > > > > + return error; > > > > + if (unlikely(!*dst)) > > > > + break; > > > > > > How unlikely is this? It'll happen once per strcpy, right? Is that > > > going to be a TLB miss or something based on what the compiler does > > > to make something unlikely? This example gets at the tradeoff of > > > using likely/unlikely. > > > > > > > If AVG string length is, say, 8, then that is more unlikely than > > likely. So the question is, in a tight loop like that, out of 8 > > times, would you prefer to be kicked in the ankle 7 times out of 8, > > or 1 out of 8? ☺ > > It depends how hard the kicks are. If the 7 kicks are light taps, and > the 1 kick is really painful, then I don't mind the 7. > > That's my understanding of the tradeoffs with these branch hints: due > to the techniques used by the compiler, it may be that taking the > unlikely branch is disproportionately more painful than not taking the > branch without a hint, such that the inflection point for using > unlikely is not necessarily 51%. Anyway, that's why I don't like the > use of likely/unlikely except in provably better cases (e.g. as in > assert()) or with actual performance numbers. > > Barret > > -- > You received this message because you are subscribed to the Google Groups > "Akaros" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Akaros" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
