aboutsummaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2013-02-07 21:40:10 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2013-02-07 21:40:10 +0000
commitaf4acefcd7e0187bdf4471b9bbb731b2757c0698 (patch)
tree7191a7b9e309d011a21d1585a551658470376170 /libgo
parentf11c7048b94d6d0c1a37f1e765fc17a69734daec (diff)
downloadgcc-af4acefcd7e0187bdf4471b9bbb731b2757c0698.zip
gcc-af4acefcd7e0187bdf4471b9bbb731b2757c0698.tar.gz
gcc-af4acefcd7e0187bdf4471b9bbb731b2757c0698.tar.bz2
re PR go/56173 (Several libgo tests FAIL on Solaris/SPARC)
PR go/56173 crypto/md5: fix for big-endian processors From-SVN: r195867
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/crypto/md5/md5block.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/libgo/go/crypto/md5/md5block.go b/libgo/go/crypto/md5/md5block.go
index 59f8f6f..0ca4217 100644
--- a/libgo/go/crypto/md5/md5block.go
+++ b/libgo/go/crypto/md5/md5block.go
@@ -5,6 +5,16 @@ import (
"unsafe"
)
+const x86 = runtime.GOARCH == "amd64" || runtime.GOARCH == "386"
+
+var littleEndian bool
+
+func init() {
+ x := uint32(0x04030201)
+ y := [4]byte{0x1, 0x2, 0x3, 0x4}
+ littleEndian = *(*[4]byte)(unsafe.Pointer(&x)) == y
+}
+
func block(dig *digest, p []byte) {
a := dig.s[0]
b := dig.s[1]
@@ -16,13 +26,13 @@ func block(dig *digest, p []byte) {
aa, bb, cc, dd := a, b, c, d
// This is a constant condition - it is not evaluated on each iteration.
- if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" {
+ if x86 {
// MD5 was designed so that x86 processors can just iterate
// over the block data directly as uint32s, and we generate
// less code and run 1.3x faster if we take advantage of that.
// My apologies.
X = (*[16]uint32)(unsafe.Pointer(&p[0]))
- } else if uintptr(unsafe.Pointer(&p[0]))&(unsafe.Alignof(uint32(0))-1) == 0 {
+ } else if littleEndian && uintptr(unsafe.Pointer(&p[0]))&(unsafe.Alignof(uint32(0))-1) == 0 {
X = (*[16]uint32)(unsafe.Pointer(&p[0]))
} else {
X = &xbuf