What is the meaning of the __attribute__ vector_si

2020-03-24 07:50发布

问题:

I got a C program were I saw the __attribute__ keyword for the 1st time. It seems like it is a GNU keyword. In GCC's this page, they explain its use with the (vector_size(16)) attribute, saying:

int foo __attribute__ ((vector_size (16)));

causes the compiler to set the mode for foo, to be 16 bytes, divided into int sized units. Assuming a 32-bit int (a vector of 4 units of 4 bytes), the corresponding mode of foo will be V4SI.

What does this mean? Is foo now declared as a 4-element array of ints? If so, what is wrong with just:

int foo[4];

?

回答1:

It's for use with SIMD vectorization. (No, it doesn't make foo an array.)

It's documented here.



回答2:

No, foo isn't be declared as an array. In this statement the int type specifies the base type, while the attribute specifies the vector size for the variable, measured in bytes.