]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use unaligned loads on ppc64
authorKeith Randall <khr@golang.org>
Thu, 17 Mar 2016 20:28:04 +0000 (13:28 -0700)
committerKeith Randall <khr@golang.org>
Fri, 18 Mar 2016 19:21:53 +0000 (19:21 +0000)
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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/export_test.go
src/runtime/hash_test.go
src/runtime/unaligned1.go
src/runtime/unaligned2.go

index 3d29851fa0cb099391df51fcd25238d6cd82fe38..3994d5caf8cff76ef488ad7c8dc04f92d439be2e 100644 (file)
@@ -193,3 +193,6 @@ func SetTracebackEnv(level string) {
        setTraceback(level)
        traceback_env = traceback_cache
 }
+
+var ReadUnaligned32 = readUnaligned32
+var ReadUnaligned64 = readUnaligned64
index 7cceab86cc9610a20008ff8526f3163f3570cdc1..0022fd39a5f0f523c8185beabbe98ce4ce359187 100644 (file)
@@ -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
+}
index d3d6c70930820268c755bca1e83a863dc4b679d5..6bd901835248d6761e9a4aee7ab2967307f9d9cd 100644 (file)
@@ -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
 
index 1ec1d166e447f494c39e354e9513b99421659aa9..fed3cca1fdd51b759e2e26696d7a4ba48cbb2f0f 100644 (file)
@@ -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