2018-12-11 23:02:50 -08:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
. "github.com/mmcloughlin/avo/build"
|
2019-01-05 17:41:07 -08:00
|
|
|
. "github.com/mmcloughlin/avo/operand"
|
2018-12-11 23:02:50 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
TEXT("Sum", "func(xs []uint64) uint64")
|
2018-12-27 23:09:44 -08:00
|
|
|
Doc("Sum returns the sum of the elements in xs.")
|
2019-01-04 18:23:44 -08:00
|
|
|
ptr := Load(Param("xs").Base(), GP64())
|
|
|
|
|
n := Load(Param("xs").Len(), GP64())
|
|
|
|
|
s := GP64()
|
2018-12-11 23:02:50 -08:00
|
|
|
XORQ(s, s)
|
|
|
|
|
LABEL("loop")
|
2019-01-05 17:41:07 -08:00
|
|
|
CMPQ(n, Imm(0))
|
|
|
|
|
JE(LabelRef("done"))
|
|
|
|
|
ADDQ(Mem{Base: ptr}, s)
|
|
|
|
|
ADDQ(Imm(8), ptr)
|
2018-12-11 23:02:50 -08:00
|
|
|
DECQ(n)
|
2019-01-05 17:41:07 -08:00
|
|
|
JMP(LabelRef("loop"))
|
2018-12-11 23:02:50 -08:00
|
|
|
LABEL("done")
|
|
|
|
|
Store(s, ReturnIndex(0))
|
|
|
|
|
RET()
|
|
|
|
|
Generate()
|
|
|
|
|
}
|