我试着写一些 SIMD,主要用于学习目的。我知道 Go 可以链接程序集,但我不能让它正常工作。+ ?- D0 i1 K8 h
这是我能做的最简单的例子(逐元素向量乘法): ' d. X7 i3 `6 y6 u) j% Z' uvec_amd64.s(注:实际文件下有一条空白线,RET否则会导致错误)0 H1 |' s7 B v2 ]# X
// func mul(v1,v2 Vec4) Vec4TEXT .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 $ z6 _; J$ H0 |& X2 R; L" i
package simdimport "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) }code]当我试着操作的时候go test出现错误:[code]# testmainsimd.TestMul: call to external function simd.mulsimd.TestMul: undefined: simd.mul5 g9 f5 F* S% P- t! x7 a) C; t