Files
aji/tests/conformance/phase5/run/atomic_cmpxchg.air
T
dev 4242132b2a Phase 5: atomics through every layer (RFC 0015)
AIR: linear atomic<T> (AtomicScalar), atomic.new/take/load/store/RMW/
cmpxchg (two results)/fence with explicit orderings; feature atomics
published. Verifier: ordering tables (E4201), ordinary access (E4202),
effects [atomic] / [atomic, atomic.weak], linearity, take while lent
(E4101, also for mutex.take). Interpreter: timestamped message machine
(src/interp/weak.zig); views travel through spawn/join, channels, mutexes,
close and cancel; seq_cst reads the latest message and programs without
weak reads make no extra draw (existing records unchanged). aji explore:
exhaustive exploration that branches only before visible operations.
Litmus: 20/20 tests give exactly the oracle's sets; differential test
(1500 random programs) found no unsound outcome. .aji layer 10, Quick
Reference atomics, source coverage 67/67, audit report atomic_operations.
AIR bundle +5.9 %, QUICK.md +0.5k.
2026-10-06 08:05:01 +03:00

28 lines
753 B
LLVM

; A strong compare-exchange returns the old value and whether it exchanged; a non-seq_cst one needs atomic.weak.
; expect: run
; result: 14
; phase: 5
; spec: docs/spec/04-concurrency-and-atomics.md
module test.atomic_cmpxchg
air 0
lang 0.1
features [atomics, effects, ownership]
fn @main() -> u64
effects [atomic, atomic.weak]
entry:
%five = const.u64 5
%c = atomic.new %five
%r = borrow.ref %c
%seven = const.u64 7
%old1, %ok1 = atomic.cmpxchg.seq_cst.seq_cst %r, %five, %seven
assert %ok1
%old2, %ok2 = atomic.cmpxchg.acq_rel.acquire %r, %five, %five
%no = const.bool true
%failed = xor.bool %ok2, %no
assert %failed
borrow.end %r
%v = atomic.take %c
%sum = add.checked.u64 %v, %old2
ret %sum