From: | David Rowley <drowley(at)postgresql(dot)org> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Add functions to calculate the next power of 2 |
Date: | 2020-04-08 04:23:24 |
Message-ID: | E1jM2FI-00045j-Bl@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Add functions to calculate the next power of 2
There are many areas in the code where we need to determine the next
highest power of 2 of a given number. We tend to always do that in an
ad-hoc way each time, generally with some tight for loop which performs a
bitshift left once per loop and goes until it finds a number above the
given number.
Here we add two generic functions which make use of the existing
pg_leftmost_one_pos* functions which, when available, will allow us to
calculate the next power of 2 without any looping.
Here we don't add any code which uses these new functions. That will be
done in follow-up commits.
Author: David Fetter, with some minor adjustments by me
Reviewed-by: John Naylor, Jesse Zhang
Discussion: https://postgr.es/m/20200114173553.GE32763%40fetter.org
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/f0705bb6286d8a24e08ddd99641264ba947ebd03
Modified Files
--------------
src/include/port/pg_bitutils.h | 72 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2020-04-08 04:29:21 | pgsql: Create memory context for HashAgg with a reasonable maxBlockSize |
Previous Message | Tom Lane | 2020-04-08 04:10:22 | pgsql: Put back mistakenly removed #include. |