Skip to content

Commit

Permalink
fix: make cpuid compatable with various architectures
Browse files Browse the repository at this point in the history
- Added new files `abi/cpuid_amd64.go` and `abi/cpuid.go`
- Implemented the `asmCpuid` function in the `abi` package
- Added tests for the `cpuid` function in `abi/abi_test.go`
  • Loading branch information
Laisky committed Sep 21, 2023
1 parent a6bdd4c commit 13d1bb5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,10 @@ func TestSnpPlatformInfo(t *testing.T) {
}
}
}

func TestCpuid(t *testing.T) {
a, b, c, d := cpuid(1)
if (a | b | c | d) == 0 {
t.Errorf("cpuid(1) = 0, 0, 0, 0")
}
}
10 changes: 10 additions & 0 deletions abi/cpuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !amd64 || gccgo
// +build !amd64 gccgo

package abi

func init() {
cpuid = func(op uint32) (eax, ebx, ecx, edx uint32) {
return 0, 0, 0, 0
}
}
10 changes: 10 additions & 0 deletions abi/cpuid_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build amd64 && !gccgo
// +build amd64,!gccgo

package abi

func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)

func init() {
cpuid = asmCpuid
}

0 comments on commit 13d1bb5

Please sign in to comment.