Re: Auto-vectorization speeds up multiplication of large-precision numerics

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Amit Khandekar <amitdkhan(dot)pg(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Auto-vectorization speeds up multiplication of large-precision numerics
Date: 2020-09-07 16:07:15
Message-ID: 1694682.1599494835@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Amit Khandekar <amitdkhan(dot)pg(at)gmail(dot)com> writes:
> On Mon, 7 Sep 2020 at 11:23, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> BTW, poking at this further, it seems that the patch only really
>> works for gcc. clang accepts the -ftree-vectorize switch, but
>> looking at the generated asm shows that it does nothing useful.
>> Which is odd, because clang does do loop vectorization.

> Hmm, yeah that's unfortunate. My guess is that the compiler would do
> vectorization only if 'i' is a constant, which is not true for our
> case.

No, they claim to handle variable trip counts, per

https://llvm.org/docs/Vectorizers.html#loops-with-unknown-trip-count

I experimented with a few different ideas such as adding restrict
decoration to the pointers, and eventually found that what works
is to write the loop termination condition as "i2 < limit"
rather than "i2 <= limit". It took me a long time to think of
trying that, because it seemed ridiculously stupid. But it works.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Konstantin Knizhnik 2020-09-07 16:35:50 Re: Improving connection scalability: GetSnapshotData()
Previous Message John Naylor 2020-09-07 15:43:00 Re: factorial function/phase out postfix operators?