Skip to content

Add PowerPC 64-bit coroutine context switching - #327

Merged
lalinsky merged 2 commits into
mainfrom
ppc64-coroutine-support
Feb 19, 2026
Merged

lalinsky merged 2 commits into
mainfrom
ppc64-coroutine-support

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Summary

  • Add powerpc64/powerpc64le coroutine context switching using inline assembly
  • Uses bcl 20,31 idiom to capture resume address without polluting the link stack predictor
  • Saves sp (r1), fp (r31), and pc in context struct; all other registers clobbered
  • Stack trace test skipped on ppc64 for now (integer overflow in Zig 0.15 stack trace dumping)

Test plan

  • Cross-compile and test via QEMU: ./check.sh --target powerpc64le-linux --qemu -Dbackend=epoll
  • All 367 tests pass, 1 skipped (stack trace)

Add powerpc64/powerpc64le support for coroutine context switching using
inline assembly. Uses bcl 20,31 to capture the resume address without
polluting the link stack predictor. Saves sp (r1), fp (r31), and pc in
the context struct, with all other registers marked as clobbered.

Stack trace test is skipped on ppc64 for now due to integer overflow in
Zig 0.15's stack trace dumping.
@coderabbitai

coderabbitai Bot commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds PowerPC 64-bit (powerpc64 / powerpc64le) support to the coroutine subsystem: new Context variants, PPC64-specific context init/switch/entry assembly paths, minor docs updates, and CI matrix entry for powerpc64le.

Changes

Cohort / File(s) Summary
Documentation
README.md, docs/index.md
Added powerpc64 to supported architectures list and reordered entries (loongarch64 before powerpc64).
Coroutine implementation
src/coro/coroutines.zig
Added Context variants for .powerpc64 and .powerpc64le; implemented PPC64 context initialization, save/restore assembly path (general regs + FP/SIMD + memory flags), and PPC64 coroutine entry trampoline; adjusted tests to skip PPC64 stack-trace cases. Review attention: ABI/register/clobber correctness and stack_alignment.
CI workflow
.github/workflows/test.yml
Added powerpc64le-linux target to the test matrix (qemu enabled, epoll/poll backends).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

PowerPC wakes, registers line up neat,
Stacks align, a trampoline takes the seat.
Coroutines hop where new bits play,
CI queues a qemu-run away. 🐧✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add PowerPC 64-bit coroutine context switching' directly and clearly describes the main change—introducing powerpc64/powerpc64le support to the coroutine context switching mechanism.
Description check ✅ Passed The description is well-related to the changeset, detailing the implementation approach (inline assembly, bcl idiom), what's stored in the context struct, known limitations (stack trace test skip), and the test results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ppc64-coroutine-support

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
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/coro/coroutines.zig (2)

1360-1361: Skip is unconditional — consider gating on Zig version.

The skip applies to all Zig versions, but the PR description says the overflow is in Zig 0.15's stack trace dumping. Other version-specific branches in this file already check builtin.zig_version.minor < 16. If Zig 0.16 fixes this, you'd silently skip the test forever.

Not blocking — ppc64 is brand new and you can revisit when 0.16 lands.

