RFR: 8282664: Unroll by hand StringUTF16 and StringLatin1 polynomial hash loops [v13]
Claes Redestad
redestad at openjdk.org
Sun Nov 13 21:07:38 UTC 2022
On Sat, 12 Nov 2022 01:35:39 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
>> Claes Redestad has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Missing & 0xff in StringLatin1::hashCode
>
> src/java.base/share/classes/jdk/internal/util/ArraysSupport.java line 185:
>
>> 183: */
>> 184: @IntrinsicCandidate
>> 185: public static int vectorizedHashCode(Object array, byte mode) {
>
> The intrinsic can be generalized by:
> 1. expanding `array` input into `base`, `offset`, and `length`. It will make it applicable to any type of data source (on-heap/off-heap `ByteBuffer`s, `MemorySegment`s.
> 2. passing initial value as a parameter.
>
> Basically, hash code computation can be represented as a reduction: `reduce(initial_val, (acc, v) -> 31 * acc + v, data)`. You hardcode the operation, but can make the rest variable.
>
> (Even the operation can be slightly generalized if you make 31 variable and then precompute the table at runtime. But right now I don't see much value in investing into that.)
I've been thinking of generalizing as thus as a possible follow-up: get the base operation on entire arrays in, then generalize carefully while ensuring that doesn't add too much complexity, introduce unforeseen overheads etc.
-------------
PR: https://git.openjdk.org/jdk/pull/10847
More information about the core-libs-dev
mailing list