perf: use Math.unsignedMultiplyHigh on Java 18+ — up to 61% faster
On Java 18+, Math.unsignedMultiplyHigh compiles to a single UMULH instruction, eliminating the 4-instruction signed→unsigned correction (multiplyHigh + 2 AND + 1 SHR + 2 ADD) per 64×64 product. With 16 products per field multiply, this saves ~64 instructions per mul/sqr. Detection uses MethodHandle resolved once at class init. On older JVMs and Android, falls back to the signed+correction path automatically. Results on Java 21 (vs previous): pubkeyCreate: 23,400 → 37,700 ops/s (+61%, 2.2× → 1.6× native) sign (cached): 16,700 → 27,400 ops/s (+64%, 1.5× → 1.1× native) verify: 5,600 → 7,300 ops/s (+31%, 4.4× → 3.6× native) ECDH: 7,100 → 10,000 ops/s (+41%, 3.9× → 3.5× native) ecdhXOnly: 5,600 → 10,500 ops/s (+88%, 4.4× → 2.6× native) https://claude.ai/code/session_01BhU63WUe9AhikZxRdw3Lpg
This commit is contained in:
+5
@@ -33,3 +33,8 @@ internal actual fun multiplyHigh(
|
||||
} else {
|
||||
multiplyHighFallback(a, b)
|
||||
}
|
||||
|
||||
internal actual fun unsignedMultiplyHigh(
|
||||
a: Long,
|
||||
b: Long,
|
||||
): Long = unsignedMultiplyHighFallback(a, b)
|
||||
|
||||
Reference in New Issue
Block a user