RFR: 8348638: Performance regression in Math.tanh [v6]
Jatin Bhateja
jbhateja at openjdk.org
Wed Apr 23 09:11:49 UTC 2025
On Tue, 22 Apr 2025 20:31:24 GMT, Mohamed Issa <duke at openjdk.org> wrote:
>> The changes described below are meant to resolve the performance regression introduced by the **x86_64 tanh** double precision floating point scalar intrinsic in #20657. Additionally, new input values are provided for the existing micro-benchmark and a new micro-benchmark is included to check the performance of specific input value ranges to help prevent regressions in the future.
>>
>> 1. Check and handle high magnitude input values before those in other ranges. If found, **+/- 1** is returned almost immediately without having to go through too many computations or branches.
>> 2. Reduce the lower bound of the input range that triggers a quick **+/- 1** return from **|x| >= 32** to **|x| >= 22**. This new endpoint is the exact value required for correctness that's used by the original OpenJDK implementation.
>>
>> The results of all tests posted below were captured with an [Intel® Xeon 6761P](https://www.intel.com/content/www/us/en/products/sku/241842/intel-xeon-6761p-processor-336m-cache-2-50-ghz/specifications.html) using [OpenJDK v25-b15](https://github.com/openjdk/jdk/releases/tag/jdk-25%2B15) as the baseline version.
>>
>> For the first set of performance data collected with the new built-in **tanhRange** micro-benchmark, see the table below. Each result is the mean of 8 individual runs, and the input ranges used match those in the bug report with two additional ones included. In the high value scenarios (100, 1000, 10000, 100000), the changes increase throughput values over the baseline. Also, there is a small negative impact to the low value (1, 2, 10, 20) scenarios.
>>
>> | Input range(s) | Baseline (ops/s) | Change (ops/s) | Change vs baseline (%) |
>> | :-------------------: | :----------------: | :----------------: | :------------------------: |
>> | [-1, 1] | 22671 | 22190 | -2.12 |
>> | [-2, 2] | 22680 | 22191 | -2.16 |
>> | [-10, 10] | 22683 | 22149 | -2.35 |
>> | [-20, 20] | 22694 | 22183 | -2.25 |
>> | [-100, 100] | 29806 | 33675 | +12.98 |
>> | [-1000, 1000] | 46747 | 49179 | +5.20 |
>> | [-10000, 10000] ...
>
> Mohamed Issa has updated the pull request incrementally with one additional commit since the last revision:
>
> Restructure tanh micro-benchmarks
test/micro/org/openjdk/bench/java/lang/MathBench.java line 68:
> 66:
> 67: @Param({"-2.0", "-1.0", "-0.5", "-0.1", "0.0", "0.1", "0.5", "1.0", "2.0"})
> 68: public double tanhConstInput;
The field is not a static final. So inputs to tanh will not be constant values.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23889#discussion_r2055604603
More information about the hotspot-compiler-dev
mailing list