From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | Nathan Bossart <nathandbossart(at)gmail(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: micro-optimize nbtcompare.c routines |
Date: | 2024-09-27 02:50:13 |
Message-ID: | CAApHDvrAi259611bx=EiWBjYhmRyxzUMssVW8E31+vHH2Vachw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, 27 Sept 2024 at 08:17, Nathan Bossart <nathandbossart(at)gmail(dot)com> wrote:
> Here's a patch that adjusts several routines in nbtcompare.c and related
> files to use the branchless integer comparison functions added in commit
> 6b80394. It's probably unlikely this produces a measurable benefit (at
> least I've been unable to find any in my admittedly-limited testing), but
> in theory it should save a cycle here and there. I was hoping that this
> would trim many lines of code, but maintaining the STRESS_SORT_INT_MIN
> stuff eats up most of what we save.
I had been looking at [1] (which I've added your version to now). I
had been surprised to see gcc emitting different code for the first 3
versions. Clang does a better job at figuring out they all do the same
thing and emitting the same code for each.
I played around with the attached (hacked up) qsort.c to see if there
was any difference. Likely function call overhead kills the
performance anyway. There does not seem to be much difference between
them. I've not tested with an inlined comparison function.
Looking at your version, it doesn't look like there's any sort of
improvement in terms of the instructions. Certainly, for clang, it's
worse as it adds a shift left instruction and an additional compare.
No jumps, at least.
What's your reasoning for returning INT_MIN and INT_MAX?
David
Attachment | Content-Type | Size |
---|---|---|
qsort.c | text/plain | 6.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Nathan Bossart | 2024-09-27 03:23:43 | Re: micro-optimize nbtcompare.c routines |
Previous Message | Nathan Bossart | 2024-09-27 02:38:40 | Re: pg_ctl/miscinit: print "MyStartTime" as a long long instead of long to avoid 2038 problem. |