public inbox for [email protected]
help / color / mirror / Atom feedFrom: Nathan Bossart <[email protected]>
To: Alexander Lakhin <[email protected]>
Cc: Joseph Koshakow <[email protected]>
Cc: jian he <[email protected]>
Cc: Heikki Linnakangas <[email protected]>
Cc: Matthew Kim <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: Andres Freund <[email protected]>
Subject: Re: Remove dependence on integer wrapping
Date: Fri, 16 Aug 2024 13:56:05 -0500
Message-ID: <Zr-gxcOehrmppDGk@nathan> (raw)
In-Reply-To: <Zr-b1c6x-Yf31TCZ@nathan>
References: <ZrznaJTIOPgSjEJ7@nathan>
<CAAvxfHc2Smk92cJX4aUju1AdW_RpNN8csEj5rvf29b-YFHRmfQ@mail.gmail.com>
<Zrz0Zv4PVFxieEii@nathan>
<CACJufxH-uLR5SnnmVbGYj7Oy90zF_pYV3G_HxfbJ6Lu3XKGXxQ@mail.gmail.com>
<Zr5M3KxOZlEZRZIN@nathan>
<Zr50ZpSyrBx0EHfR@nathan>
<CAAvxfHfkHS1n0+wMbtKwj6_GE6+aSJ9JjnsCOOdZPhTKRs-Yhw@mail.gmail.com>
<Zr-DwBxep-IaayQF@nathan>
<[email protected]>
<Zr-b1c6x-Yf31TCZ@nathan>
On Fri, Aug 16, 2024 at 01:35:01PM -0500, Nathan Bossart wrote:
> On Fri, Aug 16, 2024 at 09:00:00PM +0300, Alexander Lakhin wrote:
>> #6 0x00005576cf627c68 in bms_singleton_member (a=0x5576d09f7fb0) at bitmapset.c:691
>> 691 if (result >= 0 || HAS_MULTIPLE_ONES(w))
>
> At a glance, this appears to be caused by the RIGHTMOST_ONE macro:
>
> #define RIGHTMOST_ONE(x) ((signedbitmapword) (x) & -((signedbitmapword) (x)))
I believe hand-rolling the two's complement calculation should be
sufficient to avoid depending on -fwrapv here. godbolt.org indicates that
it produces roughly the same code, too.
diff --git a/src/backend/nodes/bitmapset.c b/src/backend/nodes/bitmapset.c
index cd05c642b0..d37a997c0e 100644
--- a/src/backend/nodes/bitmapset.c
+++ b/src/backend/nodes/bitmapset.c
@@ -67,7 +67,7 @@
* we get zero.
*----------
*/
-#define RIGHTMOST_ONE(x) ((signedbitmapword) (x) & -((signedbitmapword) (x)))
+#define RIGHTMOST_ONE(x) ((bitmapword) (x) & (~((bitmapword) (x)) + 1))
#define HAS_MULTIPLE_ONES(x) ((bitmapword) RIGHTMOST_ONE(x) != (x))
--
nathan
view thread (19+ messages) latest in thread
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Remove dependence on integer wrapping
In-Reply-To: <Zr-gxcOehrmppDGk@nathan>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox