Read / write partially allocated aligned memory

There are many questions about access to unallocated memory, which is clearly undefined. But what about the next corner case.

Consider the following structure, which is aligned with 16 bytes, but takes up only 8 bytes:

struct alignas(16) A
{
    float data[2]; // the remaining 8 bytes are unallocated
};

Now we get access to 16 bytes of data using the built-in functions of loading / storage via SSE:

__m128 test_load(const A &a)
{
    return _mm_load_ps(a.data);
}

void test_store(A &a, __m128 v)
{
    _mm_store_ps(a.data, v);
}

This is also undefined behavior, and should I use the add-on instead?

In any case, since Intel intrinsics is not standard C ++, does it have access to a partially distributed but aligned memory block (no more than the alignment size) undefined behavior in standard C ++?

I refer to both the internal case and the C ++ standard. I'm interested in both of them.

+4
2

. x86 x64? .

UB ISO ++, , , , (.. asm, ), , Intel intrinsics ( , ). asm, , ++, UB , , , . .


. , , : / , .

, , , , , . 3 float, 16B-, 4B. ( alignas , ).


3 float , 2 floats.

( 2 ) MOVSD 64- , MOVSD MOVLPS - 64- __m128.

+3

- " ". _mm_load_ps , ASM, . C++ .

- ++ , undefined. , .

0

Source: https://habr.com/ru/post/1663788/


All Articles