Re: [PATCH] Use 128-bit math to accelerate numeric division, when 8 < divisor digits <= 16

Поиск
Список
Период
Сортировка
От Joel Jacobson
Тема Re: [PATCH] Use 128-bit math to accelerate numeric division, when 8 < divisor digits <= 16
Дата
Msg-id 889c4fa6-d750-41d1-8c15-ade7df0caf1e@app.fastmail.com
обсуждение исходный текст
Ответ на Re: [PATCH] Use 128-bit math to accelerate numeric division, when 8 < divisor digits <= 16  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Ответы Re: [PATCH] Use 128-bit math to accelerate numeric division, when 8 < divisor digits <= 16  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Re: [PATCH] Use 128-bit math to accelerate numeric division, when 8 < divisor digits <= 16  (John Naylor <john.naylor@enterprisedb.com>)
Список pgsql-hackers
On Sun, Jan 22, 2023, at 11:06, Dean Rasheed wrote:
> Seems like a reasonable idea, with some pretty decent gains.
>
> Note, however, that for a divisor having fewer than 5 or 6 digits,
> it's now significantly slower because it's forced to go through
> div_var_int64() instead of div_var_int() for all small divisors. So
> the var2ndigits <= 2 case needs to come first.

Can you give a measurable example of when the patch
the way it's written is significantly slower for a divisor having
fewer than 5 or 6 digits, on some platform?

I can't detect any difference at all at my MacBook Pro M1 Max for this example:
EXPLAIN ANALYZE SELECT count(numeric_div_volatile(1,3333)) FROM generate_series(1,1e8);

I did write the code like you suggest first, but changed it,
since I realised the extra "else if" needed could be eliminated,
and thought div_var_int64() wouldn't be slower than div_var_int() since
I thought 64-bit instructions in general are as fast as 32-bit instructions,
on 64-bit platforms.

I'm not suggesting your claim is incorrect, I'm just trying to understand
and verify it experimentally.

> The implementation of div_var_int64() should be in an #ifdef HAVE_INT128 block.
>
> In div_var_int64(), s/ULONG_MAX/PG_UINT64_MAX/

OK, thanks, I'll fix, but I'll await your feedback first on the above.

/Joel



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Himanshu Upadhyaya
Дата:
Сообщение: Re: HOT chain validation in verify_heapam()
Следующее
От: Tom Lane
Дата:
Сообщение: Re: run pgindent on a regular basis / scripted manner