Invalid 'asm': alternate set alternatives

I am trying to write inline assembler code with KNC instructions for the Xeon Phi platform using a compiler k1om-mpss-linux-gcc. I want to use mask case in my code to vectorize my calculations. Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <assert.h>
#include <stdint.h>

void* aligned_malloc(size_t size, size_t alignment) {

    uintptr_t r = (uintptr_t)malloc(size + --alignment + sizeof(uintptr_t));
    uintptr_t t = r + sizeof(uintptr_t);
    uintptr_t o =(t + alignment) & ~(uintptr_t)alignment;
    if (!r) return NULL;
    ((uintptr_t*)o)[-1] = r;
    return (void*)o;
}

int main(int argc, char* argv[])
{
    const int vectorSize = 16;
    int * n_arr = (int *) aligned_malloc(16 * sizeof(int),64);
    int * lenS_arr = (int *) aligned_malloc(16 * sizeof(int),64);
    int * tt_i = (int *) aligned_malloc(16 * sizeof(int),64);
    int * tt = (int *) aligned_malloc(16 * sizeof(int),64);
    int n = 5;
    int lenS = 16;
    int i;

    for(i=0; i< 16; i++){
        tt_i[i] = 1;
        n_arr[i] = n;
        lenS_arr[i] = lenS;
    }
    __asm__("vmovdqa32 %1,%%zmm0\n\t"
            "vmovdqa32 %2,%%zmm1\n\t"
            "vmovdqa32 %3,%%zmm2\n\t"
            "vpaddd %%zmm0,%%zmm1,%%zmm0\n\t"
            "vpcmpgtd %%zmm0,%%zmm2,%%k1\n\t"
            "vpsubd %%zmm2,%%zmm0,%%zmm0 {{%%k1}}\n\t"
            "vmovdqa32 %%zmm1,%0;"
            : "=m" (tt[0]) : "m" (tt_i[0]), "m" (n_arr[0]), "m" (lenS_arr[0]));
    for (i=0; i <16 ; i++)
    {
        printf("tt_i[%d] = %d --- tt[%d] = %d\n",i, tt_i[i], i, tt[i]);
    }

    return 0;
}

And when I compile the code, I have this error:

error: invalid 'asm': nested assembly dialect alternatives

What is connected with this conveyor line:

"vpsubd %%zmm2,%%zmm0,%%zmm0 {{%%k1}}\n\t"

Any thoughts on this error?

+4
source share
1 answer

Try using %{%%k1%}inline asm to get {%k1}asm into the actual output. {and } must be shielded .


: nested assembly dialect alternatives asm, testcase.

{} GNU C inline asm : ASM.

{{%%k1}} gcc , .

:

int main (void) {
  int f = 0;
  asm ("{movl $42, %%eax | mov eax, 42}" : :);
  asm ("{movl $41, %0||mov %0, 43}" : "=r"(f));
  if (f != 42)
    abort ();

  return 0;
}
+5

Source: https://habr.com/ru/post/1620487/


All Articles