aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorIlya Tocar <ilya.tocar@intel.com>2018-06-13 14:20:19 -0500
committerIlya Tocar <ilya.tocar@intel.com>2019-03-13 17:50:18 +0000
commit3aa7bbdbcb432f78462fa816ba7c63cb7f3991fe (patch)
treeb3cfdf77c28e30f78c5bc977224a72e67fde2854 /src/runtime
parent82bd93991a84042f4d960f0338cbff4792867857 (diff)
downloadgo-3aa7bbdbcb432f78462fa816ba7c63cb7f3991fe.tar.xz
runtime: simplify readUnaligned
We already have a pure go code sequence that is compiled into single load. Just use it everywhere, instead of pointer hackery. Passes toolstash-check. Change-Id: I0c42b5532fa9a5665da3385913609c6d42aaff27 Reviewed-on: https://go-review.googlesource.com/c/go/+/118568 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/alg.go18
-rw-r--r--src/runtime/unaligned1.go17
-rw-r--r--src/runtime/unaligned2.go20
3 files changed, 18 insertions, 37 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go
index 1c6795a1fa..732d32bf41 100644
--- a/src/runtime/alg.go
+++ b/src/runtime/alg.go
@@ -316,3 +316,21 @@ func initAlgAES() {
// Initialize with random data so hash collisions will be hard to engineer.
getRandomData(aeskeysched[:])
}
+
+// Note: These routines perform the read with an native endianness.
+func readUnaligned32(p unsafe.Pointer) uint32 {
+ q := (*[4]byte)(p)
+ if sys.BigEndian {
+ return uint32(q[3]) | uint32(q[2])<<8 | uint32(q[1])<<16 | uint32(q[0])<<24
+ }
+ 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)
+ if sys.BigEndian {
+ return uint64(q[7]) | uint64(q[6])<<8 | uint64(q[5])<<16 | uint64(q[4])<<24 |
+ uint64(q[3])<<32 | uint64(q[2])<<40 | uint64(q[1])<<48 | uint64(q[0])<<56
+ }
+ 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
+}
diff --git a/src/runtime/unaligned1.go b/src/runtime/unaligned1.go
deleted file mode 100644
index 1d90bdf83e..0000000000
--- a/src/runtime/unaligned1.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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 386 amd64 amd64p32 arm64 ppc64 ppc64le s390x wasm
-
-package runtime
-
-import "unsafe"
-
-func readUnaligned32(p unsafe.Pointer) uint32 {
- return *(*uint32)(p)
-}
-
-func readUnaligned64(p unsafe.Pointer) uint64 {
- return *(*uint64)(p)
-}
diff --git a/src/runtime/unaligned2.go b/src/runtime/unaligned2.go
deleted file mode 100644
index 28b61192c4..0000000000
--- a/src/runtime/unaligned2.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// 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 mips mipsle mips64 mips64le
-
-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
-}