sse - _mm_srli_si128 equivalent on altivec -
i porting program written in sse 4.2 altivec. have problem in finding equivalent intrinsic _mm_srli_si128
.
when googled found vec_slo
equivalent.
here sample program shifting contents 1 byte left:
void test(void *buf, void *buf1) { vector unsigned int x; vector unsigned int a; x = vec_ld(0, (vector unsigned int *)buf); = vec_ld(0, (vector unsigned int *)buf1); vec_slo(x, a); } int main() { char buf[17]="1111111111111111"; char buf1[17]="0000000000000001"; test(buf, buf1); }
when compile following error:
line 20.1: 1506-930 (s) function "vec_slo" not type-generic macro.
the second argument vec_slo
needs vector signed char
or vector unsigned char
. change:
vector unsigned int a;
to:
vector unsigned char a;
and change:
a = vec_ld(0, (vector unsigned int *)buf1);
to:
a = vec_ld(0, (vector unsigned char *)buf1);
there couple of other problems code you'll see when compile , run:
buf
,buf1
need 16 byte aligned- the value shift in
buf1
needs 4 bit literal integer shifted left 3 bits, not character
here simplified/corrected version of example code - it's written gcc may need minor changes whatever compiler using (xlc ?):
int main(void) { vector unsigned char v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; vector unsigned char vshift = vec_splat_u8(1 << 3); // shift left 1 byte vector unsigned char vshifted = vec_slo(v, vshift); printf("v = %vu\n", v); printf("vshift = %vu\n", vshift); printf("vshifted = %vu\n", vshifted); return 0; }
Comments
Post a Comment