Re: [HACKERS] Do we need the gcc feature "__builtin_expect" topromote the branches prediction?

Поиск
Список
Период
Сортировка
От Hao Lee
Тема Re: [HACKERS] Do we need the gcc feature "__builtin_expect" topromote the branches prediction?
Дата
Msg-id CAGoxFiF52uLDjHNSqU1Wa1dWkCSwkz7vtFeq_qVa9ZxQb6S-0A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [HACKERS] Do we need the gcc feature "__builtin_expect" topromote the branches prediction?  (Andres Freund <andres@anarazel.de>)
Ответы Re: [HACKERS] Do we need the gcc feature "__builtin_expect" topromote the branches prediction?  (Craig Ringer <craig@2ndquadrant.com>)
Список pgsql-hackers
and another things come into my mind, in some scenario, as we know that the native library is not the most effective way to do that, such as, allocation a large amount of memories by using "alloc()"... and "memmove()", so on. As the SIMD instruction became the standard in CPU, therefore, we can that to do something more effectively. for example, using SIMD to impl 'alloc',"memmove" and so on, or the other database operations. and it seems that there some one have done this job. 




On Fri, Jun 2, 2017 at 11:32 PM, Andres Freund <andres@anarazel.de> wrote:
Hi,

On 2017-06-02 16:40:56 +0800, Hao Lee wrote:
> 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
> }

We already do this in a few cases, that are performance critical enough
to matter.  But in most cases the CPUs branch predictor does a good
enough job on its own.

- Andres

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Use of non-restart-safe storage by temp_tablespaces
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: [HACKERS] Do we need the gcc feature "__builtin_expect" topromote the branches prediction?