On Feb 27, 2009, at 12:00 AM, Stefan Behnel wrote:

> Robert Bradshaw wrote:
>> I was actually surprised how little of a difference the  
>> __builtin_expect
>> macros made in most cases, I guess gcc is good at guessing right  
>> most of
>> the time. (Still worth it I think, as we *know* the common code  
>> path.)
>
> I think the problem is that both of us are benchmarking these  
> things on
> Intel 32-bit platforms that don't support branch prediction hints and
> usually require a certain opcode chain anyway. Plus, these  
> processors are
> pretty smart about branch prediction anyway, so running tight loops in
> benchmarks will usually result in perfect branch prediction.

Sometimes it did make a difference though, but I found no logic as to  
when and can't remember the details now (probably because I wasn't  
able to fit it to a pattern). IIRC, the first time a branch is taken  
it makes a difference whether or not it's jumping forward or  
backward, and gcc sometimes uses this to rearrange code blocks even  
on processors that don't support hints.

> There might be a difference on other architectures like Itanium where
> compilers are smart and the metal is stupid.

For sure.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to