我有一个用于向量加法的简单 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 选项有什么问题。还有其他编译方法吗?