Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembler version of Sum64String #42

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ go:
- master
env:
- TAGS=""
- TAGS="-tags appengine"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we really care about special appengine support these days. I filed #46.

- TAGS="-tags purego"
script: go test $TAGS -v ./...
11 changes: 11 additions & 0 deletions sum64string_unsafe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !amd64 !appengine,purego

package xxhash

// Sum64String computes the 64-bit xxHash digest of s.
// It may be faster than Sum64([]byte(s)) by avoiding a copy.
func Sum64String(s string) uint64 {
// Forward to the version in xxhash_unsafe.go.
// Go 1.15 inlines this function.
return sum64String(s)
}
6 changes: 6 additions & 0 deletions xxhash_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ package xxhash
//go:noescape
func Sum64(b []byte) uint64

// Sum64String computes the 64-bit xxHash digest of s.
// It may be faster than Sum64([]byte(s)) by avoiding a copy.
//
//go:noescape
func Sum64String(s string) uint64

//go:noescape
func writeBlocks(d *Digest, b []byte) int
20 changes: 16 additions & 4 deletions xxhash_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// CX pointer to advance through b
// DX n
// BX loop end
// DI pointer to return value storage
// R8 v1, k1
// R9 v2
// R10 v3
Expand Down Expand Up @@ -40,14 +41,25 @@

// func Sum64(b []byte) uint64
TEXT ·Sum64(SB), NOSPLIT, $0-32
MOVQ b_base+0(FP), CX
MOVQ b_len+8(FP), DX
LEAQ ret+24(FP), DI
JMP sum64<>(SB)

// func Sum64String(s string) uint64
TEXT ·Sum64String(SB), NOSPLIT, $0-24
MOVQ s_base+0(FP), CX
MOVQ s_len+8(FP), DX
LEAQ ret+16(FP), DI
JMP sum64<>(SB)

// Takes arguments in CX, DX. Stores its return value through DI.
TEXT sum64<>(SB), NOFRAME+NOSPLIT, $0
// Load fixed primes.
MOVQ ·prime1v(SB), R13
MOVQ ·prime2v(SB), R14
MOVQ ·prime4v(SB), R15

// Load slice.
MOVQ b_base+0(FP), CX
MOVQ b_len+8(FP), DX
LEAQ (CX)(DX*1), BX

// The first loop limit will be len(b)-32.
Expand Down Expand Up @@ -166,7 +178,7 @@ finalize:
SHRQ $32, R12
XORQ R12, AX

MOVQ AX, ret+24(FP)
MOVQ AX, (DI)
RET

// writeBlocks uses the same registers as above except that it uses AX to store
Expand Down
4 changes: 1 addition & 3 deletions xxhash_unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import (
// for strings to squeeze out a bit more speed. Mid-stack inlining should
// eventually fix this.

// Sum64String computes the 64-bit xxHash digest of s.
// It may be faster than Sum64([]byte(s)) by avoiding a copy.
func Sum64String(s string) uint64 {
func sum64String(s string) uint64 {
var b []byte
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
Expand Down