Currently the 'swizzle' accessors .even/.odd/.lo/.hi return a scalar
instead of a vector with a single element when the result has a single
element. The current behavior of Clang can lead to unexpected failures
when working with ext_vector_types in templates that paramterize the
number of elements.
In the example below, currently c.even returns a scalar, which is then
converted to char and broadcasted to both elements of b.
typedef uint16_t __attribute__ ((__ext_vector_type__(2))) ushort2; typedef uint8_t __attribute__ ((__ext_vector_type__(2))) uchar2; ushort2 c = 0x0102; uchar2 b = (uchar2) c.even;
This patch changes the behavior so that swizzels return single element
vectors in that case. This should make the behavior consistent with
vectors with more than 1 element.
Just from looking at the implementation, it seems like the current
behavior is mostly a side-effect of the implementation, where the
handling of element accesses and swizzels is combined.
This patch changes existing behavior and may break some code that relies
on the current behavior. Unfortunately I could not find any
specification for the ext_vector_type so it is hard to tell if the
existing behavior is actually intentional or not. At least there are no
unit tests for the current behavior.