我看到如下代码:
#include "stdio.h"
#define VECTOR_SIZE 4
typedef float v4sf __attribute__ ((vector_size(sizeof(float)*VECTOR_SIZE)));
// vector of four single floats
typedef union f4vector
{
v4sf v;
float f[VECTOR_SIZE];
} f4vector;
void print_vector (f4vector *v)
{
printf("%f,%f,%f,%f\n", v->f[0], v->f[1], v->f[2], v->f[3]);
}
int main()
{
union f4vector a, b, c;
a.v = (v4sf){1.2, 2.3, 3.4, 4.5};
b.v = (v4sf){5., 6., 7., 8.};
c.v = a.v + b.v;
print_vector(&a);
print_vector(&b);
print_vector(&c);
}
Run Code Online (Sandbox Code Playgroud)
这段代码构建良好,并且预期使用gcc(它是内置的SSE/MMX扩展和向量数据类型.这段代码使用4个单浮点进行SIMD向量加法.
我想详细了解每个关键字/函数调用此typedef行的含义和含义:
typedef float v4sf __attribute__ ((vector_size(sizeof(float)*VECTOR_SIZE)));
Run Code Online (Sandbox Code Playgroud)
什么是vector_size()函数返回;
__attribute__关键字是什么?
这是浮点数据类型是为vfsf类型定义的类型?
我理解其余部分.
谢谢,
-广告
__attribute__GCC是一种从不符合C或C++标准的编译器中公开功能的方法.
__attribute__((vector_size(x)))指示GCC将类型视为大小为x的向量.对于SSE,这是16个字节.
但是,我建议使用各种<*mmintrin.h>标头中的__m128,__ m128i或__m128d类型.它们在编译器之间更具可移植性.
| 归档时间: |
|
| 查看次数: |
3818 次 |
| 最近记录: |