csimdssepowerpcaltivec

_mm_srli_si128 equivalent on altivec


I am porting a program written in SSE 4.2 to Altivec. I have a problem in finding the equivalent for the intrinsic _mm_srli_si128.

When I googled I found vec_slo as the equivalent.

Here is my sample program for shifting the contents by 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);
    a = 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 I compile I get the following error:

line 20.1: 1506-930 (S) The function "vec_slo" is not a type-generic macro.

Solution

  • The second argument for vec_slo needs to be vector signed char or vector unsigned char. So 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 are a couple of other problems with your code which you'll see when you get it compile and run:

    Here is a simplified/corrected version of your example code - it's written for gcc so may need minor changes for whatever compiler you are 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 by 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;
    }