-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
^ 优化及修复double解析可能潜在的bug; ^ 删除注释无用的代码;
- Loading branch information
Showing
21 changed files
with
948 additions
and
1,153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/io/github/wycst/wast/common/utils/JdkApiAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.github.wycst.wast.common.utils; | ||
|
||
/** | ||
* @Date 2024/6/8 14:22 | ||
* @Created by wangyc | ||
*/ | ||
public abstract class JdkApiAgent { | ||
|
||
public long multiplyHigh(long x, long y) { | ||
long x1 = x >> 32; | ||
long x2 = x & 0xFFFFFFFFL; | ||
long y1 = y >> 32; | ||
long y2 = y & 0xFFFFFFFFL; | ||
|
||
long z2 = x2 * y2; | ||
long t = x1 * y2 + (z2 >>> 32); | ||
long z1 = t & 0xFFFFFFFFL; | ||
long z0 = t >> 32; | ||
z1 += x2 * y1; | ||
return x1 * y1 + z0 + (z1 >> 32); | ||
} | ||
|
||
public long unsignedMultiplyHigh(long x, long y) { | ||
// Compute via multiplyHigh() to leverage the intrinsic | ||
long result = multiplyHigh(x, y); | ||
result += (y & (x >> 63)); | ||
result += (x & (y >> 63)); | ||
return result; | ||
} | ||
|
||
/** | ||
* Calculate the high bits of two long values. To be compatible with performance below JDK9, please ensure that x and y are both greater than 0 | ||
* | ||
* @param x > 0 | ||
* @param y > 0 | ||
* @return | ||
*/ | ||
public long multiplyHighKaratsuba(long x, long y) { | ||
long x1 = x >>> 32, x2 = x & 0xffffffffL; | ||
long y1 = y >>> 32, y2 = y & 0xffffffffL; | ||
long A = x1 * y1; | ||
long B = x2 * y2; | ||
long C = (x1 + x2) * (y1 + y2); | ||
// karatsuba | ||
long K = C - A - B; | ||
long BC = B >>> 32; | ||
return ((BC + K) >>> 32) + A; | ||
} | ||
} |
Oops, something went wrong.