Array addition and array sum Panama benchmarks

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Mar 20 17:18:17 UTC 2024


This is interesting.

MemorySegment reads double in the same way as other (pre-existing) 
VarHandles - e.g. as longs which are then converted to doubles (w/o 
using Unsafe::getDouble directly).

My feeling is that this is done because double/float are missing the 
getXYZUnaligned variant that other types provide (maybe because 
unaligned access to floating point values is not supported in all 
platforms?).

FFM has an advantage here compared to ByteBuffer (and even unsafe) in 
the sense that we know statically if a var handle is going to perform 
aligned access or not. So it could be possible _in principle_ to use 
Unsafe::getDouble or Unsafe::getLong + Double.longBitsToDouble() 
depending on the var handle characteristics.

Maurizio

On 20/03/2024 16:26, Roland Westrelin wrote:
> But then why does this one:
>
>      public void scalarSegmentArray(Data state) {
>          final MemorySegment input = state.inputSegment;
>          final double[] output = state.outputArray;
>          for(int i = 0; i < SIZE; i++) {
>              output[i] += input.getAtIndex(JAVA_DOUBLE, i);
>          }
>      }
>
> not vectorize? input and output can't overlap because one is off heap
> and the other is on heap. It seems for doubles the MemorySegment API
> reads a double in 2 steps: use getLongUnaligned() and then convert the
> result to double with Double.longBitsToDouble(). The vectorizer doesn't
> support vectorization of that long to double move. Whether it can or not
> (that is whether vector instructions for that exist or not), I don't
> know.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20240320/c89fe80b/attachment.htm>


More information about the panama-dev mailing list