Skip to content

Add arm64 go feature id#175

Merged
klauspost merged 3 commits into
masterfrom
arm64-feature
Jun 16, 2026
Merged

Add arm64 go feature id#175
klauspost merged 3 commits into
masterfrom
arm64-feature

Conversation

@klauspost

@klauspost klauspost commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Adds the following:

// ARM64Level returns the ARMv8/ARMv9 architecture version supported by the CPU
// as (major, minor), e.g. 8, 4 for ARMv8.4-A or 9, 0 for ARMv9.0-A.
// Only mandatory user-space instruction features are considered, so the result
// is the highest level whose required instructions are all present.
// Returns 0, 0 on non-arm64 CPUs or when feature detection was unavailable.
func (c CPUInfo) ARM64Level() (major, minor int)

// GOARM64 returns a value usable as the GOARM64 build setting for the detected
// CPU, e.g. "v8.4" or "v9.0,crypto". The ",crypto" suffix is appended when AES,
// PMULL, SHA1 and SHA256 are all present; the ",lse" suffix is appended in the
// rare case LSE is present without the rest of the ARMv8.1 feature set.
// Returns "" on non-arm64 CPUs or when feature detection was unavailable.
// See https://go.dev/wiki/MinimumRequirements#arm64
func (c CPUInfo) GOARM64() string

Fixes #159

Summary by CodeRabbit

  • New Features

    • Expanded ARM64 feature detection with additional instruction-set capabilities (including SVE2 and newer crypto/rounding/bit-manipulation extensions).
    • Improved ARM64 level reporting and updated output to include GOARM64 (including in -json output).
  • Bug Fixes

    • Fixed ARM64 hardware capability parsing on Linux so feature reporting correctly reflects values from the second capability word.
  • Documentation

    • Updated ARM feature tables in the README to list the newly supported capabilities.
  • Chores

    • Updated the Go toolchain to 1.24.0 and added extra CI test runs (with and without the noasm build tag).

Adds the following:

```go
// ARM64Level returns the ARMv8/ARMv9 architecture version supported by the CPU
// as (major, minor), e.g. 8, 4 for ARMv8.4-A or 9, 0 for ARMv9.0-A.
// Only mandatory user-space instruction features are considered, so the result
// is the highest level whose required instructions are all present.
// Returns 0, 0 on non-arm64 CPUs or when feature detection was unavailable.
func (c CPUInfo) ARM64Level() (major, minor int)

// GOARM64 returns a value usable as the GOARM64 build setting for the detected
// CPU, e.g. "v8.4" or "v9.0,crypto". The ",crypto" suffix is appended when AES,
// PMULL, SHA1 and SHA256 are all present; the ",lse" suffix is appended in the
// rare case LSE is present without the rest of the ARMv8.1 feature set.
// Returns "" on non-arm64 CPUs or when feature detection was unavailable.
// See https://go.dev/wiki/MinimumRequirements#arm64
func (c CPUInfo) GOARM64() string
```

Fixes #159
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92dc2356-d91f-446f-8b6c-dfff51cbd292

📥 Commits

Reviewing files that changed from the base of the PR and between 1a453c3 and d702c81.

📒 Files selected for processing (2)
  • cpuid.go
  • cpuid_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • cpuid_test.go
  • cpuid.go

📝 Walkthrough

Walkthrough

Adds 13 new ARM64 FeatureID constants and detects them on Linux via hwcap2 from /proc/self/auxv, on Darwin via hw.optional.arm.* sysctls, and on bare metal via ID_AA64ISAR register bitfields. Introduces ARM64Level() and updates GOARM64() to produce Go build strings. Exposes GOARM64 in the CLI tool.

Changes

ARM64 architecture level detection and GOARM64 support

Layer / File(s) Summary
New ARM64 FeatureID constants and generated stringer
cpuid.go, featureid_string.go
Adds SVE2, SB, SSBS, BTI, FLAGM2, FRINTTS, DCPODP, BF16, I8MM, WFXT, MOPS, HBC, CSSC to the FeatureID enum and regenerates the stringer output.
Linux ARM64 hwcap2 feature detection
os_linux_arm64.go
Introduces hwcap2 variable, fixes /proc/self/auxv parsing to store AT_HWCAP2, and reassigns RNDR plus all new features to be gated on hwcap2 bits instead of hwcap.
Darwin sysctl and register-based detection
os_darwin_arm64.go, detect_arm64.go
Extends tryToFillCPUInfoFomSysctl with setFeature calls for all 13 new constants; expands addInfo to extract FLAGM2, DCPODP, FRINTTS, SB, BF16, and I8MM from ID_AA64ISAR register bitfields.
ARM64Level() and GOARM64() methods
cpuid.go
Defines armV8Levels cumulative feature table and armCrypto set; adds ARM64Level() with ARMv9 promotion on SVE2; updates GOARM64() to emit vX.Y with optional ,lse and ,crypto suffixes; clarifies RVProfile() documentation.
CLI output, tests, CI, docs, and module update
cmd/cpuid/main.go, cpuid_test.go, .github/workflows/go.yml, README.md, go.mod
Adds GOARM64 to JSON and text output; adds TestARM64Level and TestGOARM64 unit tests with helpers; adds CI steps for cmd/cpuid/main.go with and without noasm; extends README ARM table and reformats RISC-V table; bumps to Go 1.24.0 and golang.org/x/sys v0.41.0.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive Title is vague and uses generic phrasing without clear description of what ARM64 features are being added. Revise title to be more specific, such as 'Add ARM64Level and GOARM64 methods for architecture detection' or 'Support ARM64 architecture level detection'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Pull request successfully implements both ARM64Level() and GOARM64() methods meeting all coding requirements from issue #159.
Out of Scope Changes check ✅ Passed All changes are in-scope, implementing ARM64 architecture detection per issue #159 with appropriate test coverage and documentation updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch arm64-feature

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 514: The ARM features table in README.md is missing periods after the
"etc" abbreviation at multiple locations. Add a period before the closing
parenthesis to change "etc)" to "etc.)" at all affected lines: line 514 in the
FRINTTS entry, line 516, line 519, and line 521. This follows American English
convention that requires periods after abbreviations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c5a60985-58b8-4902-95e2-5dd3164a9fbd

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed6d97 and 1a453c3.

📒 Files selected for processing (5)
  • README.md
  • cmd/cpuid/main.go
  • cpuid.go
  • cpuid_test.go
  • os_linux_arm64.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • cmd/cpuid/main.go
  • cpuid.go
  • cpuid_test.go
  • os_linux_arm64.go

Comment thread README.md
@klauspost klauspost merged commit f26cd2e into master Jun 16, 2026
14 checks passed
@klauspost klauspost deleted the arm64-feature branch June 16, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support detection of ARM architecture level

1 participant