On Thu, 3 Dec 2026 04:25:19 GMT, Jatin Bhateja <[email protected]> wrote:
>> Hi All,
>>
>> On x86, C2 currently implements vector count trailing zeros using following
>> formula :-
>>
>> ` ctz(x) = width - clz((x - 1) & ~x)
>> `
>> On targets supporting AVX-512 BITALG or AVX512_VPOPCNTDQ features , we can
>> use following shorter identity:-
>>
>> ` ctz(x) = popcount((x - 1) & ~x)
>> `
>> This will enable `vpopcntb/w` for byte/short lanes and `vpopcntd/q` for
>> int/long lanes. Existing lowering should remain as the fallback when these
>> CPU features are unavailable.
>>
>> Following are the performance number of benchmark included with the patch.
>>
>>
>> System: AMD EPYC 9755 128-Core Processor (Turin) Fixed frequency 2.5Ghz
>>
>> Baseline:-
>> ----------
>> Benchmark Mode Cnt Score
>> Error Units
>> VectorCountTrailingZerosBenchmark.byteThroughput thrpt 2 569.742
>> ops/us
>> VectorCountTrailingZerosBenchmark.intThroughput thrpt 2 1378.783
>> ops/us
>> VectorCountTrailingZerosBenchmark.longThroughput thrpt 2 1154.720
>> ops/us
>> VectorCountTrailingZerosBenchmark.shortThroughput thrpt 2 717.462
>> ops/us
>> VectorCountTrailingZerosBenchmark.byteLatency avgt 2 7.848
>> ns/op
>> VectorCountTrailingZerosBenchmark.intLatency avgt 2 3.328
>> ns/op
>> VectorCountTrailingZerosBenchmark.longLatency avgt 2 3.284
>> ns/op
>> VectorCountTrailingZerosBenchmark.shortLatency avgt 2 5.017
>> ns/op
>>
>> Withopt:-
>> ----------
>> Benchmark Mode Cnt Score
>> Error Units
>> VectorCountTrailingZerosBenchmark.byteThroughput thrpt 2 1174.785
>> ops/us
>> VectorCountTrailingZerosBenchmark.intThroughput thrpt 2 1600.252
>> ops/us
>> VectorCountTrailingZerosBenchmark.longThroughput thrpt 2 1396.755
>> ops/us
>> VectorCountTrailingZerosBenchmark.shortThroughput thrpt 2 1193.041
>> ops/us
>> VectorCountTrailingZerosBenchmark.byteLatency avgt 2 2.352
>> ns/op
>> VectorCountTrailingZerosBenchmark.intLatency avgt 2 2.344
>> ns/op
>> VectorCountTrailingZerosBenchmark.longLatency avgt 2 2.345
>> ns/op
>> VectorCountTrailingZerosBenchmark.shortLatency avgt 2 2.338
>> ns/op
>>
>>
>> Kindly review and share your feedback.
>>
>> Best Regards,
>> Jatin
>>
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the
>> [OpenJDK I...
>
> Jatin Bhateja has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Review comments resolution
Thanks for the update. It looks like we have a false dependency in vallones now
as we removed the vpxor. The xtmp is also a source and not initialized. We
could solve this in two ways:
1) add back the vpxor xtmp, xtmp, xtmp (better to do this in vallones).
or
2) use a slightly different sequence with no false dependency
(x - 1) & ~x is same as ~(x | -x)
The sequence ~(x | -x) is slightly better with one less operation:
vpxor xtmp, xtmp, xtmp
vpsub xtmp, xtmp, src // xtmp = -src
vpternlog xtmp, 0x5, xtmp, src // xtmp = ~(xtmp | src)
-------------
PR Comment: https://git.openjdk.org/jdk/pull/33863#issuecomment-7429576447