Skip to content

Commit f8aecbb

Browse files
committed
runtime: move s390x HWCap CPU feature detection to internal/cpu
Change-Id: I7d9e31c3b342731ddd7329962426fdfc80e9ed87 Reviewed-on: https://go-review.googlesource.com/c/go/+/263803 Trust: Martin Möhrmann <moehrmann@google.com> Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
1 parent 91b7619 commit f8aecbb

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/internal/cpu/cpu_s390x.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package cpu
66

77
const CacheLinePadSize = 256
88

9+
var HWCap uint
10+
911
// bitIsSet reports whether the bit at index is set. The bit index
1012
// is in big endian order, so bit index 0 is the leftmost bit.
1113
func bitIsSet(bits []uint64, index uint) bool {
@@ -95,8 +97,10 @@ const (
9597
// vector facilities
9698
vxe facility = 135 // vector-enhancements 1
9799

98-
// Note: vx and highgprs are excluded because they require
99-
// kernel support and so must be fetched from HWCAP.
100+
// Note: vx requires kernel support
101+
// and so must be fetched from HWCAP.
102+
103+
hwcap_VX = 1 << 11 // vector facility
100104
)
101105

102106
// facilityList contains the result of an STFLE call.
@@ -188,7 +192,14 @@ func doinit() {
188192
S390X.HasEDDSA = kdsa.Has(eddsaVerifyEd25519, eddsaSignEd25519, eddsaVerifyEd448, eddsaSignEd448)
189193
}
190194
}
195+
196+
S390X.HasVX = isSet(HWCap, hwcap_VX)
197+
191198
if S390X.HasVX {
192199
S390X.HasVXE = facilities.Has(vxe)
193200
}
194201
}
202+
203+
func isSet(hwc uint, value uint) bool {
204+
return hwc&value != 0
205+
}

src/runtime/os_linux_s390x.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ package runtime
66

77
import "internal/cpu"
88

9-
const (
10-
// bit masks taken from bits/hwcap.h
11-
_HWCAP_S390_VX = 2048 // vector facility
12-
)
13-
149
func archauxv(tag, val uintptr) {
1510
switch tag {
16-
case _AT_HWCAP: // CPU capability bit flags
17-
cpu.S390X.HasVX = val&_HWCAP_S390_VX != 0
11+
case _AT_HWCAP:
12+
cpu.HWCap = uint(val)
1813
}
1914
}
2015

0 commit comments

Comments
 (0)