RFR: 8356760: VectorAPI: Optimize VectorMask.fromLong for all-true/all-false cases [v3]

Jatin Bhateja jbhateja at openjdk.org
Fri Jul 18 03:17:54 UTC 2025


On Mon, 7 Jul 2025 09:04:40 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:

>>> > > public static final VectorSpecies FSP = FloatVector.SPECIES_512;
>>> > > public static long micro1(long a) {
>>> > > long mask = Math.min(-1, Math.max(-1, a));
>>> > > return VectorMask.fromLong(FSP, mask).toLong();
>>> > > }
>>> > > public static long micro2() {
>>> > > return FSP.maskAll(true).toLong();
>>> > > }
>>> > 
>>> > 
>>> > With this JMH method we can not see obvious performance improvement, because the hot spots are other instructions. Adding a loop is better.
>>> 
>>> There is no hard and fast rule for the inclusion of a loop in a JMH micro in that case?
>> 
>> You mean adding a loop is not a block, right ?
>
>> > > > public static final VectorSpecies FSP = FloatVector.SPECIES_512;
>> > > > public static long micro1(long a) {
>> > > > long mask = Math.min(-1, Math.max(-1, a));
>> > > > return VectorMask.fromLong(FSP, mask).toLong();
>> > > > }
>> > > > public static long micro2() {
>> > > > return FSP.maskAll(true).toLong();
>> > > > }
>> > > 
>> > > 
>> > > With this JMH method we can not see obvious performance improvement, because the hot spots are other instructions. Adding a loop is better.
>> > 
>> > 
>> > There is no hard and fast rule for the inclusion of a loop in a JMH micro in that case?
>> 
>> You mean adding a loop is not a block, right ?
> 
> Yes. If you see gains without loop go for it.

> As @jatin-bhateja suggested, I have refactored the implementation and updated the commit message. please help review this PR, thanks!

Thanks a lot @erifan , I am out for the rest of the week, will re-review early next week.

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

PR Comment: https://git.openjdk.org/jdk/pull/25793#issuecomment-3086554704


More information about the hotspot-compiler-dev mailing list