[HACKERS] Do we need the gcc feature "__builtin_expect" to promote the branches prediction? - Mailing list pgsql-hackers

From Hao Lee
Subject [HACKERS] Do we need the gcc feature "__builtin_expect" to promote the branches prediction?
Date
Msg-id CAGoxFiF4qcQAytkBDYemRP2dhNBhoq3==HYkE7TrhNtnX3=pJQ@mail.gmail.com
Whole thread Raw
Responses Re: [HACKERS] Do we need the gcc feature "__builtin_expect" topromote the branches prediction?  (Craig Ringer <craig.ringer@2ndquadrant.com>)
Re: [HACKERS] Do we need the gcc feature "__builtin_expect" topromote the branches prediction?  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Hi all, 
       There is a lot of "if statement" in system, and GCC provides a feature,"__builtin_expect", which  let compilers know which branch is mostly run. as we known, miss-prediction will lead the performance lost(because the CPU will thrown away some instructions, and re-fetch some new instructions). so that we can tell GCC how produce more efficient code. for example as following. 
It will gain performance promotion i think. As i know, the in Linux kernel, this feature is also applied already. 

 #define likely(cond)     __builtin_expect(cond,true)
#define unlikely(cond)  __builtin_expect(cond,false)

if (likely(cond)) {
//most likely run.
   xxxx
} else //otherwise.
{
   xxxx
}


Best Regards.

Hom.

pgsql-hackers by date:

Previous
From: "Mengxing Liu"
Date:
Subject: Re: [HACKERS] Re: [GSOC 17] Eliminate O(N^2) scaling fromrw-conflict tracking in serializable transactions
Next
From: Etsuro Fujita
Date:
Subject: Re: [HACKERS] Bug in ExecModifyTable function and trigger issues forforeign tables