pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add functions to calculate the next power of 2
Date: Wed, 08 Apr 2020 04:23:24 +0000
Message-ID: <E1jM2FI-00045j-Bl@gemulon.postgresql.org> (raw)

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(+)



Message-ID: <E1jM2FI-00045j-Bl@gemulon.postgresql.org>
Permalink:  ../E1jM2FI-00045j-Bl@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1jM2FI-00045j-Bl@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org
  Subject: Re: pgsql: Add functions to calculate the next power of 2
  In-Reply-To: <E1jM2FI-00045j-Bl@gemulon.postgresql.org>
  References: <E1jM2FI-00045j-Bl@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox