Re: [MERGE] branch prediction hints

From: Kinkie <gkinkie_at_gmail.com>
Date: Wed, 13 Oct 2010 11:58:45 +0200

On Wed, Oct 13, 2010 at 11:53 AM, Amos Jeffries <squid3_at_treenet.co.nz> wrote:
> On 13/10/10 04:47, Kinkie wrote:
>>
>> Hi all,
>>   this patch-let makes implements a GCC feature to hint the branch
>> prediction algorithms about the likely outcome of a test. This is useful
>> to optimize the case of singleton patterns (e.g.
>> CacheManager::GetInstance).
>> This implements the likely() and unlikely() macros.
>>
>>        Kinkie
>
> I'm neutral on this.
>
> For now definitely hold the cache_manager.cc change until Alex SMP cache
> manager updates are in.
>
>
> I'm also fairly sure it can be done as a base template class to inherit
> from. There are a mix of good and crap examples online. Some are fully
> thread-safe.

I'm not sure the scope of this patch is clear: all it does is try to
hint the compiler that a single if() clause is most likely to be
false(it will be only true once, when the singleton gets instantiated,
and in that case we don't care about performance). The compiler's
optimizer then can possilby hint the CPU branch predictor and lay out
code optimizing for the prediced case (e.g. jump on the unlikely case
so not to stall the CPU cache).

This has nothing to do with class design, or thread safety.

-- 
    /kinkie
Received on Wed Oct 13 2010 - 09:58:51 MDT

This archive was generated by hypermail 2.2.0 : Wed Oct 13 2010 - 12:00:05 MDT