Re: [PATCH] intXshr, intXshl: return error on shift count out of range

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>, Egor Ivkov <e(dot)ivkov(at)arenadata(dot)io>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ilya Khaprov <i(dot)khaprov(at)arenadata(dot)io>
Subject: Re: [PATCH] intXshr, intXshl: return error on shift count out of range
Date: 2026-09-30 19:24:46
Message-ID: 936421.1790796286@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alexander Lakhin <exclusion(at)gmail(dot)com> writes:
> By the way, having a RISC-V machine handy:
> Linux orangepirv2 6.6.63-ky #1.0.0 SMP PREEMPT Wed Mar 12 09:04:00 CST 2025 riscv64 riscv64 riscv64 GNU/Linux
> I've tried:
> SELECT int4shl(1, 100);
>  int4shl
> ---------
>       16
> (1 row)

FWIW, I don't agree with the premise of this patch, even a little bit.
To my mind, the purpose of these functions and their siblings is to
provide access to the C-level bitwise operators, which will do
whatever they do on your platform. There is no contract to restrict
them to some guaranteed-portable functionality subset, and I think
trying to do that would accomplish little except to break code that
had been working fine in the context it's used in.

We have generally taken a similar approach with respect to other
things that are platform-dependent, such as floating-point math.
FP math is more portable than it used to be thanks to IEEE 754's
achievement of world domination; but there are still discrepancies,
and we don't typically try to hide them.

There might be room for a documentation patch that adds something
like

-Bitwise shift left
+Bitwise shift left (defined to act like the C << operator)

just to clarify our intent.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aleksander Alekseev 2026-09-30 20:15:07 Re: Open SSI correctness issues
Previous Message David G. Johnston 2026-09-30 19:13:31 Re: Document that jsonpath == can be used as ANY