RFR: 8279508: Auto-vectorize Math.round API [v5]
Jatin Bhateja
jbhateja at openjdk.java.net
Thu Feb 17 03:44:02 UTC 2022
On Wed, 16 Feb 2022 12:30:27 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:
>> Summary of changes:
>> - Intrinsify Math.round(float) and Math.round(double) APIs.
>> - Extend auto-vectorizer to infer vector operations on encountering scalar IR nodes for above intrinsics.
>> - Test creation using new IR testing framework.
>>
>> Following are the performance number of a JMH micro included with the patch
>>
>> Test System: Intel(R) Xeon(R) Platinum 8380 CPU @ 2.30GHz (Icelake Server)
>>
>>
>> Benchmark | TESTSIZE | Baseline AVX3 (ops/ms) | Withopt AVX3 (ops/ms) | Gain ratio | Baseline AVX2 (ops/ms) | Withopt AVX2 (ops/ms) | Gain ratio
>> -- | -- | -- | -- | -- | -- | -- | --
>> FpRoundingBenchmark.test_round_double | 1024.00 | 584.99 | 1870.70 | 3.20 | 510.35 | 548.60 | 1.07
>> FpRoundingBenchmark.test_round_double | 2048.00 | 257.17 | 965.33 | 3.75 | 293.60 | 273.15 | 0.93
>> FpRoundingBenchmark.test_round_float | 1024.00 | 825.69 | 3592.54 | 4.35 | 825.32 | 1836.42 | 2.23
>> FpRoundingBenchmark.test_round_float | 2048.00 | 388.55 | 1895.77 | 4.88 | 412.31 | 945.82 | 2.29
>>
>>
>> Kindly review and share your feedback.
>>
>> Best Regards,
>> Jatin
>
> Jatin Bhateja has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains seven commits:
>
> - 8279508: Adding few descriptive comments.
> - Merge branch 'master' of http://github.com/openjdk/jdk into JDK-8279508
> - 8279508: Replacing by efficient instruction sequence based on MXCSR.RC mode.
> - 8279508: Adding vectorized algorithms to match the semantics of rounding operations.
> - Merge branch 'master' of http://github.com/openjdk/jdk into JDK-8279508
> - 8279508: Adding a test for scalar intrinsification.
> - 8279508: Auto-vectorize Math.round API
> _Mailing list message from [Joseph D. Darcy](mailto:joe.darcy at oracle.com) on [hotspot-dev](mailto:hotspot-dev at mail.openjdk.java.net):_
>
> On 2/12/2022 6:55 PM, Jatin Bhateja wrote:
>
> > On Fri, 21 Jan 2022 00:49:04 GMT, Sandhya Viswanathan <sviswanathan at openjdk.org> wrote:
> > > The JVM currently initializes the x86 mxcsr to round to nearest even, see below in stubGenerator_x86_64.cpp: // Round to nearest (even), 64-bit mode, exceptions masked StubRoutines::x86::_mxcsr_std = 0x1F80; The above works for Math.rint which is specified to be round to nearest even. Please see: https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html : section 4.8.4
> > > The rounding mode needed for Math.round is round to positive infinity which needs a different x86 mxcsr initialization(0x5F80).
> > > Hi @sviswa7 ,
> > > As per JLS 17 section 15.4 Java follows round to nearest rounding policy for all floating point operations except conversion to integer and remainder where it uses round toward zero.
>
> That is a true background condition, but I will note that the Math.round method does independently define the semantics of its operation and rounding behavior, which has changed (slightly) over the lifetime of the platform.
>
> -Joe
Hi @jddarcy , Thanks for your comments, patch has been updated to follow the prescribed semantics of Math.round API.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7094
More information about the hotspot-compiler-dev
mailing list