c++ - SIMD程序编译问题

标签 c++ c makefile simd altivec

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

最佳答案

您的程序是为 PowerPC Altivec(又名 VMX)SIMD 扩展编写的,您的编译器是为 x86 编写的。您应该使用 PowerPC 交叉编译器或为 x86 SIMD 扩展(SSE 或 AVX)重写代码。

关于c++ - SIMD程序编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31630444/

相关文章:

ubuntu - cmake:当我尝试通过终端安装 sfml 时包含不受支持的字符

c++ - 数组递归;无法获得正确的返回值

c - 递增指针时的不明确行为

c# - 使用 C# 的 C++ 项目

c - scanf() 格式字符串中的空白

c++ - 我如何检查 C++ 代码中的文件写入权限?

makefile - Makefile 中的 "heritage"

vim - 使用 Vim :make with quickfix ends up creating a new file when error is in header

c++ - 为什么有些人只说 "C+"而不是 C++?

c++ - 对 LibSerial 的 undefined reference