<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>This is interesting.</p>
    <p>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).</p>
    <p>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?).</p>
    <p>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.</p>
    <p>Maurizio<br>
    </p>
    <div class="moz-cite-prefix">On 20/03/2024 16:26, Roland Westrelin
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:8734sklvhu.fsf@redhat.com">
      <pre>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.</pre>
    </blockquote>
  </body>
</html>