aboutsummaryrefslogtreecommitdiff
path: root/src/include/port/pg_bitutils.h
diff options
context:
space:
mode:
authorJohn Naylor <john.naylor@postgresql.org>2022-02-20 13:22:08 +0700
committerJohn Naylor <john.naylor@postgresql.org>2022-02-20 13:22:08 +0700
commit4b35408f1ed59dd590f683ae0f015bbaf3b84d3d (patch)
treef0fbcde2e180f22114c14331512b8bcfacfcf5e6 /src/include/port/pg_bitutils.h
parentd7a978601d4e469f1a8f19122c049bb25fd7f096 (diff)
downloadpostgresql-4b35408f1ed59dd590f683ae0f015bbaf3b84d3d.tar.gz
postgresql-4b35408f1ed59dd590f683ae0f015bbaf3b84d3d.zip
Use bitwise rotate functions in more places
There were a number of places in the code that used bespoke bit-twiddling expressions to do bitwise rotation. While we've had pg_rotate_right32() for a while now, we hadn't gotten around to standardizing on that. Do so now. Since many potential call sites look more natural with the "left" equivalent, add that function too. Reviewed by Tom Lane and Yugo Nagata Discussion: https://www.postgresql.org/message-id/CAFBsxsH7c1LC0CGZ0ADCBXLHU5-%3DKNXx-r7tHYPAW51b2HK4Qw%40mail.gmail.com
Diffstat (limited to 'src/include/port/pg_bitutils.h')
-rw-r--r--src/include/port/pg_bitutils.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h
index 44c74fb9743..04e58cd1c44 100644
--- a/src/include/port/pg_bitutils.h
+++ b/src/include/port/pg_bitutils.h
@@ -285,12 +285,18 @@ extern int pg_popcount64(uint64 word);
extern uint64 pg_popcount(const char *buf, int bytes);
/*
- * Rotate the bits of "word" to the right by n bits.
+ * Rotate the bits of "word" to the right/left by n bits.
*/
static inline uint32
pg_rotate_right32(uint32 word, int n)
{
- return (word >> n) | (word << (sizeof(word) * BITS_PER_BYTE - n));
+ return (word >> n) | (word << (32 - n));
+}
+
+static inline uint32
+pg_rotate_left32(uint32 word, int n)
+{
+ return (word << n) | (word >> (32 - n));
}
#endif /* PG_BITUTILS_H */