Debian Codegraph @

examples/fnv1a/asm.go

raw symbols SCIP
1 //go:build ignore
2
3 package main
4
5 import (
6 . "github.com/mmcloughlin/avo/build"
7 . "github.com/mmcloughlin/avo/operand"
8 . "github.com/mmcloughlin/avo/reg"
9 )
10
11 const (
12 OffsetBasis = 0xcbf29ce484222325
13 Prime = 0x100000001b3
14 )
15
16 func main() {
17 TEXT("Hash64", NOSPLIT, "func(data []byte) uint64")
18 Doc("Hash64 computes the FNV-1a hash of data.")
19 ptr := Load(Param("data").Base(), GP64())
20 n := Load(Param("data").Len(), GP64())
21
22 h := RAX
23 MOVQ(Imm(OffsetBasis), h)
24 p := GP64()
25 MOVQ(Imm(Prime), p)
26
27 Label("loop")
28 CMPQ(n, Imm(0))
29 JE(LabelRef("done"))
30 b := GP64()
31 MOVBQZX(Mem{Base: ptr}, b)
32 XORQ(b, h)
33 MULQ(p)
34 INCQ(ptr)
35 DECQ(n)
36
37 JMP(LabelRef("loop"))
38 Label("done")
39 Store(h, ReturnIndex(0))
40 RET()
41 Generate()
42 }