https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127025

--- Comment #2 from Jeevitha <jeevitha at gcc dot gnu.org> ---
vec_insertl:

vec_insertl compiles to a different instruction depending on endianness:

r = vec_insertl (a, b, c)

Purpose: Insert a source element into a source vector at a specified byte
position in natural byte
order.

Result value: When a is a scalar, let e be equal to a. Otherwise, when a is a
vector, let e be the rightmost element of the leftmost doubleword of a in
register order. Then the result r is set to the value of b with e inserted at
byte position c in natural byte order. Other than the bytes modified by the
insert operation, bytes of r are identical to the corresponding bytes of b.

Endian considerations: The byte and element numbering within a register is
left-to-right for big-endian targets, and right-to-left for little-endian
targets. Note that this operation is not semantically equivalent for big- and
little-endian targets when a is a vector, because the element chosen for
insertion is at the same location in the vector, regardless of target
endianness.


For char
BE: vinsbvlx r/b,c,a | LE: vinsbvrx

Both instructions do the same two things — pull one byte out of a at bits
56:63, then write it into r at a byte position chosen by the index in the c.

consider below example:

    src_va_ch = (vector unsigned char) { 0, 1, 2, 3, 4, 5, 6, 7,
                                       8, 9, 10, 11, 12, 13, 14, 15 };
    src_vb_ch = (vector unsigned char) { 10, 11, 12, 13, 14, 15, 16, 17,
                                       18, 19, 20, 21, 22, 23, 24, 25 };
    expected_vresult_ch = (vector unsigned char) { 0, 1, 18, 3, 4, 5, 6, 7,
                                       8, 9, 10, 11, 12, 13, 14, 15 };

     vresult_ch = vec_insertl (src_vb_ch, src_va_ch, index);

BE case:
vinsbvlx v0,r9,v1
src_vb_ch -> v1

$v1 (BE) uint128 = 0xa0b0c0d0e0f10111213141516171819 ; v16_int8 =
{0xa,0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19}

so bit[56:63]---> 0x11 [This is the value to be inserted]

LE case:
vinsbvrx v0,r2,v1
src_vb_ch -> v1

$v1 (LE) uint128 = 0x191817161514131211100f0e0d0c0b0a
v16_int8={0xa,0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19}

so bit[56:63] ---> 0x12 [This is the value to be inserted]

Note: So for both LE/BE has different value for insertion but index to be
inserted is same

Reply via email to