[vector] CharVector and unsigned bytes
Richard Startin
richard at openkappa.co.uk
Sat Dec 7 09:44:28 UTC 2019
"What specifically are you missing
in order to use ShortVector as a substitute for CharVector?"
Comparisons (vectorised) and eventual use as array indexes (after extraction from a vector), the motivation is unsigned 16 bit values in trie data structures, rather than a specific need for Java chars.
It's possible to emulate these operations straightforwardly with shorts by masking with 0xFFFF and using a custom comparator instead of the < operator everywhere, but in my experience this is both error prone and harder to read than using comparison operators. It's error prone because the masks/comparators inevitably don't get used everywhere, in scalar code it is too easy for short to promote to int and sign extend without masking, without lots of tests for data at the 0x7FFF/0x8000 boundary and perfect programmers/reviewers this results in bugs. There may be more friction without automatic promotion, of course.
________________________________
From: John Rose <john.r.rose at oracle.com>
Sent: 07 December 2019 01:29
To: Richard Startin <richard at openkappa.co.uk>
Cc: panama-dev at openjdk.java.net <panama-dev at openjdk.java.net>
Subject: Re: [vector] CharVector and unsigned bytes
On Dec 6, 2019, at 11:38 AM, Richard Startin <richard at openkappa.co.uk<mailto:richard at openkappa.co.uk>> wrote:
I see that there is no CharVector type - is there a plan for something like this or has it been ruled out, where the elements would behave like a Java char, except that operations would wrap rather than promote?
char is Java's only unsigned type, but there are many useful unsigned vector operations operating on 8 bit elements - might these be beyond the scope of the API because there is no such thing as an unsigned byte?
Some of the need for unsigned types can be replaced by specific operations
which perform zero filling on the left instead of sign filling.
Several such operations are in VectorOperations, including
LSHR and ZERO_EXTEND_S2I. What specifically are you missing
in order to use ShortVector as a substitute for CharVector?
Comparisons? Table lookup? Division?
— John
More information about the panama-dev
mailing list