Skip to content

feat(sync/atomic): riscv64 arms#309

Merged
octalide merged 1 commit into
devfrom
feat/308-riscv64-atomic
Jun 27, 2026
Merged

feat(sync/atomic): riscv64 arms#309
octalide merged 1 commit into
devfrom
feat/308-riscv64-atomic

Conversation

@octalide

Copy link
Copy Markdown
Collaborator

Closes #308

Adds riscv64 implementations for all 8 atomic ops in src/sync/atomic.mach, mirroring the existing x86_64/aarch64 arms. Uses the RISC-V A extension with .aqrl ordering for sequential consistency:

op riscv64 sequence
load full fence brackets a plain aligned ld
store amoswap.d.aqrl zero, v, (ptr) (discards old)
cas lr.d.aqrl / sc.d.aqrl retry loop
fetch_add amoadd.d.aqrl
fetch_sub neg then amoadd.d.aqrl (no amosub)
exchange amoswap.d.aqrl
fence fence
spin_hint pause

Additive and comptime-gated, so x86_64/aarch64 are unaffected.

Verification

  • x86_64: mach test . -> 563/563 pass (all 12 atomic tests included).
  • riscv64: built a consumer exercising all 8 ops (load/store/exchange, cas success+fail, fetch_add, fetch_sub, fetch_add-negative, fence, spin_hint) and ran it under qemu-riscv64 -> exit 0 (every assertion passed). Each instruction sequence was also unit-verified standalone under qemu.

Requires a mach with RV64A inline-asm support (mach#1668, on mach dev); CI seeds from the latest mach release, so this goes green once the riscv64 batch ships in v2.9.0.

Add riscv64 implementations for all 8 atomic ops, mirroring the
x86_64/aarch64 arms:
- load: full FENCEs bracket a plain aligned ld (seq-cst load)
- store: amoswap.d.aqrl discarding the old value (seq-cst store)
- cas: lr.d.aqrl/sc.d.aqrl retry loop
- fetch_add: amoadd.d.aqrl
- fetch_sub: neg then amoadd.d.aqrl (no amosub)
- exchange: amoswap.d.aqrl
- fence: fence
- spin_hint: pause

Each op uses the RISC-V A extension with .aqrl ordering for sequential
consistency. Additive and comptime-gated, so x86_64/aarch64 are unaffected.

Closes #308
@octalide octalide marked this pull request as ready for review June 27, 2026 04:57
@octalide octalide merged commit 8f40ddf into dev Jun 27, 2026
2 checks passed
@octalide octalide deleted the feat/308-riscv64-atomic branch June 27, 2026 05:03
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.

sync/atomic: riscv64 arms (blocked on mach RV64A inline-asm support)

1 participant