paolo_losi
paolo_losi

Reputation: 383

how is it possible to get gccgo produce vectorized code?

I'm trying to convince gccgo without success to vectorize the following snippet:

package foo

func Sum(v []float32) float32 {
    var sum float32 = 0
    for _, x := range v {
        sum += x
    }
    return sum
} 

I'm verifying the assembly generated by:

$ gccgo -O3 -ffast-math -march=native -S test.go

gccgo version is:

$ gccgo --version
gccgo (Ubuntu 4.9-20140406-0ubuntu1) 4.9.0 20140405 (experimental) [trunk revision 209157]

Isn't gccgo supposed to be able to vectorize this code? the equivalent C code with the same gcc options is perfectly vectorized with AVX instructions...

UPDATE

here you have the corresponding C example:

#include <stdlib.h>

float sum(float *v, size_t n) {
    size_t i;
    float sum = 0;
    for(i = 0; i < n; i++) {
        sum += v[i];
    }
    return sum;
}

compile with:

$ gcc -O3 -ffast-math -march=native -S test.c

Upvotes: 20

Views: 753

Answers (1)

Y_Yen
Y_Yen

Reputation: 189

Why not just build the .so or .a with gcc and call the c function from go?

Upvotes: 1

Related Questions