RFR: 8348638: Performance regression in Math.tanh
Mohamed Issa
duke at openjdk.org
Sat Mar 22 00:50:33 UTC 2025
On Fri, 7 Mar 2025 18:01:10 GMT, Jatin Bhateja <jbhateja 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.
>>
>> 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| >= 20**. This new endpoint is the closest value above the minimum (**55 * ln(2) / 2**) required for correctness that's possible when only retrieving the topmost word of the input register.
>>
>> 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 v24-b33](https://github.com/openjdk/jdk/releases/tag/jdk-24%2B33) as the baseline version.
>>
>> For performance data collected with the regression micro-benchmark referenced in the bug report, see the table below. Each result is the mean of 3 individual runs. In the high value scenarios (100, 1000, 10000, 100000), the changes significantly improve execution times to the point where are almost at parity with the baseline. Also, there is almost no impact to the low value (1, 2) scenarios.
>>
>> | Input range (+/-) | Baseline (ms) | No fix (ms) | With fix (ms) | No fix vs baseline (%) | Fix vs baseline (%) |
>> | :------------------: | :-------------: | :-----------: | :-------------: | :----------------------: | :-------------------: |
>> | 1 | 1842 | 1961 | 1969 | +6.46 | +6.89 |
>> | 2 | 2102 | 2010 | 1998 | -4.38 | -4.95 |
>> | 100 | 801 | 1018 | 716 | +27.09 | -10.61 |
>> | 1000 | 498 | 803 | 519 | +61.24 | +4.22 |
>> | 10000 | 474 | 755 | 491 | +59.28 | +3.59 |
>> | 100000 | 473 | 758 | 491 | +60.25 ...
>
> src/hotspot/cpu/x86/stubGenerator_x86_64_tanh.cpp line 330:
>
>> 328: __ pextrw(rax, xmm0, 3);
>> 329: __ shll(rax, 16);
>> 330: __ pextrw(rax, xmm0, 4);
>
> There is an output dependency here, result of shll will be overwritten by following pextrw.
Thanks - will address in the next update. Using multiple _pextrw_ commands is unnecessary anyway.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23889#discussion_r1987395956
More information about the hotspot-compiler-dev
mailing list