Skip to content

Commit d25825d

Browse files
authored
Add Arm SVE Vector and Predicate lengths (#146)
Bumps deps and CI as well.
1 parent 95e7626 commit d25825d

File tree

10 files changed

+34
-12
lines changed

10 files changed

+34
-12
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111
strategy:
1212
matrix:
13-
go-version: [1.19.x, 1.20.x, 1.21.x]
13+
go-version: [1.20.x, 1.21.x, 1.22.x]
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515
runs-on: ubuntu-latest
1616
steps:
@@ -38,7 +38,7 @@ jobs:
3838
- name: Set up Go
3939
uses: actions/setup-go@v4
4040
with:
41-
go-version: 1.21.x
41+
go-version: 1.22.x
4242

4343
- name: Checkout code
4444
uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: Set up Go
1919
uses: actions/setup-go@v4
2020
with:
21-
go-version: 1.21.x
21+
go-version: 1.22.x
2222
-
2323
name: Run GoReleaser
2424
uses: goreleaser/goreleaser-action@v5

cpuid.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ func (c CPUInfo) FeatureSet() []string {
503503
// Uses the RDTSCP instruction. The value 0 is returned
504504
// if the CPU does not support the instruction.
505505
func (c CPUInfo) RTCounter() uint64 {
506-
if !c.Supports(RDTSCP) {
506+
if !c.Has(RDTSCP) {
507507
return 0
508508
}
509509
a, _, _, d := rdtscpAsm()
@@ -515,13 +515,22 @@ func (c CPUInfo) RTCounter() uint64 {
515515
// about the current cpu/core the code is running on.
516516
// If the RDTSCP instruction isn't supported on the CPU, the value 0 is returned.
517517
func (c CPUInfo) Ia32TscAux() uint32 {
518-
if !c.Supports(RDTSCP) {
518+
if !c.Has(RDTSCP) {
519519
return 0
520520
}
521521
_, _, ecx, _ := rdtscpAsm()
522522
return ecx
523523
}
524524

525+
// SveLengths returns arm SVE vector and predicate lengths.
526+
// Will return 0, 0 if SVE is not enabled or otherwise unable to detect.
527+
func (c CPUInfo) SveLengths() (vl, pl uint64) {
528+
if !c.Has(SVE) {
529+
return 0, 0
530+
}
531+
return getVectorLength()
532+
}
533+
525534
// LogicalCPU will return the Logical CPU the code is currently executing on.
526535
// This is likely to change when the OS re-schedules the running thread
527536
// to another CPU.

cpuid_arm64.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ TEXT ·getInstAttributes(SB), 7, $0
2424
MOVD R1, instAttrReg1+8(FP)
2525
RET
2626

27+
TEXT ·getVectorLength(SB), 7, $0
28+
WORD $0xd2800002 // mov x2, #0
29+
WORD $0x04225022 // addvl x2, x2, #1
30+
WORD $0xd37df042 // lsl x2, x2, #3
31+
WORD $0xd2800003 // mov x3, #0
32+
WORD $0x04635023 // addpl x3, x3, #1
33+
WORD $0xd37df063 // lsl x3, x3, #3
34+
MOVD R2, vl+0(FP)
35+
MOVD R3, pl+8(FP)
36+
RET

detect_arm64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "runtime"
1010
func getMidr() (midr uint64)
1111
func getProcFeatures() (procFeatures uint64)
1212
func getInstAttributes() (instAttrReg0, instAttrReg1 uint64)
13+
func getVectorLength() (vl, pl uint64)
1314

1415
func initCPU() {
1516
cpuid = func(uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
@@ -24,7 +25,7 @@ func addInfo(c *CPUInfo, safe bool) {
2425
detectOS(c)
2526

2627
// ARM64 disabled since it may crash if interrupt is not intercepted by OS.
27-
if safe && !c.Supports(ARMCPUID) && runtime.GOOS != "freebsd" {
28+
if safe && !c.Has(ARMCPUID) && runtime.GOOS != "freebsd" {
2829
return
2930
}
3031
midr := getMidr()

detect_ref.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ func initCPU() {
1010
cpuidex = func(x, y uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
1111
xgetbv = func(uint32) (a, b uint32) { return 0, 0 }
1212
rdtscpAsm = func() (a, b, c, d uint32) { return 0, 0, 0, 0 }
13+
1314
}
1415

1516
func addInfo(info *CPUInfo, safe bool) {}
17+
func getVectorLength() (vl, pl uint64) { return 0, 0 }

detect_x86.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ func addInfo(c *CPUInfo, safe bool) {
3636
c.cacheSize()
3737
c.frequencies()
3838
}
39+
40+
func getVectorLength() (vl, pl uint64) { return 0, 0 }

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/klauspost/cpuid/v2
22

3-
go 1.15
3+
go 1.20
44

5-
require golang.org/x/sys v0.5.0
5+
require golang.org/x/sys v0.22.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e h1:CsOuNlbOuf0mzxJIefr6Q4uAUetRUwZE4qt7VfzP+xo=
2-
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3-
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
4-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1+
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
2+
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

testdata/cpuid_data.zip

274 KB
Binary file not shown.

0 commit comments

Comments
 (0)