Re: Greatest Common Divisor

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Chapman Flack <chap(at)anastigmatix(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Greatest Common Divisor
Date: 2020-01-06 12:52:33
Message-ID: alpine.DEB.2.21.2001061336390.24609@pseudo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello Robert,

>> if (arg1 == PG_INT32_MIN)
>> if (arg2 == 0 || arg2 == PG_INT32_MIN)
>>
>> And possibly a "likely" on the while.
>
> I don't think decoration the code with likely() and unlikely() all
> over the place is a very good idea.

> Odds are good that we'll end up with a bunch that are actually
> non-optimal, and nobody will ever figure it out because it's hard to
> figure out.

My 0.02€: I'd tend to disagree.

Modern pipelined processors can take advantage of speculative execution on
branches, so if you know which branch is the more likely it can help.

Obviously if you get it wrong it does not, but for the above cases it
seems to me that they are rather straightforward.

It also provides some "this case is expected to be exceptional" semantics
to people reading the code.

> I have a hard time believing that we're going to be much
> worse off if we just write the code normally.

I think that your point applies to more general programming in postgres,
but this is not the context here.

For low-level arithmetic code like this one, with tests and loops
containing very few hardware instructions, I think that helping compiler
optimizations is a good idea.

Maybe in the "while" the compiler would assume that it is going to loop
anyway by default, so it may be less useful there.

--
Fabien.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2020-01-06 12:52:34 Re: [Proposal] Global temporary tables
Previous Message Masahiko Sawada 2020-01-06 12:43:16 Re: [Proposal] Table-level Transparent Data Encryption (TDE) and Key Management Service (KMS)