Index: exceptiontransform.py =================================================================== --- exceptiontransform.py (revision 45847) +++ exceptiontransform.py (working copy) @@ -283,6 +283,12 @@ v_exc_type = self.gen_getfield('exc_type', llops) var_no_exc = self.gen_isnull(v_exc_type, llops) + # a hint that the backend can use for branch prediction + hints = {'expected': True} + c_hints = Constant(hints, lltype.Void) + var_no_exc = llops.genop('hint', [var_no_exc, c_hints], + resulttype = lltype.Bool) + block.operations.extend(llops) block.exitswitch = var_no_exc Index: c/src/support.h =================================================================== --- c/src/support.h (revision 45847) +++ c/src/support.h (working copy) @@ -45,6 +45,12 @@ # define RPyAssert(x, msg) /* nothing */ #endif +#ifdef __GNUC__ +# define RPyHintExpected __builtin_expect +#else +# define RPyHintExpected(x, y) (x) +#endif + #ifdef _RPyListOfString_New /* :-( */ # define HAVE_RPY_LIST_OF_STRING #endif Index: c/funcgen.py =================================================================== --- c/funcgen.py (revision 45847) +++ c/funcgen.py (working copy) @@ -600,6 +600,13 @@ def OP_HINT(self, op): hints = op.args[1].value + if 'expected' in hints: + # a hint for gcc. only works for ints or bools + if isinstance(hints['expected'], int): + return '%s = RPyHintExpected(%s, %d);' % ( + self.expr(op.result), + self.expr(op.args[0]), + hints['expected']) return '%s\t/* hint: %r */' % (self.OP_SAME_AS(op), hints) def OP_KEEPALIVE(self, op): # xxx what should be the sematics consequences of this