Skip to content

Commit

Permalink
Use JDK's unsignedMultiplyHigh in Int128Math
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Jan 11, 2024
1 parent 5fbf6b0 commit 70052d3
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions core/trino-spi/src/main/java/io/trino/spi/type/Int128Math.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 70052d3

Please sign in to comment.