Possible version-gated skip
-    if (builtin.cpu.arch == .powerpc64 or builtin.cpu.arch == .powerpc64le) return error.SkipZigTest;
+    if ((builtin.cpu.arch == .powerpc64 or builtin.cpu.arch == .powerpc64le) and
+        builtin.zig_version.major == 0 and builtin.zig_version.minor < 16) return error.SkipZigTest;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/coro/coroutines.zig` around lines 1360 - 1361, The unconditional skip for
PowerPC in coroutines.zig should be gated by Zig version; change the condition
that currently returns error.SkipZigTest when builtin.cpu.arch == .powerpc64 or
.powerpc64le to only do so when the Zig minor version is less than 16 (check
builtin.zig_version.minor < 16) so the test is not permanently skipped; update
the condition around the return error.SkipZigTest to combine the CPU check with
the Zig version check.

805-878: FYI: f0–f31 and v0–v31 overlap with vs0–vs63 — listing all three is redundant but safe.

On PPC64, vs0–vs31 alias f0–f31, and vs32–vs63 alias v0–v31. Declaring all three sets as clobbered is conservative but harmless — same approach as x86 listing both zmm and mm. Not asking you to change it, just noting it for future reference.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/coro/coroutines.zig` around lines 805 - 878, The clobber list redundantly
lists overlapping registers (f0–f31 and v0–v31 overlap with vs0–vs63 on PPC64);
simplify by removing the explicit .f0–.f31 and .v0–.v31 entries and keep the
.vs0–.vs63 range plus the unique entries (.acc0–.acc7, .acc, .spefsc) so the
clobber set is accurate and non-redundant (look for the block that currently
enumerates .f0.. .f31, .v0.. .v31, .vs0.. .vs63 and update it to only include
.vs0.. .vs63 and the non-aliased symbols).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/coro/coroutines.zig`:
- Around line 1360-1361: The unconditional skip for PowerPC in coroutines.zig
should be gated by Zig version; change the condition that currently returns
error.SkipZigTest when builtin.cpu.arch == .powerpc64 or .powerpc64le to only do
so when the Zig minor version is less than 16 (check builtin.zig_version.minor <
16) so the test is not permanently skipped; update the condition around the
return error.SkipZigTest to combine the CPU check with the Zig version check.
- Around line 805-878: The clobber list redundantly lists overlapping registers
(f0–f31 and v0–v31 overlap with vs0–vs63 on PPC64); simplify by removing the
explicit .f0–.f31 and .v0–.v31 entries and keep the .vs0–.vs63 range plus the
unique entries (.acc0–.acc7, .acc, .spefsc) so the clobber set is accurate and
non-redundant (look for the block that currently enumerates .f0.. .f31, .v0..
.v31, .vs0.. .vs63 and update it to only include .vs0.. .vs63 and the
non-aliased symbols).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.github/workflows/test.yml (1)

74-74: LGTM — consistent with the existing QEMU matrix pattern.

The new entry follows the exact same shape as the other QEMU cross-compile targets: ubuntu-latest, qemu: true, backends: 'epoll poll' (no io_uring, which is correct for QEMU user-mode). The powerpc64le-linux target triple is the right form for Zig.

One thing worth flagging: the AI summary notes that src/coro/coroutines.zig adds both .powerpc64 (big-endian) and .powerpc64le Context variants. If big-endian PPC64 support is code-complete, a corresponding powerpc64-linux QEMU entry would give it actual CI coverage. If it's intentionally deferred (e.g., no reliable BE QEMU image or untested), that's fine — just worth documenting.

➕ Optional: add big-endian coverage if the BE path is ready
          - { os: ubuntu-latest, target: powerpc64le-linux, qemu: true, backends: 'epoll poll' }
+         - { os: ubuntu-latest, target: powerpc64-linux, qemu: true, backends: 'epoll poll' }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/test.yml at line 74, The workflow adds a QEMU matrix entry
for powerpc64le but the repo also added .powerpc64 (big-endian) and .powerpc64le
Context variants in src/coro/coroutines.zig; either add a corresponding QEMU CI
matrix entry for the big-endian target (target: powerpc64-linux, os:
ubuntu-latest, qemu: true, backends: 'epoll poll') so BE code gets tested, or
explicitly document in the workflow or README why powerpc64 (big-endian) is not
included in CI (e.g., no BE QEMU image or untested) so the disparity between
.powerpc64 and CI coverage is clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/test.yml:
- Line 74: The workflow adds a QEMU matrix entry for powerpc64le but the repo
also added .powerpc64 (big-endian) and .powerpc64le Context variants in
src/coro/coroutines.zig; either add a corresponding QEMU CI matrix entry for the
big-endian target (target: powerpc64-linux, os: ubuntu-latest, qemu: true,
backends: 'epoll poll') so BE code gets tested, or explicitly document in the
workflow or README why powerpc64 (big-endian) is not included in CI (e.g., no BE
QEMU image or untested) so the disparity between .powerpc64 and CI coverage is
clear.

@lalinsky
lalinsky merged commit f291dfc into main Feb 19, 2026
18 checks passed
@lalinsky
lalinsky deleted the ppc64-coroutine-support branch February 19, 2026 18:35
@coderabbitai coderabbitai Bot mentioned this pull request Apr 16, 2026
1 of 4 tasks
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.

1 participant