pgsql: Use pg_neg_s{32,64}_overflow() for some overflow checks - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Use pg_neg_s{32,64}_overflow() for some overflow checks
Date
Msg-id E1x1H6x-00000002zMQ-1y1K@gemulon.postgresql.org
Whole thread
List pgsql-committers
Use pg_neg_s{32,64}_overflow() for some overflow checks

The files updated in this commit open-coded checks based on a minimal
value (as of "x == PG_INTnn_MIN") combined with negative calculations.
More efficient equivalents are available in int.h with
pg_neg_s32_overflow() and pg_neg_s64_overflow().

Extracted from a larger patch by the same author.  These spots have
proved to reduce the number of instructions generated after testing
across some versions of clang and gcc, with and without the
__builtin_*_overflow() functions.  Some unlikely() can be removed, but
not all, cash.c standing as an exception.  There should be no behavioral
changes.

Suggested-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Author: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAON2xHO4tTFiow2KKLbpiOEJNL4Th5p1QVTm4mSdEU+KW1rrfQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8e483af5515ec4ee90d17a3864f5bb764e4e9c47

Modified Files
--------------
src/backend/utils/adt/cash.c    |  9 +++++----
src/backend/utils/adt/int.c     | 11 +++++------
src/backend/utils/adt/int8.c    | 12 ++++--------
src/backend/utils/adt/numeric.c |  3 +--
4 files changed, 15 insertions(+), 20 deletions(-)


pgsql-committers by date:

Previous
From: Nathan Bossart
Date:
Subject: pgsql: doc: Fix the data type named in the regdatabase entry.
Next
From: Daniel Gustafsson
Date:
Subject: pgsql: Handle PG_INT32_MIN negation overflow in right()