atomics A.3b: real swap (xchg) + fence emission + unit test (green)

emitAtomicRmw xchg arm (swap) and emitAtomicFence (LLVMBuildFence) now real.
examples/1703 (swap old=7/now=42, 'atomicrmw xchg') + 1704 (fence release/acquire/
seq_cst) green. Unit test 'emit: atomic swap (xchg) + fence'. Stream A
(atomics) is feature-complete: load/store, RMW (add/sub/and/or/xor/min/max),
compare_exchange[_weak], swap, fence. Suite green (721/0).
This commit is contained in:
agra
2026-06-20 13:51:36 +03:00
parent fca4304f83
commit b65544a68c
9 changed files with 43 additions and 20 deletions

View File

@@ -416,14 +416,6 @@ pub const Ops = struct {
}
pub fn emitAtomicRmw(self: Ops, instruction: *const Inst, a: AtomicRmw) void {
// A.3a lock: the new `xchg` (swap) kind BAILS until A.3b. The other RMW
// kinds (A.1) keep working.
if (a.kind == .xchg) {
std.debug.print("error: atomic swap (xchg) LLVM emission not yet implemented (Stream A, A.3b)\n", .{});
self.e.comptime_failed = true;
self.e.mapRef(c.LLVMGetUndef(self.e.toLLVMType(if (instruction.ty == .void) .i64 else instruction.ty)));
return;
}
const ptr = self.e.resolveRef(a.ptr);
const val = self.e.resolveRef(a.operand);
const ptr_kind = c.LLVMGetTypeKind(c.LLVMTypeOf(ptr));
@@ -475,11 +467,8 @@ pub const Ops = struct {
}
// Standalone memory fence — void result, no address. singleThread = 0.
// A.3a lock: BAILS until A.3b wires LLVMBuildFence.
pub fn emitAtomicFence(self: Ops, a: AtomicFence) void {
_ = a;
std.debug.print("error: atomic fence LLVM emission not yet implemented (Stream A, A.3b)\n", .{});
self.e.comptime_failed = true;
_ = c.LLVMBuildFence(self.e.builder, llvmOrdering(a.ordering), 0, "");
self.e.advanceRefCounter();
}