Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/physics-mv/blob/main/m3/replay_cache.s # physics-mv FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `physics-mv / m3 / replay_cache.s` 157 lines ยท 3985 bytes Raw Blame History 1 /* 2 * m3/replay_cache.s - Bounded Replay Cache & Idempotency Engine 3 * Milestone 3: PHYSICS_EFFECTS (Sovereign Machine) 4 * 5 * Fixed-capacity 32-entry replay cache. 6 * Identical replay -> idempotent original result with zero re-execution. 7 * Conflicting intent with same request_id -> REJECTED_REPLAY_CONFLICT. 8 * Storage: PHYSICS_REPLAY_CACHE @ 0x4020C000 (4 KiB) 9 */ 10 11 .global init_replay_cache 12 .global lookup_replay 13 .global record_replay 14 15 .section .text, "ax" 16 .balign 4 17 18 .equ REPLAY_CACHE_BASE, 0x4020C000 19 .equ REPLAY_CACHE_CAPACITY, 32 20 .equ REPLAY_ENTRY_SIZE, 64 21 .equ REPLAY_ENTRY_SHIFT, 6 22 23 .equ REPLAY_MISS, 0 24 .equ REPLAY_HIT, 1 25 .equ REPLAY_CONFLICT, 2 26 27 /* 28 * init_replay_cache(): 29 * Zeros the 4 KiB replay cache area. 30 */ 31 init_replay_cache: 32 ldr x0, =REPLAY_CACHE_BASE 33 mov x1, #4096 34 .Lzero_replay_loop: 35 cbz x1, .Lzero_replay_done 36 stp xzr, xzr, [x0], #16 37 sub x1, x1, #16 38 b .Lzero_replay_loop 39 .Lzero_replay_done: 40 ret 41 42 /* 43 * lookup_replay(request_id, intent_digest_ptr) 44 * x0: request_id, x1: intent_digest_ptr 45 * Returns: 46 * w0: REPLAY_MISS (0), REPLAY_HIT (1), or REPLAY_CONFLICT (2) 47 * x1: receipt_slot 48 * w2: decision 49 * x3: actual_effect 50 */ 51 lookup_replay: 52 stp x29, x30, [sp, #-16]! 53 mov x29, sp 54 55 ldr x2, =REPLAY_CACHE_BASE 56 mov w3, #0 /* index 0..31 */ 57 58 .Lsearch_replay: 59 cmp w3, #REPLAY_CACHE_CAPACITY 60 b.ge .Lreplay_not_found 61 62 ubfiz x4, x3, #REPLAY_ENTRY_SHIFT, #5 63 add x5, x2, x4 /* x5 = entry ptr */ 64 65 /* Check if entry valid */ 66 ldr x6, [x5, #0x40] /* entry.valid */ 67 cbz x6, .Lreplay_next 68 69 /* Check request_id match */ 70 ldr x7, [x5, #0x00] /* entry.request_id */ 71 cmp x0, x7 72 b.ne .Lreplay_next 73 74 /* request_id matches! Compare 32-byte intent_digest */ 75 add x8, x5, #0x08 /* entry.intent_digest */ 76 ldp x9, x10, [x8, #0] 77 ldp x11, x12, [x1, #0] 78 cmp x9, x11 79 b.ne .Lreplay_mismatch 80 cmp x10, x12 81 b.ne .Lreplay_mismatch 82 83 ldp x9, x10, [x8, #16] 84 ldp x11, x12, [x1, #16] 85 cmp x9, x11 86 b.ne .Lreplay_mismatch 87 cmp x10, x12 88 b.ne .Lreplay_mismatch 89 90 /* Exact match! REPLAY_HIT */ 91 ldr w1, [x5, #0x28] /* receipt_slot */ 92 ldr w2, [x5, #0x2C] /* decision */ 93 ldr x3, [x5, #0x30] /* actual_effect */ 94 mov w0, #REPLAY_HIT 95 ldp x29, x30, [sp], #16 96 ret 97 98 .Lreplay_mismatch: 99 /* Same request_id, different intent digest -> REPLAY_CONFLICT */ 100 mov w0, #REPLAY_CONFLICT 101 ldp x29, x30, [sp], #16 102 ret 103 104 .Lreplay_next: 105 add w3, w3, #1 106 b .Lsearch_replay 107 108 .Lreplay_not_found: 109 mov w0, #REPLAY_MISS 110 ldp x29, x30, [sp], #16 111 ret 112 113 /* 114 * record_replay(request_id, intent_digest_ptr, receipt_slot, decision, actual_effect, output) 115 * x0: request_id, x1: intent_digest_ptr, w2: receipt_slot, w3: decision, x4: actual_effect, x5: output 116 */ 117 record_replay: 118 ldr x6, =REPLAY_CACHE_BASE 119 mov w7, #0 120 121 .Lfind_replay_slot: 122 cmp w7, #REPLAY_CACHE_CAPACITY 123 b.ge .Lrecord_done /* Cache full */ 124 125 ubfiz x8, x7, #REPLAY_ENTRY_SHIFT, #5 126 add x9, x6, x8 /* x9 = entry ptr */ 127 128 ldr x10, [x9, #0x40] /* valid */ 129 cbz x10, .Lfound_free_replay 130 131 /* Check if already matches this request_id */ 132 ldr x11, [x9, #0x00] 133 cmp x0, x11 134 b.eq .Lfound_free_replay 135 136 add w7, w7, #1 137 b .Lfind_replay_slot 138 139 .Lfound_free_replay: 140 str x0, [x9, #0x00] /* request_id */ 141 142 /* Copy 32-byte digest */ 143 ldp x12, x13, [x1, #0] 144 ldp x14, x15, [x1, #16] 145 stp x12, x13, [x9, #0x08] 146 stp x14, x15, [x9, #0x18] 147 148 str w2, [x9, #0x28] /* receipt_slot */ 149 str w3, [x9, #0x2C] /* decision */ 150 str x4, [x9, #0x30] /* actual_effect */ 151 str x5, [x9, #0x38] /* output */ 152 153 mov x12, #1 154 str x12, [x9, #0x40] /* valid = 1 */ 155 156 .Lrecord_done: 157 ret