Skip to content

Commit

Permalink
examples: simplify FNV1A loop
Browse files Browse the repository at this point in the history
  • Loading branch information
SaveTheRbtz committed Apr 7, 2022
1 parent 72b8db9 commit 740992a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions examples/fnv1a/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ func main() {
TEXT("Hash64", NOSPLIT, "func(data []byte) uint64")
Doc("Hash64 computes the FNV-1a hash of data.")
ptr := Load(Param("data").Base(), GP64())
n := Load(Param("data").Len(), GP64())
endPtr := Load(Param("data").Len(), GP64())
ADDQ(ptr, endPtr)

h := RAX
MOVQ(Imm(OffsetBasis), h)
p := GP64()
MOVQ(Imm(Prime), p)

Label("loop")
CMPQ(n, Imm(0))
CMPQ(ptr, endPtr)
JE(LabelRef("done"))
b := GP64()
MOVBQZX(Mem{Base: ptr}, b)
XORQ(b, h)
MULQ(p)
INCQ(ptr)
DECQ(n)

JMP(LabelRef("loop"))
Label("done")
Expand Down
6 changes: 3 additions & 3 deletions examples/fnv1a/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ func main() {
TEXT("Hash64", NOSPLIT, "func(data []byte) uint64")
Doc("Hash64 computes the FNV-1a hash of data.")
ptr := Load(Param("data").Base(), GP64())
n := Load(Param("data").Len(), GP64())
endPtr := Load(Param("data").Len(), GP64())
ADDQ(ptr, endPtr)

h := RAX
MOVQ(Imm(OffsetBasis), h)
p := GP64()
MOVQ(Imm(Prime), p)

Label("loop")
CMPQ(n, Imm(0))
CMPQ(ptr, endPtr)
JE(LabelRef("done"))
b := GP64()
MOVBQZX(Mem{Base: ptr}, b)
XORQ(b, h)
MULQ(p)
INCQ(ptr)
DECQ(n)

JMP(LabelRef("loop"))
Label("done")
Expand Down
4 changes: 2 additions & 2 deletions examples/fnv1a/fnv1a.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
TEXT ·Hash64(SB), NOSPLIT, $0-32
MOVQ data_base+0(FP), CX
MOVQ data_len+8(FP), BX
ADDQ CX, BX
MOVQ $0xcbf29ce484222325, AX
MOVQ $0x00000100000001b3, SI

loop:
CMPQ BX, $0x00
CMPQ CX, BX
JE done
MOVBQZX (CX), DX
XORQ DX, AX
MULQ SI
INCQ CX
DECQ BX
JMP loop

done:
Expand Down

0 comments on commit 740992a

Please sign in to comment.