2021-10-29 01:18:34 -07:00
|
|
|
//go:build ignore
|
2018-12-13 00:18:44 -08:00
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
. "github.com/mmcloughlin/avo/build"
|
2019-01-05 17:41:07 -08:00
|
|
|
. "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() {
|
2019-01-06 20:04:51 -08:00
|
|
|
TEXT("Hash64", NOSPLIT, "func(data []byte) uint64")
|
2018-12-27 23:09:44 -08:00
|
|
|
Doc("Hash64 computes the FNV-1a hash of data.")
|
2019-01-04 18:23:44 -08:00
|
|
|
ptr := Load(Param("data").Base(), GP64())
|
|
|
|
|
n := Load(Param("data").Len(), GP64())
|
2018-12-13 00:18:44 -08:00
|
|
|
|
2019-01-05 17:41:07 -08:00
|
|
|
h := RAX
|
|
|
|
|
MOVQ(Imm(OffsetBasis), h)
|
2019-01-04 18:23:44 -08:00
|
|
|
p := GP64()
|
2019-01-05 17:41:07 -08:00
|
|
|
MOVQ(Imm(Prime), p)
|
2018-12-13 00:18:44 -08:00
|
|
|
|
2019-01-05 18:18:49 -08:00
|
|
|
Label("loop")
|
2019-01-05 17:41:07 -08:00
|
|
|
CMPQ(n, Imm(0))
|
|
|
|
|
JE(LabelRef("done"))
|
2019-01-04 18:23:44 -08:00
|
|
|
b := GP64()
|
2019-01-05 17:41:07 -08:00
|
|
|
MOVBQZX(Mem{Base: ptr}, b)
|
2018-12-13 00:18:44 -08:00
|
|
|
XORQ(b, h)
|
|
|
|
|
MULQ(p)
|
|
|
|
|
INCQ(ptr)
|
|
|
|
|
DECQ(n)
|
|
|
|
|
|
2019-01-05 17:41:07 -08:00
|
|
|
JMP(LabelRef("loop"))
|
2019-01-05 18:18:49 -08:00
|
|
|
Label("done")
|
2018-12-13 00:18:44 -08:00
|
|
|
Store(h, ReturnIndex(0))
|
|
|
|
|
RET()
|
|
|
|
|
Generate()
|
|
|
|
|
}
|