From 15ea61146e49b91b84b7b3a3096b13ddfb4cc01f Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 17 Mar 2016 13:28:04 -0700 Subject: [PATCH] runtime: use unaligned loads on ppc64 benchmark old ns/op new ns/op delta BenchmarkAlignedLoad-160 8.67 7.42 -14.42% BenchmarkUnalignedLoad-160 8.63 7.37 -14.60% Change-Id: Id4609d7b4038c4d2ec332efc4fe6f1adfb61b82b Reviewed-on: https://go-review.googlesource.com/20812 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/runtime/export_test.go | 3 +++ src/runtime/hash_test.go | 22 ++++++++++++++++++++++ src/runtime/unaligned1.go | 2 +- src/runtime/unaligned2.go | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 3d29851fa0..3994d5caf8 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -193,3 +193,6 @@ func SetTracebackEnv(level string) { setTraceback(level) traceback_env = traceback_cache } + +var ReadUnaligned32 = readUnaligned32 +var ReadUnaligned64 = readUnaligned64 diff --git a/src/runtime/hash_test.go b/src/runtime/hash_test.go index 7cceab86cc..0022fd39a5 100644 --- a/src/runtime/hash_test.go +++ b/src/runtime/hash_test.go @@ -11,6 +11,7 @@ import ( . "runtime" "strings" "testing" + "unsafe" ) // Smhasher is a torture test for hash functions. @@ -658,3 +659,24 @@ func TestStructHash(t *testing.T) { t.Errorf("too many allocs %f - hash not balanced", n) } } + +var sink uint64 + +func BenchmarkAlignedLoad(b *testing.B) { + var buf [16]byte + p := unsafe.Pointer(&buf[0]) + var s uint64 + for i := 0; i < b.N; i++ { + s += ReadUnaligned64(p) + } + sink = s +} +func BenchmarkUnalignedLoad(b *testing.B) { + var buf [16]byte + p := unsafe.Pointer(&buf[1]) + var s uint64 + for i := 0; i < b.N; i++ { + s += ReadUnaligned64(p) + } + sink = s +} diff --git a/src/runtime/unaligned1.go b/src/runtime/unaligned1.go index d3d6c70930..6bd9018352 100644 --- a/src/runtime/unaligned1.go +++ b/src/runtime/unaligned1.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build 386 amd64 amd64p32 arm64 +// +build 386 amd64 amd64p32 arm64 ppc64 ppc64le package runtime diff --git a/src/runtime/unaligned2.go b/src/runtime/unaligned2.go index 1ec1d166e4..fed3cca1fd 100644 --- a/src/runtime/unaligned2.go +++ b/src/runtime/unaligned2.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build arm ppc64 ppc64le mips64 mips64le +// +build arm mips64 mips64le package runtime -- 2.48.1