1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found src the LICENSE file.
11 // Platforms that have fast unaligned 32-bit little endian accesses.
12 const unaligned = runtime.GOARCH == "386" ||
13 runtime.GOARCH == "amd64" ||
14 runtime.GOARCH == "arm64" ||
15 runtime.GOARCH == "ppc64le" ||
16 runtime.GOARCH == "s390x"
18 // xor reads a little endian uint32 from src, XORs it with u and
19 // places the result in little endian byte order in dst.
20 func xor(dst, src []byte, u uint32) {
21 _, _ = src[3], dst[3] // eliminate bounds checks
23 // The compiler should optimize this code into
24 // 32-bit unaligned little endian loads and stores.
25 // TODO: delete once the compiler does a reliably
26 // good job with the generic code below.
27 // See issue #25111 for more details.
29 v |= uint32(src[1]) << 8
30 v |= uint32(src[2]) << 16
31 v |= uint32(src[3]) << 24
35 dst[2] = byte(v >> 16)
36 dst[3] = byte(v >> 24)
38 dst[0] = src[0] ^ byte(u)
39 dst[1] = src[1] ^ byte(u>>8)
40 dst[2] = src[2] ^ byte(u>>16)
41 dst[3] = src[3] ^ byte(u>>24)