Skip to content

Commit

Permalink
fix(xxhash3): support arm64 (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyunhao116 authored May 9, 2022
1 parent 79e6caf commit d1878f6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 17 deletions.
24 changes: 24 additions & 0 deletions util/xxhash3/accum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 ByteDance Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !amd64
// +build !amd64

package xxhash3

import "unsafe"

func accum(xacc *[8]uint64, xinput, xsecret unsafe.Pointer, l uintptr) {
accumScalar(xacc, xinput, xsecret, l)
}
30 changes: 30 additions & 0 deletions util/xxhash3/accum_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021 ByteDance Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package xxhash3

import "unsafe"

func accumAVX2(acc *[8]uint64, xinput, xsecret unsafe.Pointer, len uintptr)
func accumSSE2(acc *[8]uint64, xinput, xsecret unsafe.Pointer, len uintptr)

func accum(xacc *[8]uint64, xinput, xsecret unsafe.Pointer, l uintptr) {
if avx2 {
accumAVX2(xacc, xinput, xsecret, l)
} else if sse2 {
accumSSE2(xacc, xinput, xsecret, l)
} else {
accumScalar(xacc, xinput, xsecret, l)
}
}
File renamed without changes.
9 changes: 2 additions & 7 deletions util/xxhash3/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,8 @@ func xxh3HashLarge(xinput unsafe.Pointer, l int) (acc uint64) {

acc = uint64(length * prime64_1)

if avx2 {
accumAVX2(&xacc, xinput, xsecret, length)
} else if sse2 {
accumSSE2(&xacc, xinput, xsecret, length)
} else {
accumScalar(&xacc, xinput, xsecret, length)
}
accum(&xacc, xinput, xsecret, length)

//merge xacc
acc += mix(xacc[0]^xsecret_011, xacc[1]^xsecret_019)
acc += mix(xacc[2]^xsecret_027, xacc[3]^xsecret_035)
Expand Down
9 changes: 2 additions & 7 deletions util/xxhash3/hash128.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,8 @@ func xxh3HashLarge128(xinput unsafe.Pointer, l int) (acc [2]uint64) {
acc[1] = uint64(length * prime64_1)
acc[0] = uint64(^(length * prime64_2))

if avx2 {
accumAVX2(&xacc, xinput, xsecret, length)
} else if sse2 {
accumSSE2(&xacc, xinput, xsecret, length)
} else {
accumScalar(&xacc, xinput, xsecret, length)
}
accum(&xacc, xinput, xsecret, length)

// merge xacc
acc[1] += mix(xacc[0]^xsecret_011, xacc[1]^xsecret_019)
acc[1] += mix(xacc[2]^xsecret_027, xacc[3]^xsecret_035)
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions util/xxhash3/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"golang.org/x/sys/cpu"
)

func accumAVX2(acc *[8]uint64, xinput, xsecret unsafe.Pointer, len uintptr)
func accumSSE2(acc *[8]uint64, xinput, xsecret unsafe.Pointer, len uintptr)

var (
avx2 = cpu.X86.HasAVX2
sse2 = cpu.X86.HasSSE2
Expand Down

0 comments on commit d1878f6

Please sign in to comment.