I can't tell if it would be useful to do this: x = get_x(); __builtin_expect(x&MASK,KNOWNBITS); __builtin_expect(x<=KNOWNMAX,1); __builtin_expect(x>=KNOWNMIN,1); // code which uses x would follow this
Given two booleans that are 2/3 likely, the chance of both is 4/9 likely. So maybe it is appropriate to do this: if(__builtin_expect((__builtin_expect(x,1) && __builtin_expect(y,1)), 0)) Yes? No? Suppose that I am quite certain of how likely something will be, and that I care deeply about optimization. At what point should I mark my code with __builtin_expect()? The obvious choice is whenever the liklihood is not exactly 50%, but I hear that this varies by architecture. ARM supposedly uses a very strong branch prediction bit that forces a major stall when the expectation is wrong, while x86 is not so punishing. No hint of this is in the documentation. -- Summary: __builtin_expect needs better documentation Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: acahalan at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26366