Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc vector extensions don't work as stated in docs

As per Using vector instructions through built-in functions, this program should compile:

int main(){
    double v_sse __attribute__ ((vector_size (16)));

    /*
     * Should work: "For the convenience in C it is allowed to use a binary vector operation where one operand is a scalar."
     */
    v_sse=v_sse+3.4;

    /*
     * Should work: "Vectors can be subscripted as if the vector were an array with the same number of elements and base type."
     */
    double result=v_sse[0];
}

Instead I get errors at both operations, complaining about invalid operand/types.

I compile on a x86-64 system, so -msse2 is implicit, and my compiler is 4.6.3 (tested also with 4.7.0, it doesn't work). Where's the catch?

like image 869
Lorenzo Pistone Avatar asked Sep 11 '25 19:09

Lorenzo Pistone


1 Answers

The documentation at http://gcc.gnu.org/onlinedocs/gcc/ refers to current development.

Look at http://gcc.gnu.org/onlinedocs/gcc-X.Y.Z/ to find the documentation for the version you're using (see the index at http://gcc.gnu.org/onlinedocs/ for links to the docs for the most recent point release of each series).

In this case:

  • the binary operator functionality is not documented for 4.6.3 - because it was introduced as a new feature in 4.7: see the 4.7 release notes;
  • the subscript feature is present in 4.6.3; and
  • both features are specifically documented as working "in C"

...which explains what you're seeing.

Both of these do work with 4.7.0 when compiling as C -- but not when compiling as C++.

like image 196
Matthew Slattery Avatar answered Sep 13 '25 09:09

Matthew Slattery