RFR: 8u backport of JDK-8243114 Implement montgomery{Multiply,Square}intrinsics on Windows

Simon Tooke stooke at redhat.com
Mon Jan 11 21:08:38 UTC 2021

Backport of JDK-8243114 Implement montgomery{Multiply,Square} intrinsics 
on Windows

JBS: https://bugs.openjdk.java.net/browse/JDK-8243114 


I would like to backport this performance enhancement to 8u, for 
performance and for Oracle parity.

The backport is trivial, with one exception: Visual Studio 2010 does not 
implement a required compiler intrinsic used by this backport.

Accordingly, the backport is #ifdef'ed to only apply on Windows if 
Visual Studio 2017 (or higher) is used as the build compiler.

I do not have (so was not able to test this backport with) intermediate 
versions of VS; if someone were to grep for _addcarry_u64 in intrin.h, 
perhaps earlier versions can be supported.

Visual Studio 2010 is still supported as a build compiler, but will not 
reap the benefit of this backport.

In addition, MontgomeryMultiplyTest is no longer omitted on Windows 
platforms, and I made sure to apply 8248347 (the follow-up build fix patch).

Using the program below, speedups were observed:

 >openjdk-8u282-b04-vs2010\bin\java MMTest
elapsed time 58220 ms

 >openjdk-8u282-b04-vs2017\bin\java -XX:+UseMontgomeryMultiplyIntrinsic 
-XX:+UseMontgomerySquareIntrinsic MMTest (this is the default)
elapsed time 25471 ms

 >openjdk-8u282-b04-vs2017\bin\java -XX:-UseMontgomeryMultiplyIntrinsic 
-XX:-UseMontgomerySquareIntrinsic MMTest
elapsed time 58980 ms

Test code:

    class MMTest {

       public static void main(String[] args) {
         Instant start = Instant.now();
         BigInteger base = BigInteger.ONE.shiftLeft(1024);
         long count = LongStream.rangeClosed(2, 100_000)
              .mapToObj(n -> BigInteger.valueOf(n).add(base))
              .filter(i -> i.isProbablePrime(50))
         Instant finish = Instant.now();
         long timeElapsed = Duration.between(start, finish).toMillis();
         System.out.format("elapsed time %d ms\n", timeElapsed);



More information about the jdk8u-dev mailing list