mirror of
https://github.com/golang/go
synced 2024-11-19 10:24:43 -07:00
cda0ea1c0e
For arm and powerpc, as well as x86 without aes instructions. Contains a mixture of ideas from cityhash and xxhash. Compared to our old fallback on ARM, it's ~no slower on small objects and up to ~50% faster on large objects. More importantly, it is a much better hash function and thus has less chance of bad behavior. Fixes #8737 benchmark old ns/op new ns/op delta BenchmarkHash5 173 181 +4.62% BenchmarkHash16 252 212 -15.87% BenchmarkHash64 575 419 -27.13% BenchmarkHash1024 7173 3995 -44.31% BenchmarkHash65536 516940 313173 -39.42% BenchmarkHashStringSpeed 300 279 -7.00% BenchmarkHashBytesSpeed 478 424 -11.30% BenchmarkHashInt32Speed 217 207 -4.61% BenchmarkHashInt64Speed 262 231 -11.83% BenchmarkHashStringArraySpeed 609 631 +3.61% Change-Id: I0a9335028f32b10ad484966e3019987973afd3eb Reviewed-on: https://go-review.googlesource.com/1360 Reviewed-by: Russ Cox <rsc@golang.org>
21 lines
667 B
Go
21 lines
667 B
Go
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build arm ppc64 ppc64le
|
|
|
|
package runtime
|
|
|
|
import "unsafe"
|
|
|
|
// Note: These routines perform the read with an unspecified endianness.
|
|
func readUnaligned32(p unsafe.Pointer) uint32 {
|
|
q := (*[4]byte)(p)
|
|
return uint32(q[0]) + uint32(q[1])<<8 + uint32(q[2])<<16 + uint32(q[3])<<24
|
|
}
|
|
|
|
func readUnaligned64(p unsafe.Pointer) uint64 {
|
|
q := (*[8]byte)(p)
|
|
return uint64(q[0]) + uint64(q[1])<<8 + uint64(q[2])<<16 + uint64(q[3])<<24 + uint64(q[4])<<32 + uint64(q[5])<<40 + uint64(q[6])<<48 + uint64(q[7])<<56
|
|
}
|