Re: Use compiler intrinsics for bit ops in hash
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: John Naylor <john.naylor@2ndquadrant.com>
Cc: David Fetter <david@fetter.org>, Jesse Zhang <sbjesse@gmail.com>, PostgreSQL Development <pgsql-hackers@postgresql.org>
Date: 2020-04-07T11:40:52Z
Lists: pgsql-hackers
Attachments
- v7-0001-Add-functions-to-calculate-the-next-power-of-2.patch (text/x-patch) patch v7-0001
- v7-0003-Modify-additional-power-2-calculations-to-use-new.patch (text/x-patch) patch v7-0003
- v7-0002-Modify-various-power-2-calculations-to-use-new-he.patch (text/x-patch) patch v7-0002
On Thu, 12 Mar 2020 at 22:59, John Naylor <john.naylor@2ndquadrant.com> wrote: > > On Thu, Mar 12, 2020 at 7:42 AM David Rowley <dgrowleyml@gmail.com> wrote: > > > > I don't think Jesse's proposed solution is that great due to the > > additional function call overhead for pg_count_leading_zeros_32(). The > > (num & (num - 1)) == 0 I imagine will perform better, but I didn't > > test it. > > Right, I believe we've all landed on the same page about that. I see > two ways of doing next_power_of_2_32 without an indirect function > call, and leaving pg_leftmost_one_pos32 the same as it is now. I > haven't measured either yet (or tested for that matter): I've attached an updated patch. It includes the modifications mentioned above to pre-check for a power of 2 number with the bit masking hack mentioned above. I also renamed the functions to be more aligned to the other functions in pg_bitutils.h I'm not convinced pg_ceil_log2_* needs the word "ceil" in there. I dropped the part of the patch that was changing longs to ints of a known size. I went on and did some additional conversion in the 0003 patch. There are more laying around the code base, but I ended up finding a bit to fix up than i had thought I would. e.g. various places that repalloc() inside a loop that is multiplying the allocation size by 2 each time. The repalloc should be done at the end, not during the loop. I thought I might come back to those some time in the future. Is anyone able to have a look at this? David
Commits
-
Modify additional power 2 calculations to use new helper functions
- 02a2e8b44200 13.0 landed
-
Modify various power 2 calculations to use new helper functions
- d025cf88ba5a 13.0 landed
-
Add functions to calculate the next power of 2
- f0705bb6286d 13.0 landed
-
Move src/backend/utils/hash/hashfn.c to src/common
- 05d8449e7369 13.0 cited