Why short3 uses 8 bytes like short4?

With the new change, LLVM/Clang defines

typedef short short3 attribute((ext_vector_type(3)));

to be size of 8.

sizeof( short3 ) = 8

and for short3 array, one element takes 8 bytes.

&m[0] = 0xbed63b20

&m[1] = 0xbed63b28

&m[2] = 0xbed63b30

&m[3] = 0xbed63b38

I notice the older LLVM/Clang still allocate short3 to be 6 byte element.

Is there any historical reason to make 6 byte short3 to become 8 byte short4?

Is short3 supposed to be defined as three shorts in a row. It is a little difficult

to connect with other language like Java JNI.

Thanks,

Yin

Vector types are supposed to map to CPU vector types, so their size and alignment will be defined based on the smallest CPU vector that can fit the type.

Most CPUs only support a small number of power-of-two sized vectors and the alignment requirements for vectors are quite strict. In your example, if sizeof(short3) were 6 instead of 8 then &m[1] would be 0xbed63b26. This would then cause a problem when you tried to load it, because it would not be 8-byte aligned and so would fail.

David