Sample
github.com/klauspost/cpuid/v2 v2.2.10: cpuid.CPU
Verified sample for golang github.com/klauspost/cpuid/v2 v2.2.10: cpuid.CPU. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.
sha256:e392c980f485f75f0ab3bed34b8fbaa7278b5c503c85f74066bf9d2319ac9611
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 1
Declared environment
go linux 24 · ubuntu · glibc 2.39 x64 go go go
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-26 |
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | FAIL | compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-07 |
Case
HOW- Goal
- verify cpuid.CPU in pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10
- Symbols
-
- cpuid.CPU
- Environment
- go
- Created
- 2026-08-26T04:47:18Z
Contract
- cpuid.CPU is a global CPUInfo struct initialized at startup providing non-negative core counts and matching vendor information.
- cpuid.CPU.Supports returns true if all specified feature IDs are supported, and cpuid.CPU.AnyOf returns true if at least one feature ID is supported.
- Passing cpuid.UNKNOWN (-1) or an unrecognized feature ID directly to cpuid.CPU.Has causes an index out of range panic.
- Dynamic feature flag modification with Enable and Disable updates CPUInfo feature membership and alters subsequent Has, Supports, and AnyOf query results.
Files
- NOTES.md
- PROMPT.md
- cpuid_test.go
- csx.json
- go.mod
- go.sum
- spec.json
Source
# klauspost/cpuid/v2 CPU Feature Detection and Query Semantics
## Prior Knowledge Search
A query to search known solutions for `github.com/klauspost/cpuid/v2` with `cpuid.CPU` returned `NO_SAFE_MATCH`.
## Pinned Release
- `github.com/klauspost/cpuid/v2`: `v2.2.10`
## Observed Behavior and API Contracts
### 1. Global `cpuid.CPU` Singleton Initialization
- `cpuid.CPU` is an exported global `CPUInfo` struct initialized automatically at runtime startup.
- It exposes hardware attributes such as `PhysicalCores`, `LogicalCores`, `Family`, `Model`, `Stepping`, `VendorID`, and `VendorString`.
- Core counts are non-negative, and `VendorString` matches the detected `VendorID`.
### 2. Feature Querying with `Supports`, `AnyOf`, and `FeatureSet`
- `cpuid.CPU.FeatureSet()` returns a slice of string names of all detected CPU features.
- `cpuid.CPU.Supports(ids ...FeatureID)` checks for conjunction: returns `true` only if all specified features are supported (vacuously `true` when passed zero arguments).
- `cpuid.CPU.AnyOf(ids ...FeatureID)` checks for disjunction: returns `true` if at least one of the specified features is supported (returns `false` when passed zero arguments).
### 3. Negative / Unknown Feature Panic Behavior
- `cpuid.ParseFeature` returns `cpuid.UNKNOWN` (`-1`) when given an unrecognized feature name.
- `cpuid.CPU.Has(id FeatureID)` directly indexes internal flag buckets without bounds-checking negative indices (`set[id/64]`).
- As a consequence, passing `cpuid.UNKNOWN` (`-1`) to `cpuid.CPU.Has` causes a runtime panic (`runtime error: index out of range [-1]`) rather than returning `false`. Callers must guard against `UNKNOWN` or negative feature IDs before invoking `Has`.
### 4. Dynamic Feature Flag Mutation via `Enable` and `Disable`
- `CPUInfo` instances (cloned or custom) support `Enable(ids ...FeatureID)` and `Disable(ids ...FeatureID)` to mutate enabled CPU feature flags.
- Enabling or disabling features immediately updates the output of `Has`, `Supports`, and `AnyOf` on that instance.
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify cpuid.CPU in pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10
Demonstrate these symbols/APIs:
- cpuid.CPU
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
package cpuidcheck
import (
"testing"
"github.com/klauspost/cpuid/v2"
)
func TestCPUSingletonAndProperties(t *testing.T) {
// 1. cpuid.CPU provides CPU info detected at initialization
if cpuid.CPU.PhysicalCores < 0 || cpuid.CPU.LogicalCores < 0 {
t.Fatalf("expected non-negative core counts, got physical: %d, logical: %d",
cpuid.CPU.PhysicalCores, cpuid.CPU.LogicalCores)
}
if cpuid.CPU.VendorString == "" && cpuid.CPU.VendorID != cpuid.VendorUnknown {
t.Fatalf("expected VendorString to match VendorID")
}
}
func TestCPUFeatureQueries(t *testing.T) {
// 2. Querying features via Supports, AnyOf, and FeatureSet
features := cpuid.CPU.FeatureSet()
if len(features) > 0 {
// First feature from FeatureSet should be reported as supported via Has
firstFeatureID := cpuid.ParseFeature(features[0])
if firstFeatureID != cpuid.UNKNOWN {
if !cpuid.CPU.Has(firstFeatureID) {
t.Fatalf("expected cpuid.CPU.Has(%s) to be true", features[0])
}
}
}
// Supports with empty slice returns true
if !cpuid.CPU.Supports() {
t.Fatalf("cpuid.CPU.Supports() with no arguments must return true")
}
// AnyOf with empty slice returns false
if cpuid.CPU.AnyOf() {
t.Fatalf("cpuid.CPU.AnyOf() with no arguments must return false")
}
}
func TestCPUUnknownFeaturePanic(t *testing.T) {
// 3. Querying cpuid.UNKNOWN (-1) or invalid feature ID directly with Has panics with index out of range
defer func() {
r := recover()
if r == nil {
t.Fatalf("expected panic when checking cpuid.CPU.Has(cpuid.UNKNOWN), but none occurred")
}
}()
_ = cpuid.CPU.Has(cpuid.UNKNOWN)
}
func TestCPUFeatureMutation(t *testing.T) {
// 4. Modifying features on a CPUInfo instance via Enable and Disable
customCPU := cpuid.CPU
// Enable a feature
customCPU.Enable(cpuid.AVX512F)
if !customCPU.Has(cpuid.AVX512F) {
t.Fatalf("expected customCPU.Has(AVX512F) to be true after Enable")
}
// Disable the feature
customCPU.Disable(cpuid.AVX512F)
if customCPU.Has(cpuid.AVX512F) {
t.Fatalf("expected customCPU.Has(AVX512F) to be false after Disable")
}
// Supports reflects multiple features
customCPU.Enable(cpuid.AVX, cpuid.AVX2)
if !customCPU.Supports(cpuid.AVX, cpuid.AVX2) {
t.Fatalf("expected customCPU.Supports(AVX, AVX2) to be true")
}
customCPU.Disable(cpuid.AVX2)
if customCPU.Supports(cpuid.AVX, cpuid.AVX2) {
t.Fatalf("expected customCPU.Supports(AVX, AVX2) to be false after disabling AVX2")
}
if !customCPU.AnyOf(cpuid.AVX, cpuid.AVX2) {
t.Fatalf("expected customCPU.AnyOf(AVX, AVX2) to be true when AVX is enabled")
}
}
{"case":{"caseId":"case:sha256:5c14fa714ed99771e0adc1c88e6531f4b8978d973785654a1e33fe07c6a78fbb","contract":["cpuid.CPU is a global CPUInfo struct initialized at startup providing non-negative core counts and matching vendor information.","cpuid.CPU.Supports returns true if all specified feature IDs are supported, and cpuid.CPU.AnyOf returns true if at least one feature ID is supported.","Passing cpuid.UNKNOWN (-1) or an unrecognized feature ID directly to cpuid.CPU.Has causes an index out of range panic.","Dynamic feature flag modification with Enable and Disable updates CPUInfo feature membership and alters subsequent Has, Supports, and AnyOf query results."],"goal":"verify cpuid.CPU in pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10","kind":"HOW","packages":["pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10"],"schemaVersion":1,"symbols":["cpuid.CPU"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10","symbols":["cpuid.CPU"],"verifierAdapter":"golang@1"}
module example.com/cpuidcheck
go 1.26.6
require (
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
golang.org/x/sys v0.30.0 // indirect
)
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
{
"schemaVersion": 1,
"goal": "verify cpuid.CPU in pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/klauspost/cpuid/v2@v2.2.10"
],
"symbols": [
"cpuid.CPU"
]
}
Origin Seeder
anonymous