On Thu, 16 Apr 2026 05:10:52 GMT, Jatin Bhateja <[email protected]> wrote:

>> If we want to retain the asserts, they should be changed to:
>>             assert SUPPORTS_AVX512F == 
>> (VectorShape.getMaxVectorBitSize(int.class)   <= 512);
>>             assert SUPPORTS_AVX2    == 
>> (VectorShape.getMaxVectorBitSize(byte.class)   <= 256);
>>             assert SUPPORTS_AVX     == 
>> (VectorShape.getMaxVectorBitSize(float.class)   <= 256);
>> 
>> 
>> VectorShape.getMaxVectorBitSize is dependent on MaxVectorSize. MaxVectorSize 
>> is a JVM command line option and can be set by the user to be  a valid <= 
>> the cpu supported max.
>
>> If we want to retain the asserts, they should be changed to: assert 
>> SUPPORTS_AVX512F == (VectorShape.getMaxVectorBitSize(int.class) <= 512); 
>> assert SUPPORTS_AVX2 == (VectorShape.getMaxVectorBitSize(byte.class) <= 
>> 256); assert SUPPORTS_AVX == (VectorShape.getMaxVectorBitSize(float.class) 
>> <= 256);
>> 
>> VectorShape.getMaxVectorBitSize is dependent on MaxVectorSize. MaxVectorSize 
>> is a JVM command line option and can be set by the user to be a valid <= the 
>> cpu supported max.
> 
> There is a possibility of assertion failures at different AVX levels, e.g. 
> when UseAVX=1 then first assertion will fails since SUPPORTS_AVX512F will be 
> false but right hand side of equality will still be true.  Similarly with 
> UseAVX=3 on a system with AVX512BW feature, second assertion will fail 
> because VectorShape.getMaxVectorBitSize(byte.class) will return 512bit

> The question is whether vector math stubs should be used or not when 
> corresponding vector shapes aren't supported. That's what the asserts were 
> about. The assumption was that the support is there when SVML stubs are used. 
> I'd prefer `VectorMathLibrary` to be adjusted to take 
> `VectorShape.getMaxVectorBitSize()` into account.

Library entry suffix selection takes into account the species.vectorBitSize() 
and also depends on exact feature checks.
https://github.com/openjdk/jdk/blob/master/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java#L123

Also following assertion already consults VectorShapre.getMaxVectorBitSize  
https://github.com/openjdk/jdk/blob/master/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java#L124

In addition SVML.isSupported depends on VectorSupport.getMaxLaneCount which 
depends on MaxVectorSize. 
https://github.com/openjdk/jdk/blob/master/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java#L153
 
Its just that those 3 assertion in CPUFeatures were strict.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/30015#discussion_r3090995089

Reply via email to