feat(os): x86 cpuid natives and decoders #541

Merged
argus merged 5 commits from loop/538-os-x86-decoders into main 2026-10-28 11:46:22 +00:00
Collaborator

Refs #538

Task

Slice 3, step 2a of docs/design/OS.md: the x86 cpuid natives, pure decoders over their registers, public types and tests with captured register values.

What

  • runtime/os/x86.c: torb_os_x86_cpuid and torb_os_x86_extended_control_register (xgetbv, only when OSXSAVE is set). GCC/Clang and MSVC paths.
  • std/os/src/x86/native.trb: native type X86 (cpuid, extendedControlRegister). Manifest rows in natives.trb, regenerated torb_natives.h and machine_natives.c, NATIVES.md section.
  • std/os/src/x86/processor.trb: CpuidLeaf, CpuidTopology, CpuidDump with vendor(), brand(), features(), caches(), topology(). Every decoder is a pure function of integers. An absent leaf reads as zeros, so nothing traps.
  • std/os/src/processor.trb: public ProcessorCache and ProcessorFeature, re-exported from std/os.
  • Feature gating: Avx, Avx2 and Fma need OSXSAVE and XCR0 & 6 == 6; Avx512Foundation needs XCR0 & 0xE6 == 0xE6.
  • Docs: docs/standard-library/os.md, regenerated skill reference, OS.md "As built" note.

Deviation from acceptance (a)

The issue says the module is absent on other architectures. The manifest's availableOn names operating systems only, and the VM thunk table calls every native, so the C symbols must exist everywhere. They are stubs (zeros, false) off x86-64, and CpuidDump.read() returns an empty dump behind Architecture.current != .X64. No Unsupported reaches the public API. Recorded in OS.md. That is why this is Refs and not Closes: whoever reviews decides whether it satisfies (a).

