我有一个简单的SIMD程序用于矢量添加
/*
* FILE: vec_add.c
*/
#include <stdio.h>
#include <altivec.h>
/*
* declares input/output scalar varialbes
*/
int a[4] __attribute__((aligned(16))) = { 1, 3, 5, 7 };
int b[4] __attribute__((aligned(16))) = { 2, 4, 6, 8 };
int c[4] __attribute__((aligned(16)));
int main(int argc, char **argv)
{
/*
* declares vector variables which points to scalar arrays
*/
__vector signed int *va = (__vector signed int *) a;
__vector signed int *vb = (__vector signed int *) b;
__vector signed int *vc = (__vector signed int *) c;
/*
* adds four signed intergers at once
*/
*vc = vec_add(*va, *vb); // 1 + 2, 3 + 4, 5 + 6, 7 + 8
/*
* output results
*/
printf("c[0]=%d, c[1]=%d, c[2]=%d, c[3]=%d\n", c[0], c[1], c[2], c[3]);
return 0;
}
我正在尝试使用Makefile在这里编译这个程序
CC = gcc
CFLAGS = -maltivec -mabi=altivec
SOURCE = vec_add.c
TARGET = vec_add.elf
$(TARGET): $(SOURCE)
$(CC) $(CFLAGS) $^ -o $@
clean:
rm -f *.elf
编译程序时..我收到以下错误
pp@pa-Inspiron-N5050:~/Desktop/Proj/SIMD$ make
gcc -maltivec -mabi=altivec vec_add.c -o vec_add.elf
gcc: error: unrecognized argument in option ‘-mabi=altivec’
gcc: note: valid arguments to ‘-mabi=’ are: ms sysv
gcc: error: unrecognized command line option ‘-maltivec’
make: *** [vec_add.elf] Error 1
简单编译而不使用Makefile。我正在
SIMD$ gcc vec_add.c
vec_add.c:5:21: fatal error: altivec.h: No such file or directory
#include <altivec.h>
^
compilation terminated.
所以,我下载了altivec.h文件并把它放在文件夹中,但它仍然给出了同样的错误。
我不明白使用-maltivec选项有什么问题。还有其他一些编译方法吗?
答案 0 :(得分:3)
您的程序是为PowerPC Altivec(aka VMX)SIMD扩展编写的,而您的编译器是针对x86编写的。您应该使用PowerPC交叉编译器或重写x86 SIMD扩展(SSE或AVX)的代码。