Files
avo/examples/fnv1a/asm.go

43 lines
717 B
Go
Raw Normal View History

2018-12-13 00:18:44 -08:00
// +build ignore
package main
import (
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
. "github.com/mmcloughlin/avo/reg"
2018-12-13 00:18:44 -08:00
)
const (
OffsetBasis = 0xcbf29ce484222325
Prime = 0x100000001b3
)
func main() {
TEXT("Hash64", "func(data []byte) uint64")
2018-12-27 23:09:44 -08:00
Doc("Hash64 computes the FNV-1a hash of data.")
ptr := Load(Param("data").Base(), GP64())
n := Load(Param("data").Len(), GP64())
2018-12-13 00:18:44 -08:00
h := RAX
MOVQ(Imm(OffsetBasis), h)
p := GP64()
MOVQ(Imm(Prime), p)
2018-12-13 00:18:44 -08:00
Label("loop")
CMPQ(n, Imm(0))
JE(LabelRef("done"))
b := GP64()
MOVBQZX(Mem{Base: ptr}, b)
2018-12-13 00:18:44 -08:00
XORQ(b, h)
MULQ(p)
INCQ(ptr)
DECQ(n)
JMP(LabelRef("loop"))
Label("done")
2018-12-13 00:18:44 -08:00
Store(h, ReturnIndex(0))
RET()
Generate()
}