expand test cases and make sum_tail2 more efficient
MODIFY
internal/asm/f32/stubs_test.go
internal/asm/f32/stubs_test.go
@@ -198,7 +198,8 @@ func TestSum(t *testing.T) {
expect: 67,
},
} {
- gdLn := 4 + j%2
+ for _, i := range [4]int{0, 1, 2, 3} {
+ gdLn := 4 + j%4 + i
gsrc := guardVector(v.src, srcGd, gdLn)
src := gsrc[gdLn : len(gsrc)-gdLn]
ret := Sum(src)
@@ -210,3 +211,4 @@ func TestSum(t *testing.T) {
}
}
}
+}

MODIFY
internal/asm/f32/sum_amd64.s
internal/asm/f32/sum_amd64.s
@@ -79,17 +79,17 @@ sum_tail4:
sum_tail2:
HADDPS SUM, SUM // sum_i[:2] += sum_i[2:4]
- HADDPS SUM, SUM // sum_i[0] += sum_i[1]
TESTQ $2, TAIL
JZ sum_tail1
- ADDSS (X_PTR)(IDX*4), SUM // sum_i += x[i:i+1]
- ADDQ $1, IDX
- ADDSS (X_PTR)(IDX*4), SUM // sum_i += x[i:i+1]
- ADDQ $1, IDX
+ MOVSD (X_PTR)(IDX*4), SUM_1 // reuse SUM_1
+ ADDPS SUM_1, SUM // sum_i += x[i:i+2]
+ ADDQ $2, IDX
sum_tail1:
+ HADDPS SUM, SUM // sum_i[0] += sum_i[1]
+
TESTQ $1, TAIL
JZ sum_end

expand test cases and make sum_tail2 more efficient