Skip to content

Commit 92acb74

Browse files
committed
internal/xcpu: Vendor golang.org/x/sys/cpu
Standard library does this too. Unfortunate wish they just exposed it in the standard library. Perhaps we can isolate the specific code we need later.
1 parent f62cef3 commit 92acb74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2242
-33
lines changed

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module nhooyr.io/websocket
22

33
go 1.19
4-
5-
require golang.org/x/sys v0.17.0

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
2-
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

internal/examples/go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ require (
88
golang.org/x/time v0.3.0
99
nhooyr.io/websocket v0.0.0-00010101000000-000000000000
1010
)
11-
12-
require golang.org/x/sys v0.17.0 // indirect

internal/examples/go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
2-
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
31
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
42
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

internal/xcpu/.gitattributes

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Treat all files in this repo as binary, with no git magic updating
2+
# line endings. Windows users contributing to Go will need to use a
3+
# modern version of git and editors capable of LF line endings.
4+
#
5+
# We'll prevent accidental CRLF line endings from entering the repo
6+
# via the git-review gofmt checks.
7+
#
8+
# See golang.org/issue/9281
9+
10+
* -text

internal/xcpu/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Add no patterns to .gitignore except for files generated by the build.
2+
last-change

internal/xcpu/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# cpu
2+
3+
Vendored from https://github.com/golang/sys

internal/xcpu/asm_aix_ppc64.s

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 in the LICENSE file.
4+
5+
//go:build gc
6+
7+
#include "textflag.h"
8+
9+
//
10+
// System calls for ppc64, AIX are implemented in runtime/syscall_aix.go
11+
//
12+
13+
TEXT ·syscall6(SB),NOSPLIT,$0-88
14+
JMP syscall·syscall6(SB)
15+
16+
TEXT ·rawSyscall6(SB),NOSPLIT,$0-88
17+
JMP syscall·rawSyscall6(SB)

internal/xcpu/byteorder.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package xcpu
6+
7+
import (
8+
"runtime"
9+
)
10+
11+
// byteOrder is a subset of encoding/binary.ByteOrder.
12+
type byteOrder interface {
13+
Uint32([]byte) uint32
14+
Uint64([]byte) uint64
15+
}
16+
17+
type littleEndian struct{}
18+
type bigEndian struct{}
19+
20+
func (littleEndian) Uint32(b []byte) uint32 {
21+
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
22+
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
23+
}
24+
25+
func (littleEndian) Uint64(b []byte) uint64 {
26+
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
27+
return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
28+
uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
29+
}
30+
31+
func (bigEndian) Uint32(b []byte) uint32 {
32+
_ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
33+
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
34+
}
35+
36+
func (bigEndian) Uint64(b []byte) uint64 {
37+
_ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
38+
return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
39+
uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
40+
}
41+
42+
// hostByteOrder returns littleEndian on little-endian machines and
43+
// bigEndian on big-endian machines.
44+
func hostByteOrder() byteOrder {
45+
switch runtime.GOARCH {
46+
case "386", "amd64", "amd64p32",
47+
"alpha",
48+
"arm", "arm64",
49+
"loong64",
50+
"mipsle", "mips64le", "mips64p32le",
51+
"nios2",
52+
"ppc64le",
53+
"riscv", "riscv64",
54+
"sh":
55+
return littleEndian{}
56+
case "armbe", "arm64be",
57+
"m68k",
58+
"mips", "mips64", "mips64p32",
59+
"ppc", "ppc64",
60+
"s390", "s390x",
61+
"shbe",
62+
"sparc", "sparc64":
63+
return bigEndian{}
64+
}
65+
panic("unknown architecture")
66+
}

0 commit comments

Comments
 (0)