Skip to content

Commit

Permalink
Start primes at 0
Browse files Browse the repository at this point in the history
  • Loading branch information
cespare committed Dec 2, 2022
1 parent 27bcde0 commit 34f9c9a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions xxhash.go
Expand Up @@ -20,7 +20,7 @@ const (
//
// The consts are used when possible in Go code to avoid MOVs but we need a
// contiguous array of the assembly code.
var primes = [...]uint64{0, prime1, prime2, prime3, prime4, prime5}
var primes = [...]uint64{prime1, prime2, prime3, prime4, prime5}

// Digest implements hash.Hash64.
type Digest struct {
Expand All @@ -42,10 +42,10 @@ func New() *Digest {

// Reset clears the Digest's state so that it can be reused.
func (d *Digest) Reset() {
d.v1 = primes[1] + prime2
d.v1 = primes[0] + prime2
d.v2 = prime2
d.v3 = 0
d.v4 = -primes[1]
d.v4 = -primes[0]
d.total = 0
d.n = 0
}
Expand Down
18 changes: 9 additions & 9 deletions xxhash_amd64.s
Expand Up @@ -71,17 +71,17 @@ loop: \
#define do1() \
MOVBQZX (p), tmp \
ADDQ $1, p \
IMULQ ·primes+40(SB), tmp \
IMULQ ·primes+32(SB), tmp \
XORQ tmp, h \
ROLQ $11, h \
IMULQ prime1, h \

// func Sum64(b []byte) uint64
TEXT ·Sum64(SB), NOSPLIT|NOFRAME, $0-32
// Load fixed primes.
MOVQ ·primes+8(SB), prime1
MOVQ ·primes+16(SB), prime2
MOVQ ·primes+32(SB), prime4
MOVQ ·primes+0(SB), prime1
MOVQ ·primes+8(SB), prime2
MOVQ ·primes+24(SB), prime4

// Load slice.
MOVQ b_base+0(FP), p
Expand Down Expand Up @@ -125,7 +125,7 @@ TEXT ·Sum64(SB), NOSPLIT|NOFRAME, $0-32
JMP afterBlocks

noBlocks:
MOVQ ·primes+40(SB), h
MOVQ ·primes+32(SB), h

afterBlocks:
ADDQ n, h
Expand Down Expand Up @@ -156,7 +156,7 @@ try4:

ROLQ $23, h
IMULQ prime2, h
ADDQ ·primes+24(SB), h
ADDQ ·primes+16(SB), h

try2:
ADDQ $2, end
Expand All @@ -181,7 +181,7 @@ finalize:
MOVQ h, tmp
SHRQ $29, tmp
XORQ tmp, h
IMULQ ·primes+24(SB), h
IMULQ ·primes+16(SB), h
MOVQ h, tmp
SHRQ $32, tmp
XORQ tmp, h
Expand All @@ -195,8 +195,8 @@ finalize:
// func writeBlocks(d *Digest, b []byte) int
TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40
// Load fixed primes needed for round.
MOVQ ·primes+8(SB), prime1
MOVQ ·primes+16(SB), prime2
MOVQ ·primes+0(SB), prime1
MOVQ ·primes+8(SB), prime2

// Load slice.
MOVQ b_base+8(FP), p
Expand Down
8 changes: 4 additions & 4 deletions xxhash_arm64.s
Expand Up @@ -60,9 +60,9 @@
TEXT ·Sum64(SB), NOSPLIT|NOFRAME, $0-32
LDP b_base+0(FP), (p, n)

LDP ·primes+8(SB), (prime1, prime2)
LDP ·primes+24(SB), (prime3, prime4)
MOVD ·primes+40(SB), prime5
LDP ·primes+0(SB), (prime1, prime2)
LDP ·primes+16(SB), (prime3, prime4)
MOVD ·primes+32(SB), prime5

CMP $32, n
CSEL LT, prime5, ZR, h // if n < 32 { h = prime5 } else { h = 0 }
Expand Down Expand Up @@ -162,7 +162,7 @@ finalize:

// func writeBlocks(d *Digest, b []byte) int
TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40
LDP ·primes+8(SB), (prime1, prime2)
LDP ·primes+0(SB), (prime1, prime2)

// Load state. Assume v[1-4] are stored contiguously.
MOVD d+0(FP), digest
Expand Down
4 changes: 2 additions & 2 deletions xxhash_other.go
Expand Up @@ -15,10 +15,10 @@ func Sum64(b []byte) uint64 {
var h uint64

if n >= 32 {
v1 := primes[1] + prime2
v1 := primes[0] + prime2
v2 := prime2
v3 := uint64(0)
v4 := -primes[1]
v4 := -primes[0]
for len(b) >= 32 {
v1 = round(v1, u64(b[0:8:len(b)]))
v2 = round(v2, u64(b[8:16:len(b)]))
Expand Down

0 comments on commit 34f9c9a

Please sign in to comment.