Alexander Lakhin <exclusion@gmail.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