interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

Prototype scan-resistant DeepSeek expert slabs and an asynchronous file-read ring

open a324505d903f32d3 opened 2026-11-20 by z6MktvMGgxSZ19NQ...

2 commits · 9 files · 50313 bytes. Base 535d83f71c0ffa08f302ffe7dba42b4bb7d104c4. Applied head fc390f8bae66bac3ab21077e015d292707e98218: the last commit this forge's own git am made on the base. It is in no repository; the owner applies the patch by hand.

Pure seeded OM-2 implementation of the protected and FIFO expert slabs, the single-owner asynchronous read ring, and an offline layer-zero NVFP4 packer for DeepSeek-V4.1-Flash. The current transport uses a buffered Linux file worker on one AArch64 host. This patch can be reviewed independently of the GB10 kernels and the final-head executor.

The tested public source is 89e206d01aee295b274233e1299f47929304227e on codex/dsv41-cache-layout. The proposal has identical cache sources and builds byte-identical pack, replay and contract executables. The researcher archive SHA-256 is 15707fb30adfa432884ddc8d7722d302a9e5868423c365c666b34de933393159.

Single-Spark AArch64 host replay, with checkpoint revision 314113f8a7dadb388215396ba5fbee2c610a04d6 and shard 3 SHA-256 e1281f85d0ce4a3dfb63d41926fc4a47fa71f36ba20992e3597e702ead49d4c9. Commands from the unpacked archive:

```sh
sh seed/omega-from-seed.sh
sh om/gpu/dsv41/cache/build.sh rebuilt
(cd rebuilt && sha256sum -c ../qualification/binaries.sha256)
python3 -O om/gpu/dsv41/cache/check.py --all-experts "$HOME/models/deepseek-v4.1-flash-314113f8/model-00003-of-00048.safetensors" rebuilt
```

```text
PASS omc fixpoint 210c52566e782cf15ece6e478d45bfb67f1ad338f29e41546dad9b6c4f85b54c
contract: OK
pack: OK
replay: OK
PASS all 384 routed experts, 7219445760 payload bytes
PASS 8 packed layer-0 experts, 11 exact demand payloads
PASS FIFO wrap, first two returning protected hits, replacement on third consecutive turn
PASS ring saturation, out-of-order retirement, stale completion, lease and short/error controls
```

Both proposal and public staging passed tests/gates/run.sh evidence-immutable and tests/gates/run.sh zero-disk-secrets. The seeded declarations and byte-offset table are in om/gpu/dsv41/cache/slabs.om and README.md. The run measures weight-byte preservation and bounded admission behavior. End-to-end logit/token parity, the three-hour trace, post-shift serving throughput and device-level random-read improvement remain NOT_RUN.

Independent CPU-only review passed at the tested commit. It reproduced the original four failures and verified the corrected behavior under optimized Python, a partial header read with EINTR, ring wrap and stale completion, and an unavailable speculative key.

Apply it

git checkout -b patch-a324505d903f32d3 535d83f71c0ffa08f302ffe7dba42b4bb7d104c4
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/a324505d903f32d3.patch | git am

Raw patch (mbox) · Diff

Signature

The author's key did:key:z6MktvMGgxSZ19NQkrvXG6aRzjbFA1yBa2KJmmA9pSTJCiEZ signed this statement with ssh-keygen -Y sign -n interplane-patch; the forge checked the signature before it kept the patch. The lines are: format, repository, base, SHA-256 of the mbox, SHA-256 of the title, a line feed and the description.

interplane-patch 1
drakestapleton/omega-mv
535d83f71c0ffa08f302ffe7dba42b4bb7d104c4
42e606093bc97fc60e363167aabafc99f642887b1fd5dea886a88457faea6d12
2267b1d2f706cebbe06ef0281b3d78258647f0212a6149747b2128ac323dc6ed
-----BEGIN SSH SIGNATURE-----
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAg1vQ1KtWtuW5PISxEahQt4AgcBw
syuwQ4l2Qd7RBTSZ4AAAAQaW50ZXJwbGFuZS1wYXRjaAAAAAAAAAAGc2hhNTEyAAAAUwAA
AAtzc2gtZWQyNTUxOQAAAEBRZf6Uh3W7hMrONjMlJH9DKekVzhGekF/mP5YSNeJEVhvzGG
tHO3xqQRcu792i/JfjgckqVMrvfQl9vQLcTFYJ
-----END SSH SIGNATURE-----

Changes

diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index be752b1ee196c64911a6e41e6701b956e7f6f22e..91bf7b37c261a0d12cd9072450127dce6666b1dc 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -379,3 +379,4 @@ Update this table in the same commit as the work it credits.
 | Codex (under Drake Stapleton's direction) | Converted OSC handle provenance, stale read/write/free decisions, branch snapshots and loop settlement to seeded Omega. |
 | Codex (under Drake Stapleton's direction) | Converted OSC owner and borrow snapshots, rollback of fresh borrows, branch joins and move replay to seeded Omega. |
 | Codex (under Drake Stapleton's direction) | Migrated OSC statement reachability, return-path analysis, IR block layout and partition validation, and definite-assignment propagation to seeded Omega. |
+| Codex (under Drake Stapleton's direction) | Built the seeded DeepSeek expert slab and asynchronous file-read ring prototype, layer-0 packer and byte-exact detour replay. |
diff --git a/FOLDERS.md b/FOLDERS.md
index d7c28d8721ad6a4fafccfff89b35df248e1af268..0901f11bb01ba6e3c5d9f0bd8cfb87e936477a98 100644
--- a/FOLDERS.md
+++ b/FOLDERS.md
@@ -551,3 +551,7 @@ Trinary Doctrine wake-signal tool (`trit`, T-002) in seeded OM-2 sharing `tools/
 ## `seed/omc/tests/struct-bool/`
 
 Boolean struct-field execution regressions, exact expected outcomes, scalar controls and deliberate broken-compiler controls. Run by the seeded host gate. Results are kept in unique build directories.
+
+## `om/gpu/dsv41/cache/`
+
+Seeded OM-2 expert slab and I/O ring records, the DeepSeek V4.1 Flash layer-0 packer, a bounded two-zone cache replay, and its independent checkpoint-byte checks.
diff --git a/om/gpu/dsv41/cache/README.md b/om/gpu/dsv41/cache/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..dc829bd95f452e46e3c1405db2aa3a6a0c1e9ad0
--- /dev/null
+++ b/om/gpu/dsv41/cache/README.md
@@ -0,0 +1,65 @@
+# DeepSeek V4.1 Flash expert slab and read-ring prototype
+
+This seeded OM-2 prototype reads exact routed-expert bytes from the first decoder layer of the original DeepSeek checkpoint. One scheduler owns two protected slots, two FIFO scratch slots and a two-entry I/O ring. A child process uses buffered Linux `pread` to populate a fixed shared mapping while the scheduler accepts lookahead requests. The consumer returns the actual expert payload on each demand. The prototype runs on AArch64 Linux without opening the GPU.
+
+## Record ABI
+
+[slabs.om](slabs.om) defines four 64-byte OM-2 layouts. Every field is little-endian. Table bounds and arithmetic use the local rank's counts. Byte offsets are relative to the local arena or the open pack file.
+
+| Record | Fields in offset order | Ownership |
+| --- | --- | --- |
+| `slabtab` | 0 ABI u32, 4 protected count u32, 8 scratch count u32, 12 stride u32, 16 FIFO index u32, 20 active domain u32, 24 candidate domain u32, 28 consecutive-turn count u32, 32 last turn u64, 40 pack epoch u64, 48 arena span u64, 56 reserved u64 | Scheduler. Protected slots occupy the first interval. Scratch slots follow it. |
+| `slab` | 0 state u32, 4 expert key u32, 8 generation u64, 16 lease count u32, 20 zone u32, 24 destination offset u64, 32 length u32, 36 reserved u32, 40 epoch u64, 48 submission ticket u64, 56 reserved u64 | Scheduler publishes EMPTY (0), LOADING (1), then READY (2) after an exact-length completion. |
+| `nvqueue` | 0 ABI u32, 4 capacity u32, 8 entry bytes u32, 12 reserved u32, 16 submitted u64, 24 retired u64, 32–63 reserved | Single producer. Tickets begin at one. Outstanding count is submitted minus retired. Ticket `n` occupies entry `(n-1) % capacity`. Retire the contiguous completed prefix. |
+| `nvreq` | 0 ticket u64, 8 generation u64, 16 key u32, 20 slot u32, 24 file offset u64, 32 arena offset u64, 40 requested bytes u32, 44 completed bytes u32, 48 status i32, 52 phase u32, 56 pack-file ID u32, 60 reserved u32 | Scheduler sends phase 1. The worker returns the identity, byte count and status. The owner validates the ticket, slot, generation and extents before marking phase 2. |
+
+Zero-initialize the record storage before opening a session. Use ABI 1 and 64-byte descriptor strides. Use `layer * 384 + expert` as the logical key. The replay accepts layer 0. File ID 0 denotes its one verified immutable pack. Positive tickets and generations are never recycled within their owner lifetime. A leased slab stays in place through consumer completion. A failed or short read leaves the slab empty and terminates the replay. A fully occupied ring drops a speculative request. A demand waits and loads its exact key.
+
+A scratch miss uses `protected_count + fifo` and advances the FIFO only after successful submission. A protected hit keeps its slot across a one-turn detour, even after the scratch FIFO wraps. Three consecutive votes for the same new domain authorize a pack change. A repeated turn ID contributes once, a gap breaks the streak, and an unknown or current-domain vote clears it. Committing drains outstanding I/O and checks protected leases before advancing the epoch. Old protected slots then become invisible to lookup. Filling the new pack is explicit and can stall. The replay starts in domain zero and accepts domain IDs from its caller.
+
+## Source bytes and budgets
+
+The pinned layer-0 header lists three 5,898,240-byte packed weight tensors and three 368,640-byte scale tensors per expert. The expert slab is **18,800,640 bytes (17.9296875 MiB)**, exactly 4,590 pages of 4 KiB. The original header places the three matrices together and the three scale arrays together at a separate offset. Within each group, expert IDs are in decimal-string order. The packer verifies the source file size and SHA-256 of its JSON header before using that ordering. The qualification program first verifies the SHA-256 of the entire source shard. [Pinned release](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash/tree/314113f8a7dadb388215396ba5fbee2c610a04d6)
+
+The 4 KiB pack header starts with ASCII `DXP1`, version 1, expert count and slab stride as four u32s. An ordered array of u32 expert IDs follows at byte 16. The body begins at byte 4,096. Slab `i` contains W1, W2, W3 weights, then W1, W2, W3 scales, byte-for-byte in checkpoint order. A profiler can supply co-activated experts adjacently. The compact prototype has no learned classifier. The pack must be immutable and its complete checksum verified before reuse across a trust boundary.
+
+| Deployment assumption, decimal GB | Protected slots | FIFO slots |
+| --- | ---: | ---: |
+| 1 Spark with 70 GB / 18 GB | 3,723 | 957 |
+| Each of 2 Sparks with 82 GB / 13 GB | 4,361 | 691 |
+
+These are payload capacities. Metadata and I/O buffers require additional space. Two rank-local protected arenas hold at most 8,722 distinct complete experts, about 56.8% of 15,360, when ranks own disjoint expert sets. Replicated experts reduce coverage. Zone 1, Zone 4, KV capacity and Engram row admission require their own measured budgets. CPU and GPU activity share the same physical memory bandwidth.
+
+Keep neuron order for the strict-parity baseline. A later neuron-sliced pack has to permute W1/W3 rows with W2 columns and preserve scale-group membership, nibble order and the reduction order. All contributions must reach the original accumulation positions. Bit equality needs a matched arithmetic path and matched RNG state.
+
+## Researcher replay
+
+From the repository root on AArch64 Linux, with the original shard available locally:
+
+```sh
+sh seed/omega-from-seed.sh
+sh om/gpu/dsv41/cache/build.sh build/dsv41-cache
+python3 om/gpu/dsv41/cache/check.py --all-experts /path/to/model-00003-of-00048.safetensors build/dsv41-cache
+```
+
+The full-layer check streams all 384 experts through the packer and compares every slab with the six source tensor extents. The detour replay then uses eight selected experts. For an arbitrary layer-0 routing trace, include all 384 IDs in the pack. A demand for an unlisted ID ends the replay before emitting any substitute. A speculative hint for a valid unlisted layer-0 expert is dropped.
+
+To build an ordered pack for a lane, pass distinct expert IDs as arguments. Publish the output only after the command exits successfully and its checksum has been recorded.
+
+```sh
+build/dsv41-cache/pack /path/to/model-00003-of-00048.safetensors 0 383 12 2 103 4 256 5 > layer0.pack
+build/dsv41-cache/replay layer0.pack < events.bin > demands.bin
+```
+
+Events are eight bytes, `<u32 opcode, u32 value>`. Opcodes 1, 2 and 3 warm a protected slot, demand an exact expert, and offer a speculative scratch read. Opcode 4 records the next turn's domain vote. Opcode 5 commits the specified eligible domain. Each demand emits `<u32 key, u8 already_ready, u8 zone, u16 zero>` and the complete slab payload. The ready bit for a speculative load depends on when its completion arrives. Output bytes for a given expert are independent of arrival order. Domain classification, learned lookahead and QMD launch policy are outside this replay.
+
+## Falsification gates
+
+| Claim | Evidence required |
+| --- | --- |
+| Byte-identical inference | Run identical token IDs through a non-evicting and caching executor at the same checkpoint precision, arithmetic order, sampling settings and RNG seed. Compare every logit bit and sampled ID for 128 tokens. Compare a higher-precision reference separately with a stated tolerance. This prototype checks the packed and delivered weight bytes. |
+| Detour immunity | Replay recorded route IDs and domain votes from the three-hour workload. Pair the first returning token with its no-detour counterfactual, and count protected hits, total requests and protected evictions separately. The supplied fixture covers one scratch wrap and the first return to two protected keys. |
+| Sustained shift | Record the turn and epoch on commit. The fixture exercises the three-turn gate. Compare production tokens/s against the same run cold-booted in the new domain, including the pack-fill period and reporting steady state separately. |
+| NVMe efficiency | Use the same route trace, usable byte capacity, initial state and storage-cache conditions for LRU and the proposed policy. Count device-level random 4 KiB reads, bytes per token, and token latency. Logical contiguous file extents can still fragment on the physical device. Buffered read calls cannot establish a threefold device IOPS reduction. |
+
+The ring is a scheduler-to-I/O-worker ABI. Connecting it to an io_uring or native NVMe submission/completion backend requires registered buffers, block alignment, visibility fences, cancellation/drain semantics and measured overlap on the target. DoMoE describes prefill domain matching, and APEX describes confidence-based prefetch before attention. The two-to-four-layer horizon is an experiment parameter. [DoMoE](https://ijcai.org/proceedings/2026/657) · [APEX](https://arxiv.org/abs/2608.11688)
diff --git a/om/gpu/dsv41/cache/build.sh b/om/gpu/dsv41/cache/build.sh
new file mode 100644
index 0000000000000000000000000000000000000000..708d481fedbf8fd5e470e8d067414b2bbff30bb9
--- /dev/null
+++ b/om/gpu/dsv41/cache/build.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+set -eu
+out=${1:?usage: sh om/gpu/dsv41/cache/build.sh OUTPUT_DIRECTORY}
+src=om/gpu/dsv41/cache
+mkdir -p "$out"
+tmp=$(mktemp -d "$out/cache.XXXXXX")
+trap 'rm -rf "$tmp"' EXIT
+( echo om2; cat seed/ng/sha256.om "$src/pack.om" ) > "$tmp/pack-input.om"
+cat "$src/slabs.om" "$src/replay.om" > "$tmp/replay-input.om"
+cat "$src/slabs.om" "$src/contract.om" > "$tmp/contract-input.om"
+for name in pack replay contract; do
+    seed/out/omc < "$tmp/$name-input.om" > "$tmp/$name"
+    chmod +x "$tmp/$name"
+done
+"$tmp/contract"
+mv "$tmp/pack" "$tmp/replay" "$tmp/contract" "$out/"
diff --git a/om/gpu/dsv41/cache/check.py b/om/gpu/dsv41/cache/check.py
new file mode 100644
index 0000000000000000000000000000000000000000..12dd593ba1970a60e6949c28732a41f3876a3bcb
--- /dev/null
+++ b/om/gpu/dsv41/cache/check.py
@@ -0,0 +1,133 @@
+"""Independent single-layer byte oracle. Uses the released safetensors header."""
+import argparse
+import hashlib
+import json
+import struct
+import subprocess
+import tempfile
+from pathlib import Path
+
+SHARD_HASH = "e1281f85d0ce4a3dfb63d41926fc4a47fa71f36ba20992e3597e702ead49d4c9"
+EXPERT_BYTES = 18_800_640
+IDS = (0, 383, 12, 2, 103, 4, 256, 5)
+WARM, DEMAND, PREFETCH, TURN, COMMIT = range(1, 6)
+
+
+def require(condition, message):
+    if not condition:
+        raise ValueError(message)
+
+
+def events(records):
+    return b"".join(struct.pack("<II", *record) for record in records)
+
+
+def read_experts(shard, ids):
+    with shard.open("rb") as f:
+        if hashlib.file_digest(f, "sha256").hexdigest() != SHARD_HASH:
+            raise ValueError("expected pinned original shard 3")
+        f.seek(0)
+        hlen, = struct.unpack("<Q", f.read(8))
+        header = json.loads(f.read(hlen))
+        digests = {}
+        for expert in ids:
+            sha = hashlib.sha256()
+            total = 0
+            for kind in ("weight", "scale"):
+                for projection in ("w1", "w2", "w3"):
+                    lo, hi = header[f"layers.0.ffn.experts.{expert}.{projection}.{kind}"]["data_offsets"]
+                    f.seek(8 + hlen + lo)
+                    payload = f.read(hi - lo)
+                    require(len(payload) == hi - lo, f"short tensor read for expert {expert}, {projection}.{kind}")
+                    sha.update(payload)
+                    total += len(payload)
+            require(total == EXPERT_BYTES, f"unexpected payload size for expert {expert}")
+            digests[expert] = sha.digest()
+        return digests
+
+
+def rejected(command, data=b"", code=65):
+    result = subprocess.run(command, input=data, stdout=subprocess.DEVNULL, check=False)
+    if result.returncode != code:
+        raise AssertionError(f"expected exit {code}, got {result.returncode}")
+
+
+def check_whole_layer(command, ids, digests):
+    # The entire pack goes through a pipe so qualification does not require a second copy of the layer.
+    with subprocess.Popen([*command, *map(str, ids)], stdout=subprocess.PIPE) as proc:
+        try:
+            header = proc.stdout.read(4096)
+            require(struct.unpack_from("<4I", header) == (0x31505844, 1, len(ids), EXPERT_BYTES), "full-layer pack header mismatch")
+            require(struct.unpack_from(f"<{len(ids)}I", header, 16) == tuple(ids), "full-layer expert order mismatch")
+            for expert in ids:
+                block = proc.stdout.read(EXPERT_BYTES)
+                require(len(block) == EXPERT_BYTES and hashlib.sha256(block).digest() == digests[expert], f"full-layer bytes mismatch for expert {expert}")
+            require(proc.stdout.read(1) == b"", "trailing full-layer pack data")
+        finally:
+            proc.stdout.close()
+        if proc.wait() != 0:
+            raise RuntimeError("native full-layer pack failed")
+    print(f"PASS all {len(ids)} routed experts, {len(ids)*EXPERT_BYTES} payload bytes")
+
+
+def check(shard, binaries, scratch, whole_layer):
+    subprocess.run([binaries / "contract"], check=True)
+    all_ids = [*IDS, *(i for i in range(384) if i not in IDS)]
+    digests = read_experts(shard, all_ids if whole_layer else IDS)
+    pack = scratch / "layer0.pack"
+    cmd = [binaries / "pack", shard]
+    if whole_layer:
+        check_whole_layer(cmd, all_ids, digests)
+    with pack.open("xb") as f:
+        subprocess.run([*cmd, *map(str, IDS)], stdout=f, check=True)
+    with pack.open("rb") as f:
+        header = f.read(4096)
+        require(struct.unpack_from("<4I", header) == (0x31505844, 1, len(IDS), EXPERT_BYTES), "fixture pack header mismatch")
+        require(struct.unpack_from(f"<{len(IDS)}I", header, 16) == IDS, "fixture expert order mismatch")
+        for expert in IDS:
+            require(hashlib.sha256(f.read(EXPERT_BYTES)).digest() == digests[expert], f"fixture bytes mismatch for expert {expert}")
+        require(f.read(1) == b"", "trailing fixture pack data")
+    rejected([*cmd, "383", "383"], code=64)
+    rejected([*cmd, "384"], code=64)
+    replay = [binaries / "replay", pack]
+    route = [(WARM, 0), (WARM, 383), (DEMAND, 0), (TURN, 7), (PREFETCH, 33), (PREFETCH, 12), (PREFETCH, 2),
+             (DEMAND, 12), (DEMAND, 2), (DEMAND, 103), (DEMAND, 4), (DEMAND, 256), (DEMAND, 5),
+             (TURN, 0), (DEMAND, 0), (DEMAND, 383), (TURN, 7), (TURN, 7), (TURN, 7),
+             (COMMIT, 7), (WARM, 12), (WARM, 2), (DEMAND, 12), (DEMAND, 0)]
+    keys = [key for op, key in route if op == DEMAND]
+    result = scratch / "demands.bin"
+    with result.open("xb") as out:
+        subprocess.run(replay, input=events(route), stdout=out, check=True)
+    with result.open("rb") as f:
+        observations = []
+        for expert in keys:
+            key, hit, zone, pad = struct.unpack("<IBBH", f.read(8))
+            require(key == expert and pad == 0 and hit in (0, 1), f"invalid demand metadata for expert {expert}")
+            require(hashlib.sha256(f.read(EXPERT_BYTES)).digest() == digests[key], f"wrong demand payload for expert {key}")
+            observations.append((key, hit, zone))
+        require(f.read(1) == b"", "unexpected demand output")
+    require(observations[0] == (0, 1, 2), "initial protected expert missed")
+    require(observations[-4:] == [(0, 1, 2), (383, 1, 2), (12, 1, 2), (0, 0, 3)], f"detour return or pack switch mismatch: {observations[-4:]}")
+    require(all(zone == 3 for _, _, zone in observations[1:-4]), "detour expert entered the protected zone")
+    rejected(replay, events([(TURN, 7), (COMMIT, 7)]))
+    rejected(replay, events([(TURN, 7), (TURN, 7), (COMMIT, 7)]))
+    rejected(replay, events([(TURN, 7), (TURN, 0), (TURN, 7), (COMMIT, 7)]))
+    rejected(replay, events([(WARM, 12), (WARM, 12)]))
+    rejected(replay, events([(DEMAND, 6)]))
+    rejected(replay, b"\x02")
+    badpack = scratch / "short.pack"
+    badpack.write_bytes(header)
+    rejected([binaries / "replay", badpack])
+    print(f"PASS {len(IDS)} packed layer-0 experts, {len(keys)} exact demand payloads")
+    print("PASS FIFO wrap, first two returning protected hits, replacement on third consecutive turn")
+    print("PASS ring saturation, out-of-order retirement, stale completion, lease and short/error controls")
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument("shard", type=Path)
+    parser.add_argument("binaries", type=Path)
+    parser.add_argument("--all-experts", action="store_true", help="check all 384 layer-0 pack extents")
+    args = parser.parse_args()
+    with tempfile.TemporaryDirectory(prefix="dsv41-cache-") as path:
+        check(args.shard.resolve(), args.binaries.resolve(), Path(path), args.all_experts)
diff --git a/om/gpu/dsv41/cache/contract.om b/om/gpu/dsv41/cache/contract.om
new file mode 100644
index 0000000000000000000000000000000000000000..b74cd571c40c38b2dfb6108a369fe1b0d0a40f5b
--- /dev/null
+++ b/om/gpu/dsv41/cache/contract.om
@@ -0,0 +1,172 @@
+note Host-only controls for ownership, partial transfers, stale completions, ABA and turn hysteresis.
+fn exchange t edit slabtab q edit nvqueue a edit slab b edit slab x edit nvreq y edit nvreq to int
+request x 0 5 4096
+request y 1 6 18804736
+if not beginRead t q a x
+ret 11
+end
+if not beginRead t q b y
+ret 12
+end
+if freeEntry q
+ret 13
+end
+if complete a y 2 expertBytes 0
+ret 14
+end
+if not complete b y 2 expertBytes 0
+ret 15
+end
+if reap q y
+ret 16
+end
+if not complete a x 1 sub expertBytes 1 0
+ret 17
+end
+if ne acquire t a 5 0
+ret 18
+end
+if not reap q x
+ret 19
+end
+if not reap q y
+ret 20
+end
+if or reap q y complete b y 2 expertBytes 0
+ret 21
+end
+returnCode = lockCheck t q b x
+ret returnCode
+end
+fn lockCheck t edit slabtab q edit nvqueue s edit slab r edit nvreq to int
+lease = acquire t s 6
+if eq lease 0
+ret 23
+end
+request r 1 7 18804736
+if beginRead t q s r
+ret 24
+end
+if release s 6 add lease 1
+ret 25
+end
+if not release s 6 lease
+ret 26
+end
+if not beginRead t q s r
+ret 27
+end
+if complete s r 2 expertBytes 0
+ret 28
+end
+if not complete s r 3 expertBytes -5
+ret 29
+end
+if ne acquire t s 7 0
+ret 30
+end
+if not reap q r
+ret 31
+end
+ret 0
+end
+fn votes t edit slabtab to int
+if observe t 1 1
+ret 33
+end
+if observe t 1 1
+ret 34
+end
+if observe t 3 1
+ret 35
+end
+if observe t 4 noDomain
+ret 36
+end
+if observe t 5 2
+ret 37
+end
+if observe t 6 2
+ret 38
+end
+if not observe t 7 2
+ret 39
+end
+ret 0
+end
+fn testRing t edit slabtab q edit nvqueue to int
+if not cacheStart t 1 1
+ret 1
+end
+if not ringStart q 2
+ret 2
+end
+a = new uchar 64 0
+b = new uchar 64 0
+x = new uchar 64 0
+y = new uchar 64 0
+rc = exchange t q a b x y
+if ne rc 0
+ret rc
+end
+ret votes t
+end
+fn heldPack t edit slabtab q edit nvqueue s edit slab r edit nvreq table long to int
+request r 0 8 4096
+if not beginRead t q s r
+ret 40
+end
+if commitPack t q table
+ret 41
+end
+if not complete s r get r ticket expertBytes 0
+ret 42
+end
+if not reap q r
+ret 43
+end
+request r 0 9 18804736
+if beginRead t q s r
+ret 44
+end
+lease = acquire t s 8
+if eq lease 0
+ret 45
+end
+if ne mapwrite table 0 s 0 64 64
+ret 46
+end
+if commitPack t q table
+ret 47
+end
+if not release s 8 lease
+ret 48
+end
+if ne mapwrite table 0 s 0 64 64
+ret 49
+end
+if not commitPack t q table
+ret 50
+end
+if ne acquire t s 8 0
+ret 51
+end
+ret 0
+end
+fn main to int
+t = new uchar 64 0
+q = new uchar 64 0
+rc = testRing t q
+if ne rc 0
+ret rc
+end
+s = new uchar 64 0
+r = new uchar 64 0
+table = mapnew -1 0 128 3 33
+if le table 0
+ret 52
+end
+rc = heldPack t q s r table
+closed = mapdrop table
+ret rc
+end
diff --git a/om/gpu/dsv41/cache/pack.om b/om/gpu/dsv41/cache/pack.om
new file mode 100644
index 0000000000000000000000000000000000000000..2f250a6b7743439c0767578d4083ed188948c4b8
--- /dev/null
+++ b/om/gpu/dsv41/cache/pack.om
@@ -0,0 +1,181 @@
+note Layer-0 packer for the pinned DeepSeek V4.1 Flash release. Compose after seed/ng/sha256.om.
+text headerHash "71213f444f9c15a4af6dbcbddc36f7611542884ebb3aadef54de650071357449"
+global usedExpert uint 384
+global plan uint 384
+fn fillBytes fd int start ulong size ulong to bool
+pos = ulong 0
+while lt pos size
+n = pread fd sh_dat pos sub size pos long add start pos
+if eq n -4
+continue
+end
+if le n 0
+ret false
+end
+pos = add pos ulong n
+end
+ret true
+end
+fn putBytes size ulong to bool
+pos = ulong 0
+while lt pos size
+n = write 1 sh_dat pos sub size pos
+if eq n -4
+continue
+end
+if le n 0
+ret false
+end
+pos = add pos ulong n
+end
+ret true
+end
+fn checkShard fd int to bool
+if ne fseek fd 0 2 7389759032
+ret false
+end
+if not fillBytes fd 0 8
+ret false
+end
+headerSize = ulong 0
+for i ulong 8
+headerSize = or headerSize shl ulong get sh_dat i mul i 8
+end
+if ne headerSize 258136
+ret false
+end
+if not fillBytes fd 8 headerSize
+ret false
+end
+sh_all headerSize
+for i ulong 32
+b = uint get sh_dig i
+if ne sh_hexd shr b 4 get headerHash mul 2 i
+ret false
+end
+if ne sh_hexd and b 15 get headerHash add mul 2 i 1
+ret false
+end
+end
+ret true
+end
+fn idArg arg ulong to uint
+b = new uchar 4 0
+n = argread arg b 0 4
+if or le n 0 gt n 3
+ret 384
+end
+v = uint 0
+for j ulong ulong n
+c = uint get b j
+if or lt c 48 gt c 57
+ret 384
+end
+v = add mul v 10 sub c 48
+end
+ret v
+end
+note Decimal strings use lexicographic order in this verified header. Base 11 reserves zero for EOS.
+fn lexKey id uint to uint
+if lt id 10
+ret mul add id 1 121
+end
+if lt id 100
+ret add mul add div id 10 1 121 mul add rem id 10 1 11
+end
+a = mul add div id 100 1 121
+b = mul add rem div id 10 10 1 11
+ret add add a b add rem id 10 1
+end
+fn sourceRow id uint to ulong
+key = lexKey id
+row = ulong 0
+for i uint 384
+if lt lexKey i key
+row = add row 1
+end
+end
+ret row
+end
+fn emitExtent fd int base ulong size ulong to bool
+pos = ulong 0
+while lt pos size
+chunk = sub size pos
+if gt chunk 1048576
+chunk = 1048576
+end
+if not fillBytes fd add base pos chunk
+ret false
+end
+if not putBytes chunk
+ret false
+end
+pos = add pos chunk
+end
+ret true
+end
+fn store32 pos ulong v uint to void
+for j ulong 4
+put sh_dat add pos j uchar and shr v mul j 8 255
+end
+end
+fn emitPack fd int count uint to bool
+for i ulong 4096
+put sh_dat i 0
+end
+store32 0 0x31505844
+store32 4 1
+store32 8 count
+store32 12 18800640
+for i uint count
+store32 add 16 mul ulong i 4 get plan i
+end
+if not putBytes 4096
+ret false
+end
+for i uint count
+row = sourceRow get plan i
+if not emitExtent fd add 594986552 mul row 17694720 17694720
+ret false
+end
+if not emitExtent fd add 8273720 mul row 1105920 1105920
+ret false
+end
+end
+ret true
+end
+fn main to int
+if or lt argcnt 3 gt argcnt 386
+ret 64
+end
+count = sub uint argcnt 2
+for j uint count
+id = idArg ulong add j 2
+if ge id 384
+ret 64
+end
+if ne get usedExpert id 0
+ret 64
+end
+put usedExpert id 1
+put plan j id
+end
+path = new uchar 4096 0
+n = argread 1 path 0 4096
+if le n 0
+ret 64
+end
+fd = fopen path 0 ulong n 524288 0
+if lt fd 0
+ret 66
+end
+rc = int 65
+if checkShard int fd
+rc = int 74
+if emitPack int fd count
+rc = int 0
+end
+end
+closed = fclose int fd
+ret rc
+end
diff --git a/om/gpu/dsv41/cache/replay.om b/om/gpu/dsv41/cache/replay.om
new file mode 100644
index 0000000000000000000000000000000000000000..871a8efbba066cec62b0cfcca8fdb287581db645
--- /dev/null
+++ b/om/gpu/dsv41/cache/replay.om
@@ -0,0 +1,545 @@
+note A single-layer host transport. The parent is the only metadata writer. One child reads the pack.
+global handles long 3
+global pipes int 4
+global packRows uint 384
+global warmCount uint 1
+global fileBytes ulong 1
+const cacheSlots uint 4
+const hotSlots uint 2
+const ringSlots uint 2
+fn leWord buf view uchar * off ulong to uint
+v = uint 0
+for i ulong 4
+v = or v shl uint get buf add off i mul i 8
+end
+ret v
+end
+fn recvAll fd int buf edit uchar * to int
+n = ulong 0
+while lt n len buf
+r = read fd buf n sub len buf n
+if eq r -4
+continue
+end
+if lt r 0
+ret -1
+end
+if eq r 0
+if eq n 0
+ret 0
+end
+ret -1
+end
+n = add n ulong r
+end
+ret 1
+end
+fn sendAll fd int buf view uchar * size ulong to bool
+n = ulong 0
+while lt n size
+r = write fd buf n sub size n
+if eq r -4
+continue
+end
+if le r 0
+ret false
+end
+n = add n ulong r
+end
+ret true
+end
+fn readHeader fd int h edit uchar 4096 to bool
+n = ulong 0
+while lt n 4096
+got = pread fd h n sub 4096 n long n
+if eq got -4
+continue
+end
+if le got 0
+ret false
+end
+n = add n ulong got
+end
+ret true
+end
+fn packIndex fd int to bool
+h = new uchar 4096 0
+if not readHeader fd h
+ret false
+end
+if or ne leWord h 0 0x31505844 ne leWord h 4 1
+ret false
+end
+count = leWord h 8
+if or eq count 0 gt count 384
+ret false
+end
+if ne leWord h 12 expertBytes
+ret false
+end
+size = add 4096 mul ulong count ulong expertBytes
+if ne fseek fd 0 2 long size
+ret false
+end
+put fileBytes 0 size
+for i uint count
+key = leWord h add 16 mul ulong i 4
+if ge key 384
+ret false
+end
+if ne get packRows key 0
+ret false
+end
+put packRows key add i 1
+end
+ret true
+end
+fn transfer fd int r edit nvreq to bool
+if ge get r slot cacheSlots
+ret false
+end
+if or ne get r length expertBytes ne get r arenaoff mul ulong get r slot ulong expertBytes
+ret false
+end
+if gt get r fileoff sub get fileBytes 0 ulong expertBytes
+ret false
+end
+b = new uchar 65536 0
+n = ulong 0
+while lt n ulong expertBytes
+k = minChunk sub ulong expertBytes n
+got = pread fd b 0 k long add get r fileoff n
+if eq got -4
+continue
+end
+if le got 0
+ret false
+end
+if ne mapwrite get handles 2 add get r arenaoff n b 0 ulong got got
+ret false
+end
+n = add n ulong got
+put r got uint n
+end
+ret true
+end
+fn minChunk n ulong to ulong
+if gt n 65536
+ret 65536
+end
+ret n
+end
+fn workOne fd int r edit nvreq to void
+if not transfer fd r
+put r status -1
+end
+end
+fn worker fd int to int
+r = new uchar 64 0
+for turn ulong 1000000000
+n = recvAll get pipes 0 r
+if eq n 0
+ret 0
+end
+if lt n 0
+ret 74
+end
+workOne fd r
+cpufence
+if not sendAll get pipes 3 r 64
+ret 74
+end
+end
+ret 75
+end
+fn tableRead slot uint s edit slab to bool
+ret eq mapread get handles 0 mul ulong slot 64 s 0 64 64
+end
+fn tableWrite slot uint s view slab to bool
+ret eq mapwrite get handles 0 mul ulong slot 64 s 0 64 64
+end
+fn queuePos ticket ulong to ulong
+ret mul rem sub ticket 1 ulong ringSlots 64
+end
+fn sameRequest a view nvreq b view nvreq to bool
+if or ne get a key get b key ne get a slot get b slot
+ret false
+end
+if or ne get a fileoff get b fileoff ne get a arenaoff get b arenaoff
+ret false
+end
+if or ne get a length get b length ne get a pack get b pack
+ret false
+end
+ret and eq get b phase 1 eq get a version get b version
+end
+fn acceptResult q edit nvqueue doneRec view nvreq s edit slab r edit nvreq to bool
+seq = get doneRec ticket
+if ne seq add get q retire 1
+ret false
+end
+if ne mapread get handles 1 queuePos seq r 0 64 64
+ret false
+end
+if not sameRequest r doneRec
+ret false
+end
+slot = get r slot
+if not tableRead slot s
+ret false
+end
+if not complete s r seq get doneRec got get doneRec status
+ret false
+end
+if not tableWrite slot s
+ret false
+end
+if ne mapwrite get handles 1 queuePos seq r 0 64 64
+ret false
+end
+if not reap q r
+ret false
+end
+ret eq get s state 2
+end
+fn waitOne q edit nvqueue to bool
+if eq get q retire get q submit
+ret false
+end
+msg = new uchar 64 0
+s = new uchar 64 0
+r = new uchar 64 0
+if ne recvAll get pipes 2 msg 1
+ret false
+end
+ret acceptResult q msg s r
+end
+fn drain q edit nvqueue to bool
+while lt get q retire get q submit
+if not waitOne q
+ret false
+end
+end
+ret true
+end
+fn startSlot t edit slabtab q edit nvqueue s edit slab r edit nvreq slot uint key uint to bool
+if not tableRead slot s
+ret false
+end
+row = get packRows key
+if eq row 0
+ret false
+end
+request r slot key add 4096 mul ulong sub row 1 ulong expertBytes
+if not beginRead t q s r
+ret false
+end
+if not tableWrite slot s
+ret false
+end
+if ne mapwrite get handles 1 queuePos get r ticket r 0 64 64
+ret false
+end
+if not sendAll get pipes 1 r 64
+ret false
+end
+if ge slot hotSlots
+bumpFifo t
+end
+ret true
+end
+fn startKey t edit slabtab q edit nvqueue slot uint key uint to bool
+s = new uchar 64 0
+r = new uchar 64 0
+ret startSlot t q s r slot key
+end
+fn matchSlot t view slabtab s view slab key uint to uint
+if and eq get s zone 2 ne get s epoch get t epoch
+ret 0
+end
+if ne get s key key
+ret 0
+end
+ret get s state
+end
+note Encoded result is slot plus one for READY, its negative for LOADING, zero for a miss.
+fn lookup t view slabtab s edit slab key uint to int
+for i uint cacheSlots
+if not tableRead i s
+ret -127
+end
+st = matchSlot t s key
+if eq st 2
+ret int add i 1
+end
+if eq st 1
+ret neg int add i 1
+end
+end
+ret 0
+end
+fn probe t view slabtab key uint to int
+s = new uchar 64 0
+ret lookup t s key
+end
+fn canDispatch t view slabtab q view nvqueue s edit slab to bool
+if not freeEntry q
+ret false
+end
+if not tableRead fifoSlot t s
+ret false
+end
+ret not busy s
+end
+fn maybeRead t edit slabtab q edit nvqueue key uint to bool
+s = new uchar 64 0
+found = probe t key
+if eq found -127
+ret false
+end
+if ne found 0
+ret true
+end
+if not canDispatch t q s
+ret true
+end
+ret startKey t q fifoSlot t key
+end
+fn consume t view slabtab s edit slab slot uint key uint hit uint to bool
+v = acquire t s key
+if eq v 0
+ret false
+end
+if not tableWrite slot s
+ret false
+end
+header = new uchar 8 0
+for i ulong 4
+put header i uchar and shr key mul i 8 255
+end
+put header 4 uchar hit
+put header 5 uchar get s zone
+if not sendAll 1 header 8
+ret false
+end
+if not emitSlab get s offset
+ret false
+end
+if not release s key v
+ret false
+end
+ret tableWrite slot s
+end
+fn emitSlab base ulong to bool
+b = new uchar 65536 0
+n = ulong 0
+while lt n ulong expertBytes
+k = minChunk sub ulong expertBytes n
+if ne mapread get handles 2 add base n b 0 k long k
+ret false
+end
+if not sendAll 1 b k
+ret false
+end
+n = add n k
+end
+ret true
+end
+fn demand t edit slabtab q edit nvqueue key uint to bool
+s = new uchar 64 0
+hit = uint 1
+for attempt uint 6
+found = lookup t s key
+if gt found 0
+ret consume t s uint sub found 1 key hit
+end
+if eq found -127
+ret false
+end
+hit = 0
+if eq found 0
+if canDispatch t q s
+if not startKey t q fifoSlot t key
+ret false
+end
+end
+end
+if not waitOne q
+ret false
+end
+end
+ret false
+end
+fn warm t edit slabtab q edit nvqueue key uint to bool
+slot = get warmCount 0
+if ge slot hotSlots
+ret false
+end
+if not drain q
+ret false
+end
+found = probe t key
+if lt found 0
+ret false
+end
+if and gt found 0 le found int hotSlots
+ret false
+end
+note A newly protected key can already have a scratch copy. Both carry identical immutable bytes.
+if not startKey t q slot key
+ret false
+end
+put warmCount 0 add slot 1
+ret waitOne q
+end
+fn pollReady q edit nvqueue to bool
+while lt get q retire get q submit
+p = waitio get pipes 2 1 0
+if eq p 0
+ret true
+end
+if eq p -4
+continue
+end
+if lt p 0
+ret false
+end
+if not waitOne q
+ret false
+end
+end
+ret true
+end
+fn step t edit slabtab q edit nvqueue op uint value uint to bool
+if eq op 4
+vote = observe t add get t turn 1 value
+ret true
+end
+if eq op 5
+if ne get t pending value
+ret false
+end
+if not drain q
+ret false
+end
+if not commitPack t q get handles 0
+ret false
+end
+put warmCount 0 0
+ret true
+end
+if ge value 384
+ret false
+end
+if eq get packRows value 0
+ret eq op 3
+end
+if eq op 1
+ret warm t q value
+end
+if eq op 2
+ret demand t q value
+end
+if eq op 3
+ret maybeRead t q value
+end
+ret false
+end
+fn dispatch to int
+t = new uchar 64 0
+q = new uchar 64 0
+b = new uchar 8 0
+if not cacheStart t hotSlots sub cacheSlots hotSlots
+ret 70
+end
+if not ringStart q ringSlots
+ret 70
+end
+for i ulong 1000000000
+n = recvAll 0 b
+if eq n 0
+if drain q
+ret 0
+end
+ret 74
+end
+if lt n 0
+ret 65
+end
+if not pollReady q
+ret 74
+end
+if not step t q leWord b 0 leWord b 4
+ret 65
+end
+end
+ret 75
+end
+fn pipeAt index ulong to bool
+b = new uchar 8 0
+if lt pipefds b 0 8 524288 0
+ret false
+end
+put pipes index int leWord b 0
+put pipes add index 1 int leWord b 4
+ret true
+end
+fn runCache fd int to int
+put handles 0 mapnew -1 0 mul ulong cacheSlots 64 3 33
+put handles 1 mapnew -1 0 mul ulong ringSlots 64 3 33
+put handles 2 mapnew -1 0 mul ulong cacheSlots ulong expertBytes 3 33
+for i ulong 3
+if le get handles i 0
+ret 74
+end
+end
+if not pipeAt 0
+ret 74
+end
+if not pipeAt 2
+ret 74
+end
+pid = fork
+if lt pid 0
+ret 74
+end
+if eq pid 0
+x = fclose get pipes 1
+x = fclose get pipes 2
+ret worker fd
+end
+x = fclose get pipes 0
+x = fclose get pipes 3
+rc = dispatch
+x = fclose get pipes 1
+x = fclose get pipes 2
+status = new uchar 4 0
+w = waitpid int pid status 0 4 0
+while eq w -4
+w = waitpid int pid status 0 4 0
+end
+if and eq rc 0 or ne w pid ne leWord status 0 0
+ret 74
+end
+ret rc
+end
+fn main to int
+if ne argcnt 2
+ret 64
+end
+p = new uchar 4096 0
+n = argread 1 p 0 4096
+if le n 0
+ret 64
+end
+fd = fopen p 0 ulong n 524288 0
+if lt fd 0
+ret 66
+end
+if not packIndex int fd
+ret 65
+end
+rc = runCache int fd
+x = fclose int fd
+ret rc
+end
diff --git a/om/gpu/dsv41/cache/slabs.om b/om/gpu/dsv41/cache/slabs.om
new file mode 100644
index 0000000000000000000000000000000000000000..930f12e9a05816dfd30b183ebbed70b793cd5d0d
--- /dev/null
+++ b/om/gpu/dsv41/cache/slabs.om
@@ -0,0 +1,260 @@
+note SPDX-License-Identifier: AGPL-3.0-only
+note One scheduler owns the tables. The file worker receives immutable request records.
+om2
+layout slabtab 64
+field abi uint at 0 little
+field protect uint at 4 little
+field scratch uint at 8 little
+field stride uint at 12 little
+field fifo uint at 16 little
+field domain uint at 20 little
+field pending uint at 24 little
+field streak uint at 28 little
+field turn ulong at 32 little
+field epoch ulong at 40 little
+field span ulong at 48 little
+field pad ulong at 56 little
+end
+layout slab 64
+field state uint at 0 little
+field key uint at 4 little
+field version ulong at 8 little
+field refs uint at 16 little
+field zone uint at 20 little
+field offset ulong at 24 little
+field length uint at 32 little
+field pad uint at 36 little
+field epoch ulong at 40 little
+field ticket ulong at 48 little
+field spare ulong at 56 little
+end
+layout nvqueue 64
+field abi uint at 0 little
+field capacity uint at 4 little
+field entsize uint at 8 little
+field pad uint at 12 little
+field submit ulong at 16 little
+field retire ulong at 24 little
+field spare ulong 4 at 32 little
+end
+layout nvreq 64
+field ticket ulong at 0 little
+field version ulong at 8 little
+field key uint at 16 little
+field slot uint at 20 little
+field fileoff ulong at 24 little
+field arenaoff ulong at 32 little
+field length uint at 40 little
+field got uint at 44 little
+field status int at 48 little
+field phase uint at 52 little
+field pack uint at 56 little
+field pad uint at 60 little
+end
+const expertBytes uint 18800640
+const noDomain uint 4294967295
+note An empty header and all slots initially contain zeroes. Keys are layer * 384 + expert.
+fn cacheStart t edit slabtab protectedCount uint scratchCount uint to bool
+if or eq protectedCount 0 eq scratchCount 0
+ret false
+end
+if gt add ulong protectedCount ulong scratchCount 15360
+ret false
+end
+put t abi 1
+put t protect protectedCount
+put t scratch scratchCount
+put t stride expertBytes
+put t pending noDomain
+put t span mul add ulong protectedCount ulong scratchCount ulong expertBytes
+ret true
+end
+fn ringStart q edit nvqueue cap uint to bool
+if or eq cap 0 gt cap 15360
+ret false
+end
+put q abi 1
+put q capacity cap
+put q entsize 64
+ret true
+end
+note One vote per distinct consecutive turn. Unknown or current domain breaks a streak.
+fn observe t edit slabtab turn ulong domain uint to bool
+if le turn get t turn
+ret false
+end
+if gt sub turn get t turn 1
+put t streak 0
+end
+put t turn turn
+if or eq domain noDomain eq domain get t domain
+put t pending noDomain
+put t streak 0
+ret false
+end
+if ne domain get t pending
+put t pending domain
+put t streak 0
+end
+if lt get t streak 3
+put t streak add get t streak 1
+end
+ret eq get t streak 3
+end
+note Caller drains all leases and I/O before publishing the new protected pack.
+fn busy s view slab to bool
+ret or eq get s state 1 ne get s refs 0
+end
+fn request r edit nvreq slot uint key uint offset ulong to void
+put r slot slot
+put r key key
+put r fileoff offset
+end
+fn freeEntry q view nvqueue to bool
+tail = get q submit
+if or lt tail get q retire eq tail 18446744073709551615
+ret false
+end
+ret lt sub tail get q retire ulong get q capacity
+end
+fn targetOK t view slabtab s view slab r view nvreq to bool
+if ge get r key 15360
+ret false
+end
+if ge ulong get r slot add ulong get t protect ulong get t scratch
+ret false
+end
+if lt get r slot get t protect
+if and eq get s state 2 eq get s epoch get t epoch
+ret false
+end
+end
+if or busy s ne rem get r fileoff 4096 0
+ret false
+end
+if gt get r fileoff sub 9223372036854775807 ulong get t stride
+ret false
+end
+ret ne get s version 18446744073709551615
+end
+fn beginRead t view slabtab q edit nvqueue s edit slab r edit nvreq to bool
+if or ne get t abi 1 ne get q abi 1
+ret false
+end
+if not freeEntry q
+ret false
+end
+if not targetOK t s r
+ret false
+end
+put q submit add get q submit 1
+put s state 1
+put s key get r key
+put s version add get s version 1
+put s refs 0
+put s zone 3
+if lt get r slot get t protect
+put s zone 2
+end
+put s offset mul ulong get r slot ulong get t stride
+put s length get t stride
+put s epoch get t epoch
+put s ticket get q submit
+put r ticket get s ticket
+put r version get s version
+put r arenaoff get s offset
+put r length get s length
+put r got 0
+put r status 0
+put r phase 1
+put r pack 0
+ret true
+end
+note Completion is consumed by the owner. A short read makes the slot EMPTY.
+fn complete s edit slab r edit nvreq seq ulong got uint status int to bool
+if or ne get r phase 1 ne get r ticket seq
+ret false
+end
+if or ne get s state 1 ne get s ticket seq
+ret false
+end
+if or ne get s version get r version ne get s key get r key
+ret false
+end
+if or ne get s offset get r arenaoff ne get s length get r length
+ret false
+end
+put r got got
+put r status status
+put r phase 2
+put s state 0
+if and eq status 0 eq got get r length
+put s state 2
+end
+ret true
+end
+fn reap q edit nvqueue r view nvreq to bool
+if ge get q retire get q submit
+ret false
+end
+if or ne get r phase 2 ne get r ticket add get q retire 1
+ret false
+end
+put q retire get r ticket
+ret true
+end
+fn acquire t view slabtab s edit slab key uint to ulong
+if and eq get s zone 2 ne get s epoch get t epoch
+ret 0
+end
+if or ne get s state 2 ne get s key key
+ret 0
+end
+if eq get s refs 4294967295
+ret 0
+end
+put s refs add get s refs 1
+ret get s version
+end
+fn release s edit slab key uint version ulong to bool
+if or ne get s state 2 ne get s key key
+ret false
+end
+if or ne get s version version eq get s refs 0
+ret false
+end
+put s refs sub get s refs 1
+ret true
+end
+fn fifoSlot t view slabtab to uint
+ret add get t protect get t fifo
+end
+fn bumpFifo t edit slabtab to void
+put t fifo rem add get t fifo 1 get t scratch
+end
+
+fn blockedSlot buf view slab to bool
+ret busy buf
+end
+fn commitPack t edit slabtab q view nvqueue table long to bool
+if or ne get t streak 3 ne get q submit get q retire
+ret false
+end
+if or eq get t pending noDomain eq get t epoch 18446744073709551615
+ret false
+end
+buf = new uchar 64 0
+for i uint get t protect
+if ne mapread table mul ulong i 64 buf 0 64 64
+ret false
+end
+if blockedSlot buf
+ret false
+end
+end
+put t domain get t pending
+put t epoch add get t epoch 1
+put t pending noDomain
+put t streak 0
+ret true
+end