examples/complex: and bugfixes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user