我正在尝试在我的C程序中使用SIMD指令。我正在使用CodeBlocks进行写入。
我正在尝试做整数和浮点SIMD加法、减法等。
但是,页面中解释的代码在CodeBlocks/C中不起作用。我如何在这里使用SIMD?
#include <stdio.h>
typedef int v4sf __attribute__ ((mode(V4SF))); // vector of four single floats
union f4vector
{
v4sf v;
float f[4];
};
int main()
{
union f4vector a, b, c;
a.f[0] = 1; a.f[1] = 2; a.f[2] = 3; a.f[3] = 4;
b.f[0] = 5; b.f[1] = 6; b.f[2] = 7; b.f[3] = 8;
c.v = a.v + b.v;
printf("%f, %f, %f, %f\n", c.f[0], c.f[1], c.f[2], c.f[3]);
}C:\Things\New Text Document.c|2|warning: specifying vector types with __attribute__ ((mode)) is deprecated [-Wattributes]|
C:\Things\New Text Document.c|2|warning: use __attribute__ ((vector_size)) instead [-Wattributes]|
C:\Things\New Text Document.c|2|error: mode 'V4SF' applied to inappropriate type|
||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|发布于 2014-09-27 03:08:57
您尝试使用的教程是用于Cell CPU的SIMD编程(即,在PlayStation3中)。它不适用于x86编程。
使用适用于您正在使用的编译器(GCC、Clang或Visual C++)的教程。
https://stackoverflow.com/questions/26065980
复制相似问题