calculating Luhn checksum with Vector API
Paul Sandoz
paul.sandoz at oracle.com
Mon Aug 22 18:11:22 UTC 2022
Hi,
You should write a JMH benchmarking comparing the performance of the vectorized version with a sequential version. If the former is not performing as expected then we can look at the generated assembler code.
For reduction of lanes, such as adding all lanes see ByteVector.reduceLanes (watch out for potential overflow in this case?).
When measuring you can experiment with placing the mask inline or in a static final field.
Paul.
> On Aug 19, 2022, at 12:32 PM, Ghadi Shayban <gshayban at gmail.com> wrote:
>
> Hi folks,
> I've implemented [1] the common Luhn checksum algorithm [2], and I have a few questions:
>
> How does one verify that the method is jitting to the good instructions, rather than to e.g. a sequential fallback?
> Is L31-L39 the right way to do an addition across lanes? Should VectorShuffles be squirreled away in a static final? I see the admonition at the end of [3] about storing in non-final fields, but I wasn't sure if hotspot would treat the inline locals as constant.
>
> Thanks!
>
> [1] https://gist.github.com/ghadishayban/9bfdc8230cfdcc8f7bad6d3fd8797552
> [2] https://en.wikipedia.org/wiki/Luhn_algorithm
> [3] https://download.java.net/java/early_access/jdk19/docs/api/jdk.incubator.vector/jdk/incubator/vector/VectorShuffle.html
More information about the panama-dev
mailing list