繁体   English   中英

SIMD程序编译问题

[英]SIMD program compilation issue

我有一个简单的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(aka VMX)SIMD扩展编写的,而编译器则是针对x86的。 您应该使用PowerPC交叉编译器或为x86 SIMD扩展(SSE或AVX)重写代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM