diff --git a/examples/fnv1a/README.md b/examples/fnv1a/README.md index c9948a3b..cb0e1ee2 100644 --- a/examples/fnv1a/README.md +++ b/examples/fnv1a/README.md @@ -13,7 +13,8 @@ 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) @@ -21,14 +22,13 @@ func main() { 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") diff --git a/examples/fnv1a/asm.go b/examples/fnv1a/asm.go index 809a1c95..474916a8 100644 --- a/examples/fnv1a/asm.go +++ b/examples/fnv1a/asm.go @@ -18,7 +18,8 @@ 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) @@ -26,14 +27,13 @@ func main() { 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") diff --git a/examples/fnv1a/fnv1a.s b/examples/fnv1a/fnv1a.s index 6628c374..1fe0942c 100644 --- a/examples/fnv1a/fnv1a.s +++ b/examples/fnv1a/fnv1a.s @@ -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: