add fnv1a example

This commit is contained in:
Michael McLoughlin
2018-12-13 00:18:44 -08:00
parent b89d211ff4
commit 93b53377ac
8 changed files with 124 additions and 14 deletions

41
examples/fnv1a/asm.go Normal file
View File

@@ -0,0 +1,41 @@
// +build ignore
package main
import (
. "github.com/mmcloughlin/avo/build"
"github.com/mmcloughlin/avo/operand"
"github.com/mmcloughlin/avo/reg"
)
const (
OffsetBasis = 0xcbf29ce484222325
Prime = 0x100000001b3
)
func main() {
TEXT("Hash64", "func(data []byte) uint64")
ptr := Load(Param("data").Base(), GP64v())
n := Load(Param("data").Len(), GP64v())
h := reg.RAX
MOVQ(operand.Imm(OffsetBasis), h)
p := GP64v()
MOVQ(operand.Imm(Prime), p)
LABEL("loop")
CMPQ(n, operand.Imm(0))
JE(operand.LabelRef("done"))
b := GP64v()
MOVBQZX(operand.Mem{Base: ptr}, b)
XORQ(b, h)
MULQ(p)
INCQ(ptr)
DECQ(n)
JMP(operand.LabelRef("loop"))
LABEL("done")
Store(h, ReturnIndex(0))
RET()
Generate()
}