我正在测试pcmpistr指令,这是SSE中的strchr()等价物,但是我得到了返回值的错误,由于某种原因,编译器认为' int'类型变量' idx'是一个向量,但它是一个标量,它应该存储在字符串中找到的字符的索引。这有什么问题?
[niko@dev1 test]$ cat pcmpistr.c
#include <nmmintrin.h>
#include <stdio.h>
int main(int argc,char **argv) {
int idx;
char str1[16] __attribute__ ((aligned (16))) ={'G','E','T',' ','/','i','n','d','e','x','.','h','t','m','l','\n'} ;
char str2[1] __attribute__ ((aligned (16))) ={'\n'};
__m128i *a,*b;
a=(__m128i*) str1;
b=(__m128i*) str2;
idx=_mm_cmpestri (a, 16, b, 1, _SIDD_UBYTE_OPS |_SIDD_CMP_EQUAL_ANY|_SIDD_LEAST_SIGNIFICANT);
printf("idx=%d\n",idx);
}
[niko@dev1 test]$ gcc -o pcmpstr pcmpistr.c
pcmpistr.c: In function ‘main’:
pcmpistr.c:13:2: error: can’t convert value to a vector
idx=_mm_cmpestri (a, 16, b, 1, _SIDD_UBYTE_OPS |_SIDD_CMP_EQUAL_ANY|_SIDD_LEAST_SIGNIFICANT);
^
pcmpistr.c:13:2: error: can’t convert value to a vector
[niko@dev1 test]$
答案 0 :(得分:1)
@FUZxxl是对的,函数的签名如下:
int _mm_cmpestri (
__m128i a,
int la,
__m128i b,
int lb,
const int mode
);
因此,您需要将a和b取消引用为:
idx=_mm_cmpestri (*a, 16, *b, 1, _SIDD_UBYTE_OPS |_SIDD_CMP_EQUAL_ANY|_SIDD_LEAST_SIGNIFICANT);