pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Optimise numeric multiplication for short inputs.
Date: Tue, 09 Jul 2024 09:03:33 +0000
Message-ID: <E1sR6l3-000yAB-Ir@gemulon.postgresql.org> (raw)

Optimise numeric multiplication for short inputs.

When either input has a small number of digits, and the exact product
is requested, the speed of numeric multiplication can be increased
significantly by using a faster direct multiplication algorithm. This
works by fully computing each result digit in turn, starting with the
least significant, and propagating the carry up. This save cycles by
not requiring a temporary buffer to store digit products, not making
multiple passes over the digits of the longer input, and not requiring
separate carry-propagation passes.

For now, this is used when the shorter input has 1-4 NBASE digits (up
to 13-16 decimal digits), and the longer input is of any size, which
covers a lot of common real-world cases. Also, the relative benefit
increases as the size of the longer input increases.

Possible future work would be to try extending the technique to larger
numbers of digits in the shorter input.

Joel Jacobson and Dean Rasheed.

Discussion: https://postgr.es/m/44d2ffca-d560-4919-b85a-4d07060946aa@app.fastmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ca481d3c9ab7bf69ff0c8d71ad3951d407f6a33c

Modified Files
--------------
src/backend/utils/adt/numeric.c | 220 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 219 insertions(+), 1 deletion(-)



Message-ID: <E1sR6l3-000yAB-Ir@gemulon.postgresql.org>
Permalink:  ../E1sR6l3-000yAB-Ir@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1sR6l3-000yAB-Ir@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: dean.a.rasheed@gmail.com, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Optimise numeric multiplication for short inputs.
  In-Reply-To: <E1sR6l3-000yAB-Ir@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox