| From: | Hao Lee <mixtrue(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Do we need the gcc feature "__builtin_expect" to promote the branches prediction? |
| Date: | 2017-06-02 08:40:56 |
| Message-ID: | CAGoxFiF4qcQAytkBDYemRP2dhNBhoq3==HYkE7TrhNtnX3=pJQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Etsuro Fujita | 2017-06-02 09:10:27 | Re: Bug in ExecModifyTable function and trigger issues for foreign tables |
| Previous Message | Mengxing Liu | 2017-06-02 08:16:18 | Re: Re: [GSOC 17] Eliminate O(N^2) scaling from rw-conflict tracking in serializable transactions |