From 70052d3977d17e853d30def6f565955b5bd5103d Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Thu, 11 Jan 2024 10:41:25 -0500 Subject: [PATCH] Use JDK's unsignedMultiplyHigh in Int128Math --- .../src/main/java/io/trino/spi/type/Int128Math.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/core/trino-spi/src/main/java/io/trino/spi/type/Int128Math.java b/core/trino-spi/src/main/java/io/trino/spi/type/Int128Math.java index 2c8042841a20..b4a2e07aec00 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/type/Int128Math.java +++ b/core/trino-spi/src/main/java/io/trino/spi/type/Int128Math.java @@ -20,6 +20,7 @@ import static io.trino.spi.type.Decimals.longTenToNth; import static java.lang.Integer.toUnsignedLong; import static java.lang.Math.abs; +import static java.lang.Math.unsignedMultiplyHigh; import static java.lang.System.arraycopy; import static java.util.Arrays.fill; @@ -1359,16 +1360,6 @@ private static long signExtension(long value) return value >> 63; } - // TODO: replace with JDK 18's Math.unsignedMultiplyHigh - private static long unsignedMultiplyHigh(long x, long y) - { - // From Hacker's Delight 2nd Ed. 8-3: High-Order Product Signed from/to Unsigned - long result = Math.multiplyHigh(x, y); - result += (y & (x >> 63)); // equivalent to: if (x < 0) result += y; - result += (x & (y >> 63)); // equivalent to: if (y < 0) result += x; - return result; - } - private static int compareUnsigned(long leftHigh, long leftLow, long rightHigh, long rightLow) { int comparison = Long.compareUnsigned(leftHigh, rightHigh);