diff options
author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/golang.org/x/sys/cpu/hwcap_linux.go | |
parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip |
Make Nix builds work
Diffstat (limited to 'vendor/golang.org/x/sys/cpu/hwcap_linux.go')
-rw-r--r-- | vendor/golang.org/x/sys/cpu/hwcap_linux.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/golang.org/x/sys/cpu/hwcap_linux.go b/vendor/golang.org/x/sys/cpu/hwcap_linux.go new file mode 100644 index 0000000..34e49f9 --- /dev/null +++ b/vendor/golang.org/x/sys/cpu/hwcap_linux.go | |||
@@ -0,0 +1,71 @@ | |||
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 cpu | ||
6 | |||
7 | import ( | ||
8 | "os" | ||
9 | ) | ||
10 | |||
11 | const ( | ||
12 | _AT_HWCAP = 16 | ||
13 | _AT_HWCAP2 = 26 | ||
14 | |||
15 | procAuxv = "/proc/self/auxv" | ||
16 | |||
17 | uintSize = int(32 << (^uint(0) >> 63)) | ||
18 | ) | ||
19 | |||
20 | // For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2 | ||
21 | // These are initialized in cpu_$GOARCH.go | ||
22 | // and should not be changed after they are initialized. | ||
23 | var hwCap uint | ||
24 | var hwCap2 uint | ||
25 | |||
26 | func readHWCAP() error { | ||
27 | // For Go 1.21+, get auxv from the Go runtime. | ||
28 | if a := getAuxv(); len(a) > 0 { | ||
29 | for len(a) >= 2 { | ||
30 | tag, val := a[0], uint(a[1]) | ||
31 | a = a[2:] | ||
32 | switch tag { | ||
33 | case _AT_HWCAP: | ||
34 | hwCap = val | ||
35 | case _AT_HWCAP2: | ||
36 | hwCap2 = val | ||
37 | } | ||
38 | } | ||
39 | return nil | ||
40 | } | ||
41 | |||
42 | buf, err := os.ReadFile(procAuxv) | ||
43 | if err != nil { | ||
44 | // e.g. on android /proc/self/auxv is not accessible, so silently | ||
45 | // ignore the error and leave Initialized = false. On some | ||
46 | // architectures (e.g. arm64) doinit() implements a fallback | ||
47 | // readout and will set Initialized = true again. | ||
48 | return err | ||
49 | } | ||
50 | bo := hostByteOrder() | ||
51 | for len(buf) >= 2*(uintSize/8) { | ||
52 | var tag, val uint | ||
53 | switch uintSize { | ||
54 | case 32: | ||
55 | tag = uint(bo.Uint32(buf[0:])) | ||
56 | val = uint(bo.Uint32(buf[4:])) | ||
57 | buf = buf[8:] | ||
58 | case 64: | ||
59 | tag = uint(bo.Uint64(buf[0:])) | ||
60 | val = uint(bo.Uint64(buf[8:])) | ||
61 | buf = buf[16:] | ||
62 | } | ||
63 | switch tag { | ||
64 | case _AT_HWCAP: | ||
65 | hwCap = val | ||
66 | case _AT_HWCAP2: | ||
67 | hwCap2 = val | ||
68 | } | ||
69 | } | ||
70 | return nil | ||
71 | } | ||