I am trying to write SIMD mainly for educational purposes. I know that Go can bind an assembly, but I cannot get it to work correctly.
Here is the most minimal example I can do (multiplication by elementary vectors):
vec_amd64.s (note: the actual file has a space bar under RET , as it causes errors otherwise)
// func mul(v1, v2 Vec4) Vec4 TEXT .mul(SB),4,$0-48 MOVUPS v1+0(FP), X0 MOVUPS v2+16(FP), X1 MULPS X1, X0 // also tried ret+32 since I've seen some places do that MOVUPS X0, toReturn+32(FP) RET
vec.go
package simd type Vec4 [4]float32 func (v1 Vec4) Mul(v2 Vec4) Vec4 { return Vec4{v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2], v1[3] * v2[3]} } func mul(v1, v2 Vec4) Vec4
simd_test.go
package simd import ( "testing" ) func TestMul(t *testing.T) { v1 := Vec4{1, 2, 3, 4} v2 := Vec4{5, 6, 7, 8} res := v1.Mul(v2) res2 := mul(v1, v2) // Placeholder until I get it to compile if res != res2 { t.Fatalf("Expected %v; got %v", res, res2) } }
When I try to run go test , I get an error:
# testmain simd.TestMul: call to external function simd.mul simd.TestMul: undefined: simd.mul
The go env command tells my GOHOSTARCH as amd64 , and my version of Go is 1.3. To confirm that this is not an architecture issue, I found another package that uses assembly and deletes all assembly files except _amd64.s , and its tests went fine.
I also tried changing it to an exported identifier in case it was weird but not dice. I think I followed the template pretty closely in packages like math/big , so hopefully it is simple and clear that I am missing.
I know that Go is no less trying to use assembly, because if I introduce a syntax error into the .s file, the build tool will complain about it.
Edit:
To be clear, go build will compile cleanly, but go test raises an error.