RFR: 8265917: Different values computed by C2 and interpreter/C1 for Math.pow(x, 2.0) on x86_32 [v2]
Tobias Hartmann
thartmann at openjdk.java.net
Tue Apr 27 09:32:41 UTC 2021
On Mon, 26 Apr 2021 06:06:07 GMT, Jie Fu <jiefu at openjdk.org> wrote:
>> Hi all,
>>
>> C2 may produce different results for Math.pow(x, 2.0) compared with interpreter/C1 on x86_32.
>>
>> E.g., for Math.pow(1.0 / 2047, 2.0):
>>
>> interpreter: 2.38651580386563E-7
>> C2: 2.3865158038656307E-7
>>
>>
>> The reason is that C2 will replace Math.pow(x, 2.0) with x*x.
>> However, there is no such optimization for interpreter/C1 on x86_32.
>>
>> The fix just disables C2's opt for Math.pow(x, 2.0) on x86_32 since nobody (or very few people) would run x86_32.
>> And we don't have a plan to implement such opt on x86_32.
>>
>> Another reason to fix this bug is that we need this patch to extend C2's opt for Math.pow(x, 0.5) on other platforms.
>>
>> Thanks.
>> Best regards,
>> Jie
>
> Jie Fu has updated the pull request incrementally with one additional commit since the last revision:
>
> Optimize pow(x, 2.0) for x86_32
src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp line 2546:
> 2544:
> 2545: address static_const_table_pow = (address)_static_const_table_pow;
> 2546: static double DOUBLE2 = 2.0;
Constants in the 64-bit code and `_static_const_table_pow` above use `ATTRIBUTE_ALIGNED`. Should we add that for `DOUBLE2` as well?
src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp line 2555:
> 2553: movsd(xmm1, Address(rsp, 136));
> 2554:
> 2555: // Special case: pow(x, 2.0) => x * x
64-bit code also handles `Special case: pow(x, 0.5) => sqrt(x)`. Don't we need to add that as well for consistency?
-------------
PR: https://git.openjdk.java.net/jdk/pull/3677
More information about the hotspot-compiler-dev
mailing list