Re: Greatest Common Divisor

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, 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-07 02:33:35
Message-ID: alpine.DEB.2.21.2001070251170.20326@pseudo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello Merlin,

>> 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.
>
> Do you have any performance data to back that up?

Yep.

A generic data is the woes about speculative execution related CVE (aka
Spectre) fixes and their impact on performance, which is in percents,
possibly tens of them, when the thing is more or less desactivated to
mitigate the security issue:

https://www.nextplatform.com/2018/03/16/how-spectre-and-meltdown-mitigation-hits-xeon-performance/

Some data about the __builtin_expect compiler hints:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0479r0.html

Basically, they are talking about percents, up to tens in some cases,
which is consistent with the previous example.

As I said, helping the compiler is a good idea, and pg has been doing that
with the likely/unlikely macros for some time, there are over an hundred
of them, including in headers which get expanded ("logging.h", "float.h",
"simplehash.h", …), which is a good thing.

I do not see any good reason to stop doing that, especially in low-level
arithmetic functions.

Now, I do not have specific data about the performance impact on a gcd
implementation. Mileage may vary depending on hardware, compiler, options
and other overheads.

--
Fabien.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-01-07 02:36:56 Re: Recognizing superuser in pg_hba.conf
Previous Message Tomas Vondra 2020-01-07 01:37:43 Re: RFC: seccomp-bpf support