[lworld+fp16] RFR: 8339473: Add support for FP16 isFinite, isInfinite and isNaN

Bhavana Kilambi bkilambi at openjdk.org
Tue Sep 17 12:14:33 UTC 2024


On Tue, 17 Sep 2024 12:09:41 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:

> > Hi @jatin-bhateja , just tested the other two intrinsics as well. I do get huge performance gains (on aarch64) with the java versions. I used these -
> > ```
> > @IntrinsicCandidate
> >     public static boolean isNaN(Float16 f16) {
> >         return ((float16ToRawShortBits(f16) & 0x7e00) == 0x7e00);
> >     }
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > ```
> > @IntrinsicCandidate
> >     public static boolean isInfinite(Float16 f16) {
> >         return ((float16ToRawShortBits(f16) ^ float16ToRawShortBits(POSITIVE_INFINITY)) & 0x7fff) == 0;
> >     }
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > ```
> > @IntrinsicCandidate
> >     public static boolean isFinite(Float16 f16) {
> >         return !(isInfinite(f16) || isNaN(f16));
> >      }
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > I see these gains compared to the intrinsic version uploaded in the latest patch on this PR -
> > ```
> > Benchmark               (SIZE)    Gain
> > FP16Ops.isFiniteHF      65504     1.18409353876134
> > FP16Ops.isInfiniteHF    65504     1.57611028955779
> > FP16Ops.isNaNHF         65504     1.48276431718062
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Do you think it's better to not have any intrinsics at all for these operations?
> 
> Thanks @Bhavana-Kilambi , yes it will be optimal, your java versions still carries @IntrinsicCandidate, hope we are not accedently running intrinsics, if that is not the case then making only a java side change should suffice as its also easily auto-vectorizatable

Thanks, I will make the necessary changes. I ran the tests with the `-XX:DisableIntrinsic` flag to test the java code and not run the intrinsics

-------------

PR Comment: https://git.openjdk.org/valhalla/pull/1239#issuecomment-2355548147


More information about the valhalla-dev mailing list