Java 8 Integer and Long unsigned methods - are there plans to add intrinsics for them?
Andrew Haley
aph at redhat.com
Fri Apr 11 13:21:02 UTC 2014
On 04/11/2014 01:58 PM, Roman Leventov wrote:
> No, the code for x86 is the same. But long division is almost twice slower than int on AMD.
>
> IMO the worth of having unsigned helpers in standard lib is mainly in ability of achiving native performance (exactly equal to performance of builtin signed division). Because it isn't bothering to add these one-liners to own adhoc.util.Math class, keeping compatibility with Java 7.
Right, but all we've got to do is persuade C2 not to CSE the unsigned
ConvI2L when expanding a division, then we can match
(Set dst (DivL (AndL (ConvI2L src1) mask) (AndL (ConvI2L src2) mask1)))
in the back ends, and we're done.
> 11.04.14, 15:52, "Andrew Haley" <aph at redhat.com>":
>>
>> On 04/11/2014 12:54 AM, Roman Leventov wrote:
>>> > 11.04.2014, 02:51, "Christian Thalinger" <christian.thalinger at oracle.com>:
>>> > Do you see a performance problem with these methods?
>>> Currently divideUnsigned and remainderUnsigned take a dozen of instructions with
>>> widening to long, while there is a signle div assembly instruction for this.
>>
>> It seems this is an x86 thing rather than a HotSpot thing. On AArch64
>> I get
>>
>> 01c ubfm R10, R2, 0, 31 # ui2l
>> 020 ubfm R11, R1, 0, 31 # ui2l
>> 024 cbeq R10, B4 P=0.000001 C=-1.000000
>> 028 sdiv R10, R11, R10
>>
>> This isn't exactly ideal, given that long division is slower than int
>> division, but it's not terrible.
>>
>> I can't match on
>>
>> (Set dst (DivL (AndL (ConvI2L src1) mask) (AndL (ConvI2L src2) mask1)))
>>
>> and generate a simple udiv because of the pesky (If ...) that checks for
>> division by zero. I suppose we could persuade HotSpot to rearrange things.
>>
>> Andrew.
>>
>
>
More information about the hotspot-compiler-dev
mailing list