Re: Optimize mul_var() for var1ndigits >= 8

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Joel Jacobson <joel@compiler.org>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-08-24T18:17:20Z
Lists: pgsql-hackers
Dean Rasheed <dean.a.rasheed@gmail.com> writes:
> On Wed, 14 Aug 2024 at 07:31, Joel Jacobson <joel@compiler.org> wrote:
>> I think this is acceptable, since it produces more correct results.

> Thanks for checking. I did a bit more testing myself and didn't see
> any problems, so I have committed both these patches.

About a dozen buildfarm members are complaining thus (eg [1]):

gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O2 -ftree-vectorize -I. -I. -I../../../../src/include  -D_GNU_SOURCE -I/usr/include/libxml2   -c -o numeric.o numeric.c
numeric.c: In function \342\200\230mul_var\342\200\231:
numeric.c:9209:9: warning: \342\200\230carry\342\200\231 may be used uninitialized in this function [-Wmaybe-uninitialized]
    term = PRODSUM1(var1digits, 0, var2digits, 0) + carry;
         ^
numeric.c:8972:10: note: \342\200\230carry\342\200\231 was declared here
  uint32  carry;
          ^

I guess these compilers aren't able to convince themselves that the
first switch must initialize "carry".

			regards, tom lane

[1] https://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=arowana&dt=2024-08-24%2004%3A19%3A29&stg=build



Commits

  1. Optimise numeric multiplication using base-NBASE^2 arithmetic.

  2. Extend mul_var_short() to 5 and 6-digit inputs.