[vectorIntrinsics] RFR: Load store memory segment
Quan Anh Mai
duke at openjdk.java.net
Wed Mar 30 17:04:00 UTC 2022
On Wed, 30 Mar 2022 00:58:10 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> Hi, may I ask why do we reject loading a vector from a heap `MemorySegment` not backed by a `byte[]`?
>>
>> Thank.
>
>> Hi, may I ask why do we reject loading a vector from a heap `MemorySegment` not backed by a `byte[]`?
>>
>
> I wanted to first keep to the equivalent functionality that is currently supported, then think through the implications of supporting any primitive backing array and what that means regarding alignment and byte order.
>
> MemorySegment now supports misaligned access on primitive arrays for values whose size is larger or smaller than the primitive array element size. However, by default the value layouts disallow that, for example (using the preview API for memory segments), for example:
>
>
> MemorySegment ias = MemorySegment.ofArray(
> new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
>
>
> // Access using element whose natural alignment is wider than the natural primitive array alignment
>
> // java.lang.IllegalArgumentException: Misaligned access at address: 16
> ias.set(JAVA_LONG, 0, 1L);
>
> // No exception
> ias.set(JAVA_LONG.withBitAlignment(8), 0, 1L);
>
> // No exception
> ias.set(JAVA_LONG.withBitAlignment(8), 1, 1L);
>
>
> // Access using element whose natural alignment is smaller than the natural primitive array alignment
>
> // java.lang.IllegalArgumentException: Misaligned access at address: 17
> ias.set(JAVA_SHORT, 1, (short) 1);
>
> // No exception
> ias.set(JAVA_SHORT, 0, (short) 1);
>
> // No exception
> ias.set(JAVA_SHORT.withBitAlignment(8), 1, (short) 1);
@PaulSandoz I see, however, the problem of alignment here seems a little backward since a byte array is the most unaligned kind of array, so if we support loads, stores from byte arrays then alignment does not need any consideration anymore. For byte order I agree that the story would be much more complicated since mismatched loads, stores here would introduce both memory endianness and register endianness for the defined results.
Thanks.
-------------
PR: https://git.openjdk.java.net/panama-vector/pull/187
More information about the panama-dev
mailing list