Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 570
paolo_losi Avatar asked May 09 '14 17:05

paolo_losi


Video Answer


1 Answers

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

like image 120
Y_Yen Avatar answered Oct 15 '22 01:10

Y_Yen