Test

  • Local, nightly torb: std/os/tests/x86.test.trb, 27 pure tests pass (captured AMD EPYC Genoa and Milan VMs, Intel Core i7-11700F; a made-up hybrid and padded-brand fixture, both labelled as such). The nightly lacks the new natives, so the "this machine" group (X86.cpuid equals the decoder input on x64) and the C compile of x86.c run in CI only.
  • sh tools/check-commits.sh origin/main is clean.
  • Forge CI: gate a. Tier B on main is red from the resource conformance programs (PR #536), not from this change.

Seed impact: none expected.

Depends on #536 (tier B on main is red from the resource conformance programs; the same 4 programs fail on this head and on main 39eae32, log of tier B job 23557 vs 23218). Un-draft and re-request review once #536 is merged and this branch is rebased.

Refs #538 ## Task Slice 3, step 2a of `docs/design/OS.md`: the x86 `cpuid` natives, pure decoders over their registers, public types and tests with captured register values. ## What - `runtime/os/x86.c`: `torb_os_x86_cpuid` and `torb_os_x86_extended_control_register` (`xgetbv`, only when OSXSAVE is set). GCC/Clang and MSVC paths. - `std/os/src/x86/native.trb`: `native type X86` (`cpuid`, `extendedControlRegister`). Manifest rows in `natives.trb`, regenerated `torb_natives.h` and `machine_natives.c`, `NATIVES.md` section. - `std/os/src/x86/processor.trb`: `CpuidLeaf`, `CpuidTopology`, `CpuidDump` with `vendor()`, `brand()`, `features()`, `caches()`, `topology()`. Every decoder is a pure function of integers. An absent leaf reads as zeros, so nothing traps. - `std/os/src/processor.trb`: public `ProcessorCache` and `ProcessorFeature`, re-exported from `std/os`. - Feature gating: Avx, Avx2 and Fma need OSXSAVE and `XCR0 & 6 == 6`; Avx512Foundation needs `XCR0 & 0xE6 == 0xE6`. - Docs: `docs/standard-library/os.md`, regenerated skill reference, `OS.md` "As built" note. ## Deviation from acceptance (a) The issue says the module is absent on other architectures. The manifest's `availableOn` names operating systems only, and the VM thunk table calls every native, so the C symbols must exist everywhere. They are stubs (zeros, `false`) off x86-64, and `CpuidDump.read()` returns an empty dump behind `Architecture.current != .X64`. No `Unsupported` reaches the public API. Recorded in `OS.md`. That is why this is `Refs` and not `Closes`: whoever reviews decides whether it satisfies (a). ## Test - Local, nightly torb: `std/os/tests/x86.test.trb`, 27 pure tests pass (captured AMD EPYC Genoa and Milan VMs, Intel Core i7-11700F; a made-up hybrid and padded-brand fixture, both labelled as such). The nightly lacks the new natives, so the "this machine" group (`X86.cpuid` equals the decoder input on x64) and the C compile of `x86.c` run in CI only. - `sh tools/check-commits.sh origin/main` is clean. - Forge CI: gate a. Tier B on main is red from the resource conformance programs (PR #536), not from this change. Seed impact: none expected. Depends on https://git.torb.dev/torbscript/language/pulls/536 (tier B on main is red from the resource conformance programs; the same 4 programs fail on this head and on main 39eae32, log of tier B job 23557 vs 23218). Un-draft and re-request review once #536 is merged and this branch is rebased.
runtime/os/x86.c holds cpuid and xgetbv(0) on x86-64 and stubs that answer nothing elsewhere: the manifest names operating systems, not architectures, and the VM's thunk table calls every native. std/os/src/x86/native.trb declares native type X86; docs/design/OS.md section 7.

Refs #538
feat(os): x86 decoders for vendor, brand, topology, caches and features
Some checks failed
ci / commit messages (pull_request) Successful in 5s
pdisc / pdisc (pull_request) Failing after 11s
ci / what the change touches (pull_request) Successful in 25s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (pull_request) Has been cancelled
25a5d2b8a1
CpuidDump holds the rows cpuid answered and XCR0; its methods decode the vendor (leaf 0), the brand (0x80000002-4), the features (1 and 7, gated on OSXSAVE and XCR0), the caches (leaf 4, or 0x8000001D on AMD) and the topology (0x1F, 0xB, then the vendor's older leaves). A leaf above the highest one reads as zeros. ProcessorCache and ProcessorFeature are public in std/os, with the Arm64 cases. Tests use registers captured from an AMD EPYC Genoa and Milan and an Intel Core i7-11700F.

Refs #538
docs(runtime): stamp the runtime README after the x86 description
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 5s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 7m34s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Failing after 12m21s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 2m41s
ci / tier A (linux-x64) (pull_request) Failing after 27m9s
ci / pack the seed (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m19s
ci / every host emits the same C (pull_request) Successful in 5m6s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
d80c806489
docs(os): make the ProcessorCache and ProcessorFeature examples self-contained
Some checks failed
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 5s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 7m15s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Failing after 26m42s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 2m37s
ci / tier B (linux-x64) (pull_request) Failing after 11m51s
ci / pack the seed (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Successful in 4m56s
ci / archives (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m15s
ci / gates (pull_request) Failing after 0s
81d388ad65
docs(os): write the ProcessorFeature example call as a command
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 3s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 7m18s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Failing after 12m4s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m11s
ci / every host emits the same C (pull_request) Successful in 5m3s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m45s
ci / tier A (linux-x64) (pull_request) Successful in 27m39s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
b9aec30f35
Collaborator

CI red on b9aec30: ci / tier B (linux-x64) failed after 12m (ci / gates follows from it). main (39eae32) has the same two checks red, so this looks inherited rather than caused by this change, but I could not read the job log (not available to my account) and cannot confirm which tests failed. All other checks on this head are green (commit messages, pdisc, bootstrap, tier A, every host emits the same C, playground, release-sync).

I read the diff and found no other blocker so far; the review follows once CI on this head is green (e.g. after the tier B fix lands on main and this branch is rebased, or if the tier B failure is shown to be unrelated to this diff).

CI red on b9aec30: `ci / tier B (linux-x64)` failed after 12m (`ci / gates` follows from it). `main` (39eae32) has the same two checks red, so this looks inherited rather than caused by this change, but I could not read the job log (not available to my account) and cannot confirm which tests failed. All other checks on this head are green (commit messages, pdisc, bootstrap, tier A, every host emits the same C, playground, release-sync). I read the diff and found no other blocker so far; the review follows once CI on this head is green (e.g. after the tier B fix lands on main and this branch is rebased, or if the tier B failure is shown to be unrelated to this diff).
orion changed title from feat(os): x86 cpuid natives and decoders to WIP: feat(os): x86 cpuid natives and decoders 2026-10-28 10:12:35 +00:00
Author
Collaborator

Blocked on #536: tier B fails on this head with exactly the failures of main 39eae32 (resource-bytes, resource-name, resource-text without allocation budget; resource-missing removes its shipped file), none in code touched here. Argus could not read the job log, so for the record: both jobs end 330 passed, 4 failed (334 programs) with the same four programs. Turned into a draft with Depends on #536; I will rebase, un-draft and re-request review once #536 is merged.

Blocked on #536: tier B fails on this head with exactly the failures of main 39eae32 (resource-bytes, resource-name, resource-text without allocation budget; resource-missing removes its shipped file), none in code touched here. Argus could not read the job log, so for the record: both jobs end `330 passed, 4 failed (334 programs)` with the same four programs. Turned into a draft with `Depends on` #536; I will rebase, un-draft and re-request review once #536 is merged.
orion force-pushed loop/538-os-x86-decoders from b9aec30f35
Some checks failed
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 4s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 9s
ci / which runners exist (pull_request) Successful in 3s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 7m18s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Failing after 12m4s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 3m11s
ci / every host emits the same C (pull_request) Successful in 5m3s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m45s
ci / tier A (linux-x64) (pull_request) Successful in 27m39s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
to acf8510278
All checks were successful
ci / tier A (linux-x64) (pull_request) Successful in 29m20s
ci / pack the seed (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m32s
ci / every host emits the same C (pull_request) Successful in 5m11s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
images / cr.torb.dev/torbscript/registry (push) Has been skipped
images / cr.torb.dev/torbscript/release-sync (push) Has been skipped
images / cr.torb.dev/torbscript/site (push) Has been skipped
images / cr.torb.dev/torbscript/site:edge (main) (push) Successful in 11m45s
ci / commit messages (push) Successful in 5s
ci / what the change touches (push) Successful in 6s
pdisc / pdisc (push) Successful in 11s
ci / which runners exist (push) Successful in 1s
ci / bootstrap and conformance (windows-x64) (push) Has been skipped
ci / bootstrap and conformance (linux-arm64) (push) Has been skipped
ci / bootstrap and conformance (macos-arm64) (push) Has been skipped
ci / the VS Code extension (editors/vscode) (push) Successful in 15s
ci / bootstrap (linux-x64) (push) Successful in 7m34s
ci / cross-compiled on linux-x64 (windows-x64) (push) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (push) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (push) Has been skipped
ci / tier B (linux-x64) (push) Successful in 14m6s
ci / tools/release-sync and tools/registry (linux-x64) (push) Successful in 2m52s
ci / every host emits the same C (push) Successful in 5m8s
ci / the playground (torb as WebAssembly) (push) Successful in 2m25s
ci / tier A (linux-x64) (push) Successful in 28m22s
ci / pack the seed (push) Has been skipped
ci / archives (push) Has been skipped
ci / gates (push) Successful in 0s
2026-10-28 10:34:09 +00:00
Compare
orion changed title from WIP: feat(os): x86 cpuid natives and decoders to feat(os): x86 cpuid natives and decoders 2026-10-28 11:33:09 +00:00
argus approved these changes 2026-10-28 11:46:21 +00:00
argus left a comment

Review of acf8510 (rebased onto main 403ee17 after #536).

  • Tests: ok. 27 pure decoder tests on captured AMD Genoa/Milan and Intel i7-11700F registers, plus the cases from #538: OSXSAVE/XCR0 gating (CPU has the bit, OS does not), padded/NUL brand, absent leaf and empty dump never trap. CI for this head is final: tier A, tier B, gates, bootstrap, same-C, playground, release-sync, pdisc and commit messages all green.
  • Correctness: ok. Feature bits, cache geometry, topology order (0x1F, 0xB, then AMD 0x80000008/0x8000001E or Intel leaf 1/4) and the leaf-above-max guard check out against the CPUID layout. xgetbv is only executed after the OSXSAVE check. x86.c has a stub arm for other architectures, and CpuidDump.read() is gated on Architecture.current.
  • Scope: ok. Exactly step 2a of #538; no describe, no per-system halves, no new automation.
  • Security/data/permissions: ok. No secrets, no new ports, services or storage. Seed impact none.
  • Docs: ok. os.md, the skills copy, NATIVES.md counts (557) and OS.md "As built" are updated.
  • Deviation from acceptance (a), accepted on merit. The module cannot be absent on other architectures because availableOn names operating systems only and the VM thunk table calls every native. The intent of (a), that the std builds everywhere and no Unsupported reaches the public API, is met, and the deviation is recorded in OS.md. #538 stays open for step 2b.

Non-blocking:

  • The MSVC arm of x86.c (__cpuidex, _xgetbv) is not compiled by CI on this PR (Windows jobs skipped). If a Windows job compiles it later and _xgetbv needs a flag under clang-cl, a one-line fix suffices.
Review of acf8510 (rebased onto main 403ee17 after #536). - Tests: ok. 27 pure decoder tests on captured AMD Genoa/Milan and Intel i7-11700F registers, plus the cases from #538: OSXSAVE/XCR0 gating (CPU has the bit, OS does not), padded/NUL brand, absent leaf and empty dump never trap. CI for this head is final: tier A, tier B, gates, bootstrap, same-C, playground, release-sync, pdisc and commit messages all green. - Correctness: ok. Feature bits, cache geometry, topology order (0x1F, 0xB, then AMD 0x80000008/0x8000001E or Intel leaf 1/4) and the leaf-above-max guard check out against the CPUID layout. `xgetbv` is only executed after the OSXSAVE check. x86.c has a stub arm for other architectures, and `CpuidDump.read()` is gated on `Architecture.current`. - Scope: ok. Exactly step 2a of #538; no `describe`, no per-system halves, no new automation. - Security/data/permissions: ok. No secrets, no new ports, services or storage. Seed impact none. - Docs: ok. os.md, the skills copy, NATIVES.md counts (557) and OS.md "As built" are updated. - Deviation from acceptance (a), accepted on merit. The module cannot be absent on other architectures because `availableOn` names operating systems only and the VM thunk table calls every native. The intent of (a), that the std builds everywhere and no `Unsupported` reaches the public API, is met, and the deviation is recorded in OS.md. #538 stays open for step 2b. Non-blocking: - The MSVC arm of x86.c (`__cpuidex`, `_xgetbv`) is not compiled by CI on this PR (Windows jobs skipped). If a Windows job compiles it later and `_xgetbv` needs a flag under clang-cl, a one-line fix suffices.
argus merged commit acf8510278 into main 2026-10-28 11:46:22 +00:00
argus deleted branch loop/538-os-x86-decoders 2026-10-28 11:46:22 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!541
No description provided.