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

Bernd Eckenfels ecki at zusammenkunft.net
Wed Jan 13 00:24:32 UTC 2021

The patch does not touch the flag processing, will PrintFlagsFinal be able to tell if the version, compiler and os supports it?

Von: jdk8u-dev <jdk8u-dev-retn at openjdk.java.net> im Auftrag von Simon Tooke <stooke at redhat.com>
Gesendet: Monday, January 11, 2021 10:08:38 PM
An: jdk8u-dev at openjdk.java.net <jdk8u-dev at openjdk.java.net>
Betreff: RFR: 8u backport of JDK-8243114 Implement montgomery{Multiply,Square}intrinsics on Windows

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