examples/complex: and bugfixes

This commit is contained in:
Michael McLoughlin
2018-12-12 00:02:22 -08:00
parent 2189d38d1e
commit b89d211ff4
12 changed files with 179 additions and 34 deletions

View File

@@ -4,15 +4,15 @@
// func Sum(xs []uint64) uint64
TEXT ·Sum(SB),0,$0-32
MOVQ xs_base(FP), DX
MOVQ xs_len+8(FP), CX
XORQ AX, AX
MOVQ xs_len+8(FP), AX
XORQ CX, CX
loop:
CMPQ CX, $0x0
CMPQ AX, $0x0
JE done
ADDQ (DX), AX
ADDQ (DX), CX
ADDQ $0x8, DX
DECQ CX
DECQ AX
JMP loop
done:
MOVQ AX, ret+24(FP)
MOVQ CX, ret+24(FP)
RET

View File

@@ -7,14 +7,15 @@ import (
//go:generate go run asm.go -out sum.s -stubs stub.go
func expect(xs []uint64) uint64 {
var s uint64
for _, x := range xs {
s += x
}
return s
}
func TestSum(t *testing.T) {
quick.CheckEqual(Sum, expect, nil)
expect := func(xs []uint64) uint64 {
var s uint64
for _, x := range xs {
s += x
}
return s
}
if err := quick.CheckEqual(Sum, expect, nil); err != nil {
t.Fatal(err)
}
}