Re: Optimising numeric division

Joel Jacobson <joel@compiler.org>

From: "Joel Jacobson" <joel@compiler.org>
To: "Dean Rasheed" <dean.a.rasheed@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-08-23T21:03:56Z
Lists: pgsql-hackers
On Fri, Aug 23, 2024, at 21:21, Joel Jacobson wrote:
> On Fri, Aug 23, 2024, at 15:49, Dean Rasheed wrote:
>> The attached patch attempts to resolve those issues by replacing
>> div_var() and div_var_fast() with a single function intended to be
>> faster than both the originals.
...
> I've had an initial look at the code and it looks straight-forward,
> thanks to most of the complicated parts of the changed code is just
> change of NBASE to NBASE_SQR.

This part seems to be entirely new:

```
if (remainder[0] < 0)
{
	/* remainder < 0; quotient is too large */
	...
}
else
{
	/* remainder >= 0 */
	...
}
```

Maybe add some additional comments here? Or maybe it's fine already as is,
not sure what I think. Nothing specific here that is extra complicated,
but there are four nested branches, so quite a lot in total to keep track of.

Regards,
Joel



Commits

  1. Speed up numeric division by always using the "fast" algorithm.