pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: Matthew Kim <matthewkmkim@gmail.com>
Cc: Joseph Koshakow <koshy44@gmail.com>
Cc: jian he <jian.universality@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Andres Freund <andres@anarazel.de>
Subject: Re: Remove dependence on integer wrapping
Date: Wed, 7 Aug 2024 10:08:04 -0500
Message-ID: <ZrON1CT7Lk9_EJOG@nathan> (raw)
In-Reply-To: <ZrKY8PJwGg23eZ3R@nathan>
References: <Zp54I4WMbWW6AQnP@nathan>
	<CAAvxfHdWseDnK0gLYY51fdw-_pE=5Q2=K=pToVv5jo3YNVfHoQ@mail.gmail.com>
	<Zp7Q4erYWVjtWzQr@nathan>
	<Zp7cwd_6NXlHt6Ye@nathan>
	<CAAvxfHeg0En5VV_9pjoHgd0kerK7REL84XEiS6=PUDOSKwx9rg@mail.gmail.com>
	<CACJufxERqAgy4YBwc2hLZY=hw1kD2m6AVD3=kyAen8=HeLsfmw@mail.gmail.com>
	<CAAvxfHeOdkaQXoca3W54=RZ6opCWLzqgmDM6s8GrUxKG1Tk+_g@mail.gmail.com>
	<ZqBzEucmgeib_6Fe@nathan>
	<CAGzNdfGMe8vK1BRvUmW29T7rkqUhM67t=wbgsCSDBu=T+rqZrw@mail.gmail.com>
	<ZrKY8PJwGg23eZ3R@nathan>

I started looking at 0001 again with the intent of committing it, and this
caught my eye:

-        /* make the amount positive for digit-reconstruction loop */
-        value = -value;
+        /*
+         * make the amount positive for digit-reconstruction loop, we can
+         * leave INT64_MIN unchanged
+         */
+        pg_neg_s64_overflow(value, &value);

The comment mentions that we can leave the minimum value unchanged, but it
doesn't explain why.  Can we explain why?

+static inline bool
+pg_neg_s64_overflow(int64 a, int64 *result)
+{
+    if (unlikely(a == PG_INT64_MIN))
+    {
+        return true;
+    }
+    else
+    {
+        *result = -a;
+        return false;
+    }
+}

Can we add a comment that these routines do not set "result" when true is
returned?

-- 
nathan





view thread (85+ messages)  latest in thread

Message-ID: <ZrON1CT7Lk9_EJOG@nathan>
Permalink:  ../ZrON1CT7Lk9_EJOG@nathan/
Also on:    postgresql.org/message-id/ZrON1CT7Lk9_EJOG@nathan

 · 

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: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com, matthewkmkim@gmail.com, koshy44@gmail.com, jian.universality@gmail.com, exclusion@gmail.com, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org, andres@anarazel.de
  Subject: Re: Remove dependence on integer wrapping
  In-Reply-To: <ZrON1CT7Lk9_EJOG@nathan>

* 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