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

GitHub aien-dev/omega-mv#956 (code only)

closed derived 8b375f261062b8e1 #956

Imported from GitHub aien-dev/omega-mv#956 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 62d1d0d668f897386a0e311374f8dbcc5c32dde8 · Head 5b218a7f057d39d7b51064245b31ae79a534308f

Apply it

git checkout -b patch-8b375f261062b8e1 62d1d0d668f897386a0e311374f8dbcc5c32dde8
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/8b375f261062b8e1.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/omega-mv
956
5b218a7f057d39d7b51064245b31ae79a534308f
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":956,"url":"https://github.com/aien-dev/omega-mv/pull/956","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:28Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index f3e51fe46..08f831e23 100644
--- a/.crumb
+++ b/.crumb
@@ -72,38 +72,38 @@
         },
         {
           "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986",
-          "last_commit": "a8a6a3d3c",
+          "last_commit": "62d1d0d66",
           "name": "spec",
           "purpose": "Directory spec. Purpose not yet described by a human."
         },
         {
-          "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7",
-          "last_commit": "bf54b19fa",
+          "digest": "cc6a9359171ea3a5429974b2912e1f8300094010f41f5aaa08125d02c4d8ccf3",
+          "last_commit": "e9eedabb0",
           "name": "src",
           "purpose": "Directory src. Purpose not yet described by a human."
         },
         {
-          "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874",
-          "last_commit": "a8a6a3d3c",
+          "digest": "5f81a8f4b2ef515e242f0de809b5df1f245a9f593030a1741e1dd5820d524842",
+          "last_commit": "e9eedabb0",
           "name": "tests",
           "purpose": "Directory tests. Purpose not yet described by a human."
         },
         {
           "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29",
-          "last_commit": "a8a6a3d3c",
+          "last_commit": "62d1d0d66",
           "name": "tools",
           "purpose": "Directory tools. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc",
-      "compiled_at": "2026-10-30T12:31:50Z",
+      "children_root": "sha256:acdbd01d50f9dd38f72f96f2e4cdfb0adffe67ab69d4e689f24b08e658d68452",
+      "compiled_at": "2026-10-30T14:53:29Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6",
+      "digest": "sha256:ee2064187013a3e8c905d084528b7b36b367cde6be8844bf3ca2228c75859908",
       "evidence_files": 12622,
       "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9",
-      "files": 17849,
-      "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06",
-      "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed"
+      "files": 17851,
+      "generated_at_commit": "e9eedabb00ab600b6f623955d0988f1a6b73f185",
+      "source_tree": "sha256:fcb2a31cc3c5675cc61d6825822cec6a684a69b0dff6b2324889f5a32d76b279"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/Makefile b/Makefile
index 6b53cd124..19d8e1962 100644
--- a/Makefile
+++ b/Makefile
@@ -2024,6 +2024,30 @@ test-library: tests/test_omega_library.c src/omega_library.c src/omega_library.h
 	  mp_run build_mutant refuse-deps           dep-null             '    if (dep_count > 0) return -1;'; mp_wait
 	@echo "test-library: PASS (all checks, all mutants killed)"
 
+# omega-mv#574: omega_exec_native_f3 keeps executable pages for the last OMEGA_EXEC_CACHE_SLOTS distinct code
+# byte strings. test-exec-native-cache: reuse (hits), invalidation (same length or same address with new bytes
+# never runs a stale mapping), LRU eviction, capacity. Then each mutant of src/omega_exec.c must make the test fail.
+.PHONY: test-exec-native-cache
+EXECCACHE_CORE = $(filter-out src/omega_exec.c,$(LIBTEST_CORE))
+EXECCACHE_DIR = $(OUT_DIR)/exec-cache-test
+test-exec-native-cache: tests/exec/test_exec_native_cache.c src/omega_exec.c src/omega_exec.h
+	@mkdir -p $(EXECCACHE_DIR)
+	$(CC) $(LIBTEST_FLAGS) -o $(EXECCACHE_DIR)/test_exec_native_cache tests/exec/test_exec_native_cache.c src/omega_exec.c $(EXECCACHE_CORE) -lpthread
+	$(EXECCACHE_DIR)/test_exec_native_cache
+	@set -eu; for m in 'identity-by-length|s/ \&\& memcmp(s->code, real->code_bytes, real->code_len) == 0//' \
+	                 'evict-most-recent|s/s->last_use < lru->last_use/s->last_use > lru->last_use/' \
+	                 'hit-not-touched|/^ *s->last_use = ++g_tick;$$/d'; do \
+	  name=$${m%%|*}; expr=$${m#*|}; mut=$(EXECCACHE_DIR)/mut_$$name.c; \
+	  sed "$$expr" src/omega_exec.c > $$mut; \
+	  if cmp -s src/omega_exec.c $$mut; then echo "mutant $$name: sed changed nothing"; exit 1; fi; \
+	  $(CC) $(LIBTEST_FLAGS) -o $(EXECCACHE_DIR)/mut_$$name tests/exec/test_exec_native_cache.c $$mut $(EXECCACHE_CORE) -lpthread; \
+	  rc=0; $(EXECCACHE_DIR)/mut_$$name > $(EXECCACHE_DIR)/mut_$$name.out 2>&1 || rc=$$?; \
+	  if [ $$rc -ne 1 ] || ! grep -q '^EXEC_NATIVE_CACHE: FAIL' $(EXECCACHE_DIR)/mut_$$name.out; then \
+	    echo "mutant $$name NOT killed (exit $$rc)"; cat $(EXECCACHE_DIR)/mut_$$name.out; exit 1; fi; \
+	  echo "mutant $$name: killed ($$(grep -c '^FAIL' $(EXECCACHE_DIR)/mut_$$name.out) failing checks)"; \
+	done
+	@echo "test-exec-native-cache: PASS (all checks, all mutants killed)"
+
 # VC1-STORE (VC1 stage 3): unit test for the Verified Crumb Store (omega_vcstore): golden
 # vectors from aien-protocols (tests/vcstore/golden, PIN names the commit), immutability,
 # dependency closure, insert-order-independent digest, name index, save/load. Plus a mutation
diff --git a/bench/m1/block1_sched.c b/bench/m1/block1_sched.c
new file mode 100644
index 000000000..049015b92
--- /dev/null
+++ b/bench/m1/block1_sched.c
@@ -0,0 +1,80 @@
+/* M1 block 1 (omega-mv#574): time both realization schedules on the Spark.
+ * Two measurements per program:
+ *   path  = omega_exec_native_f3 as Omega runs it (mmap+copy+mprotect+call+munmap per call)
+ *   code  = map once, call the function N times (the instruction bytes alone)
+ * Verifies every schedule against omega_program_eval before timing. */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include "omega_program.h"
+#include "omega_realize.h"
+#include "omega_realize_synth.h"
+#include "omega_exec.h"
+
+static double now(void){struct timespec t;clock_gettime(CLOCK_MONOTONIC,&t);return t.tv_sec+t.tv_nsec*1e-9;}
+static int make_prog(OmegaProgram *p,const char *name,uint16_t w,const uint8_t *ops,const uint64_t *imms,size_t n){
+    omega_program_init(p,name);
+    p->contract.input_type=p->contract.output_type=TYPE_UNSIGNED_INT;
+    p->contract.input_width=p->contract.output_width=w;
+    snprintf(p->contract.precondition,sizeof p->contract.precondition,"true");
+    snprintf(p->contract.postcondition,sizeof p->contract.postcondition,"true");
+    omega_build_constraint_id(CONST_PRECONDITION,"true",&p->contract.precondition_id);
+    omega_build_constraint_id(CONST_POSTCONDITION,"true",&p->contract.postcondition_id);
+    p->body.has_body=true;p->body.step_count=(uint16_t)n;
+    for(size_t i=0;i<n;++i){p->body.steps[i].op=ops[i];p->body.steps[i].imm=imms[i];}
+    return omega_program_compute_id(p);
+}
+static int compose2(OmegaProgram *out,OpCode o1,uint64_t i1,OpCode o2,uint64_t i2){
+    OmegaProgram a,b;char err[160];
+    if(omega_program_build_unary_op(&a,"a",o1,i1)||omega_program_build_unary_op(&b,"b",o2,i2))return -1;
+    return omega_program_compose(&a,&b,out,err,sizeof err);
+}
+typedef uint64_t(*Fn3)(uint64_t,uint64_t,uint64_t);
+
+int main(int argc,char**argv){
+    long NPATH=argc>1?atol(argv[1]):20000, NCODE=argc>2?atol(argv[2]):20000000;
+    OmegaProgram P[24];const char*L[24];int n=0;
+#define ADD(label,rc) do{if((rc)==0){L[n++]=label;}else{fprintf(stderr,"build fail %s\n",label);return 2;}}while(0)
+    ADD("x+1",omega_program_build_unary_op(&P[n],"f",OP_ADD,1));
+    ADD("x*3",omega_program_build_unary_op(&P[n],"f",OP_MUL,3));
+    ADD("(x*3)-2",compose2(&P[n],OP_MUL,3,OP_SUB,2));
+    ADD("(x+7)*5",compose2(&P[n],OP_ADD,7,OP_MUL,5));
+    ADD("x&0xFF00FF",omega_program_build_unary_op(&P[n],"f",OP_AND,0xFF00FF));
+    {uint8_t o[]={OP_ADD};uint64_t i[]={0x123456789ABCDEF0ull};ADD("x+0x123456789ABCDEF0",make_prog(&P[n],"w",64,o,i,1));}
+    {uint8_t o[]={OP_MUL,OP_AND,OP_OR};uint64_t i[]={0x100000001ull,0xFFFF0000FFFF0000ull,0x0001000000000000ull};ADD("3-step wide",make_prog(&P[n],"w",64,o,i,3));}
+    {uint8_t o[]={OP_MUL,OP_SUB};uint64_t i[]={3,2};ADD("u32 (x*3)-2",make_prog(&P[n],"n",32,o,i,2));}
+    {uint8_t o[16];uint64_t i[16];for(int k=0;k<16;++k){o[k]=k%2?OP_MUL:OP_ADD;i[k]=0xFEDCBA9876543210ull^(uint64_t)k;}ADD("16-step wide",make_prog(&P[n],"long",64,o,i,16));}
+    {uint8_t o[64];uint64_t i[64];for(int k=0;k<64;++k){o[k]=k%2?OP_MUL:OP_ADD;i[k]=0xFEDCBA9876543210ull^(uint64_t)k;}ADD("64-step wide",make_prog(&P[n],"long",64,o,i,64));}
+
+    printf("program,schedule,code_bytes,verified,n_path,path_ns_per_call,n_code,code_ns_per_call,rule_pick\n");
+    size_t pg=(size_t)sysconf(_SC_PAGESIZE);
+    for(int k=0;k<n;++k){
+        RealizationSynthesisResult rs; int src=omega_synthesize_for_dgx_spark(&P[k],&rs);
+        const char*pick=src==0?(rs.schedule==OMEGA_SCHED_PRELOAD?"PRELOAD":"SEQUENTIAL"):"synth_refused";
+        for(int s=0;s<2;++s){
+            RealizationObject r;memset(&r,0,sizeof r);
+            if(omega_program_emit_schedule(&P[k].body,P[k].contract.input_width,(OmegaRealizeSchedule)s,r.code_bytes,&r.code_len,sizeof r.code_bytes)){printf("%s,%s,0,emit_fail,,,,,%s\n",L[k],s?"PRELOAD":"SEQUENTIAL",pick);continue;}
+            uint64_t xs[OMEGA_REALIZE_DIFF_INPUTS],ys[OMEGA_REALIZE_DIFF_INPUTS];
+            size_t ni=omega_realize_differential_inputs(&P[k],xs,OMEGA_REALIZE_DIFF_INPUTS);
+            int ok=omega_program_eval(&P[k],xs,ni,ys)==0;
+            for(size_t i=0;ok&&i<ni;++i){uint64_t g=0;if(omega_exec_native_f3(&r,xs[i],0,0,&g)||g!=ys[i])ok=0;}
+            if(!ok){printf("%s,%s,%zu,FAIL,,,,,%s\n",L[k],s?"PRELOAD":"SEQUENTIAL",r.code_len,pick);continue;}
+            /* path: as Omega executes */
+            volatile uint64_t sink=0;uint64_t g;
+            for(int w=0;w<200;++w)omega_exec_native_f3(&r,xs[0],0,0,&g);
+            double t0=now();for(long i=0;i<NPATH;++i){omega_exec_native_f3(&r,xs[i%ni],0,0,&g);sink+=g;}double t1=now();
+            /* code: map once */
+            size_t al=(r.code_len+pg-1)&~(pg-1);void*m=mmap(NULL,al,PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
+            memcpy(m,r.code_bytes,r.code_len);__builtin___clear_cache((char*)m,(char*)m+r.code_len);mprotect(m,al,PROT_READ|PROT_EXEC);
+            union{void*p;Fn3 f;}u;u.p=m;uint64_t acc=xs[0];
+            for(long i=0;i<1000000;++i)acc=u.f(acc,0,0);
+            double t2=now();for(long i=0;i<NCODE;++i)acc=u.f(acc,0,0);double t3=now();sink+=acc;munmap(m,al);
+            printf("%s,%s,%zu,ok,%ld,%.1f,%ld,%.3f,%s\n",L[k],s?"PRELOAD":"SEQUENTIAL",r.code_len,NPATH,(t1-t0)/NPATH*1e9,NCODE,(t3-t2)/NCODE*1e9,pick);
+            fflush(stdout);
+        }
+    }
+    return 0;
+}
diff --git a/src/.crumb b/src/.crumb
index 7c4b83da7..e234d4e37 100644
--- a/src/.crumb
+++ b/src/.crumb
@@ -188,14 +188,14 @@
         }
       ],
       "children_root": "sha256:2f729945214be989a74d7c2064ae4ba3c2deb52ebea3f334b459198a7bd032ed",
-      "compiled_at": "2026-10-30T02:49:13Z",
+      "compiled_at": "2026-10-30T14:53:29Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7",
+      "digest": "sha256:cc6a9359171ea3a5429974b2912e1f8300094010f41f5aaa08125d02c4d8ccf3",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 568,
-      "generated_at_commit": "2cb1ccb5d3c1a1ce1cb94a7a3dd3c221395c4e15",
-      "source_tree": "sha256:7f1fef46a27e8baf5cf567bb590d417ede3767c5f07e714d0f0812af0645bb4b"
+      "generated_at_commit": "e9eedabb00ab600b6f623955d0988f1a6b73f185",
+      "source_tree": "sha256:dc087cee230bdd8e675a74db6a7b8406c7ba9e2d6b74687c907dbee99b82cdb2"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/src/omega_exec.c b/src/omega_exec.c
index 5b42ccfe3..150026065 100644
--- a/src/omega_exec.c
+++ b/src/omega_exec.c
@@ -21,33 +21,93 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-int omega_exec_native_f3(const RealizationObject *real, uint64_t a, uint64_t b, uint64_t c, uint64_t *out_res) {
-    if (!real || !out_res || real->code_len == 0) return -1;
+#include <pthread.h>
+
+typedef uint64_t (*OmegaExecFn3)(uint64_t, uint64_t, uint64_t);
+
+/* One resident executable mapping. Identity is the exact code bytes. */
+typedef struct {
+    void *mem;
+    size_t alloc_size;
+    size_t code_len;
+    uint8_t code[AARCH64_MAX_CODE_BYTES];
+    uint64_t last_use;
+} ExecSlot;
+
+static pthread_mutex_t g_cache_mu = PTHREAD_MUTEX_INITIALIZER;
+static ExecSlot g_slots[OMEGA_EXEC_CACHE_SLOTS];
+static OmegaExecCacheStats g_stats;
+static uint64_t g_tick;
+
+static void slot_drop(ExecSlot *s) {
+    if (s->mem) { munmap(s->mem, s->alloc_size); g_stats.resident--; }
+    memset(s, 0, sizeof *s);
+}
+
+void omega_exec_native_cache_reset(void) {
+    pthread_mutex_lock(&g_cache_mu);
+    for (unsigned i = 0; i < OMEGA_EXEC_CACHE_SLOTS; i++) slot_drop(&g_slots[i]);
+    memset(&g_stats, 0, sizeof g_stats);
+    g_tick = 0;
+    pthread_mutex_unlock(&g_cache_mu);
+}
+
+void omega_exec_native_cache_stats(OmegaExecCacheStats *out) {
+    if (!out) return;
+    pthread_mutex_lock(&g_cache_mu);
+    *out = g_stats;
+    pthread_mutex_unlock(&g_cache_mu);
+}
 
 #if defined(__aarch64__)
+/* Returns the slot holding these bytes, mapping them if needed; NULL on a mapping failure.
+ * Victim choice: the first empty slot, else the least recently used. */
+static ExecSlot *slot_acquire(const RealizationObject *real) {
+    ExecSlot *empty = NULL, *lru = NULL;
+    for (unsigned i = 0; i < OMEGA_EXEC_CACHE_SLOTS; i++) {
+        ExecSlot *s = &g_slots[i];
+        if (s->mem && s->code_len == real->code_len && memcmp(s->code, real->code_bytes, real->code_len) == 0) {
+            s->last_use = ++g_tick;
+            g_stats.hits++;
+            return s;
+        }
+        if (!s->mem) { if (!empty) empty = s; }
+        else if (!lru || s->last_use < lru->last_use) lru = s;
+    }
+    ExecSlot *victim = empty ? empty : lru;
+    if (victim->mem) { slot_drop(victim); g_stats.evictions++; }
+
     size_t page_size = (size_t)sysconf(_SC_PAGESIZE);
     size_t alloc_size = (real->code_len + page_size - 1) & ~(page_size - 1);
-
     void *mem = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
-    if (mem == MAP_FAILED) return -1;
-
+    if (mem == MAP_FAILED) return NULL;
     memcpy(mem, real->code_bytes, real->code_len);
     __builtin___clear_cache((char*)mem, (char*)mem + real->code_len);
+    if (mprotect(mem, alloc_size, PROT_READ | PROT_EXEC) != 0) { munmap(mem, alloc_size); return NULL; }
+
+    victim->mem = mem;
+    victim->alloc_size = alloc_size;
+    victim->code_len = real->code_len;
+    memcpy(victim->code, real->code_bytes, real->code_len);
+    victim->last_use = ++g_tick;
+    g_stats.misses++;
+    g_stats.resident++;
+    return victim;
+}
+#endif
 
-    if (mprotect(mem, alloc_size, PROT_READ | PROT_EXEC) != 0) {
-        munmap(mem, alloc_size);
-        return -1;
-    }
+int omega_exec_native_f3(const RealizationObject *real, uint64_t a, uint64_t b, uint64_t c, uint64_t *out_res) {
+    if (!real || !out_res || real->code_len == 0 || real->code_len > AARCH64_MAX_CODE_BYTES) return -1;
 
-    typedef uint64_t (*Fn3)(uint64_t, uint64_t, uint64_t);
-    union {
-        void *ptr;
-        Fn3 fn;
-    } u;
-    u.ptr = mem;
+#if defined(__aarch64__)
+    union { void *ptr; OmegaExecFn3 fn; } u;
+    pthread_mutex_lock(&g_cache_mu);
+    ExecSlot *s = slot_acquire(real);
+    if (!s) { pthread_mutex_unlock(&g_cache_mu); return -1; }
+    u.ptr = s->mem;
+    /* Held under the lock: no other thread can unmap this slot during the (short) call. */
     *out_res = u.fn(a, b, c);
-
-    munmap(mem, alloc_size);
+    pthread_mutex_unlock(&g_cache_mu);
     return 0;
 #else
     (void)a; (void)b; (void)c;
diff --git a/src/omega_exec.h b/src/omega_exec.h
index 34042436b..632141662 100644
--- a/src/omega_exec.h
+++ b/src/omega_exec.h
@@ -21,8 +21,21 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-/* Native in-process execution on AArch64 host */
+/* Native in-process execution on AArch64 host.
+ * Executable pages are kept for the last OMEGA_EXEC_CACHE_SLOTS distinct code byte strings
+ * (identity = the bytes, not the RealizationObject address). Measured 2026-10-19 on the Spark
+ * (omega-mv#574): mmap+copy+mprotect+munmap per call cost 19 to 23 us against under 40 ns of
+ * code, so a repeated realization paid 99.9 percent of its time in page setup. */
+#define OMEGA_EXEC_CACHE_SLOTS 64u
+typedef struct {
+    uint64_t hits;      /* calls served from a resident mapping */
+    uint64_t misses;    /* calls that mapped fresh pages */
+    uint64_t evictions; /* resident mappings dropped to make room */
+    uint64_t resident;  /* mappings currently held */
+} OmegaExecCacheStats;
 int omega_exec_native_f3(const RealizationObject *real, uint64_t a, uint64_t b, uint64_t c, uint64_t *out_res);
+void omega_exec_native_cache_stats(OmegaExecCacheStats *out);
+void omega_exec_native_cache_reset(void);   /* unmaps every resident mapping and zeroes the counters */
 
 /* Bare-metal QEMU runner generation and execution */
 int omega_build_qemu_runner(const RealizationObject *real, const char *out_bin_path);
diff --git a/tests/.crumb b/tests/.crumb
index 5fbfcb29c..3fce2bbd3 100644
--- a/tests/.crumb
+++ b/tests/.crumb
@@ -302,14 +302,14 @@
         }
       ],
       "children_root": "sha256:0c57282ff8cf1d34e5685e2729755f2978917e66debb5423961033be9d25c902",
-      "compiled_at": "2026-10-30T12:31:50Z",
+      "compiled_at": "2026-10-30T14:53:29Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874",
+      "digest": "sha256:5f81a8f4b2ef515e242f0de809b5df1f245a9f593030a1741e1dd5820d524842",
       "evidence_files": 16,
       "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a",
-      "files": 1386,
-      "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06",
-      "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679"
+      "files": 1387,
+      "generated_at_commit": "e9eedabb00ab600b6f623955d0988f1a6b73f185",
+      "source_tree": "sha256:1f8b2c2be4bc7a296aaefbb096b8df545daf21f77d82af667b3631f5360b2224"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/tests/exec/test_exec_native_cache.c b/tests/exec/test_exec_native_cache.c
new file mode 100644
index 000000000..b8b920c27
--- /dev/null
+++ b/tests/exec/test_exec_native_cache.c
@@ -0,0 +1,100 @@
+/* omega_exec_native_f3 keeps executable pages for recently seen realizations.
+ * Contract: same bytes -> same mapping (hit), different bytes -> new mapping (miss),
+ * results identical to a fresh mapping, eviction frees without breaking later calls. */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "omega_program.h"
+#include "omega_exec.h"
+
+static int fails;
+#define CHECK(c, ...) do{ if(!(c)){ fails++; printf("FAIL: " __VA_ARGS__); printf("\n"); } }while(0)
+
+static void mk(OmegaProgram *p, OpCode op, uint64_t imm) {
+    if (omega_program_build_unary_op(p, "f", op, imm) != 0 || omega_program_realize(p) != 0) { puts("build fail"); exit(2); }
+}
+
+int main(void) {
+    OmegaExecCacheStats s0, s1;
+    OmegaProgram a, b;
+    uint64_t y = 0;
+    mk(&a, OP_ADD, 5);
+    mk(&b, OP_MUL, 7);
+    omega_exec_native_cache_reset();
+    omega_exec_native_cache_stats(&s0);
+    CHECK(s0.hits == 0 && s0.misses == 0 && s0.resident == 0, "reset clears counters");
+
+    CHECK(omega_exec_native_f3(&a.realization, 10, 0, 0, &y) == 0 && y == 15, "a first call result");
+    CHECK(omega_exec_native_f3(&a.realization, 11, 0, 0, &y) == 0 && y == 16, "a second call result");
+    omega_exec_native_cache_stats(&s1);
+    CHECK(s1.misses == 1 && s1.hits == 1 && s1.resident == 1, "same bytes: 1 miss then 1 hit (got m=%llu h=%llu r=%llu)",
+          (unsigned long long)s1.misses, (unsigned long long)s1.hits, (unsigned long long)s1.resident);
+
+    CHECK(omega_exec_native_f3(&b.realization, 3, 0, 0, &y) == 0 && y == 21, "b result");
+    omega_exec_native_cache_stats(&s1);
+    CHECK(s1.misses == 2 && s1.resident == 2, "different bytes: a miss, 2 resident");
+
+    /* a copy with identical bytes but a different RealizationObject address still hits */
+    RealizationObject copy = a.realization;
+    CHECK(omega_exec_native_f3(&copy, 1, 0, 0, &y) == 0 && y == 6, "copy result");
+    omega_exec_native_cache_stats(&s1);
+    CHECK(s1.hits == 2, "identity is the bytes, not the pointer");
+
+    /* Invalidation. A program of the same length whose bytes differ (ADD #6 vs ADD #5) must map fresh
+     * pages and compute its own result; a cache keyed by length or address would return a + 5. */
+    OmegaProgram a6;
+    mk(&a6, OP_ADD, 6);
+    CHECK(a6.realization.code_len == a.realization.code_len &&
+          memcmp(a6.realization.code_bytes, a.realization.code_bytes, a.realization.code_len) != 0,
+          "fixture: ADD #6 has the same length as ADD #5 and different bytes");
+    omega_exec_native_cache_stats(&s0);
+    CHECK(omega_exec_native_f3(&a6.realization, 5, 0, 0, &y) == 0 && y == 11, "same length, other bytes: own result (got %llu)",
+          (unsigned long long)y);
+    omega_exec_native_cache_stats(&s1);
+    CHECK(s1.hits == s0.hits && s1.misses == s0.misses + 1, "same length, other bytes: a miss, not a hit");
+
+    /* The same RealizationObject rewritten in place (same address, same length, new bytes) must not run
+     * the stale mapping; rewriting it back to the original bytes hits the mapping still resident. */
+    RealizationObject *ra = &a.realization;
+    mk(&a, OP_ADD, 9);
+    CHECK(ra == &a.realization && omega_exec_native_f3(&a.realization, 5, 0, 0, &y) == 0 && y == 14,
+          "rewritten in place: new code runs (got %llu, stale mapping gives 10)", (unsigned long long)y);
+    mk(&a, OP_ADD, 5);
+    omega_exec_native_cache_stats(&s0);
+    CHECK(omega_exec_native_f3(&a.realization, 5, 0, 0, &y) == 0 && y == 10, "rewritten back: original result");
+    omega_exec_native_cache_stats(&s1);
+    CHECK(s1.hits == s0.hits + 1 && s1.misses == s0.misses, "rewritten back: hit on the resident mapping");
+
+    /* fill past capacity: every program still computes right after eviction */
+    omega_exec_native_cache_reset();
+    for (unsigned i = 0; i < 2 * OMEGA_EXEC_CACHE_SLOTS + 3; i++) {
+        OmegaProgram p; mk(&p, OP_ADD, 1000 + i);
+        CHECK(omega_exec_native_f3(&p.realization, i, 0, 0, &y) == 0 && y == 1000 + 2ull * i, "evict loop %u", i);
+    }
+    omega_exec_native_cache_stats(&s1);
+    CHECK(s1.resident == OMEGA_EXEC_CACHE_SLOTS, "resident capped at %u (got %llu)", OMEGA_EXEC_CACHE_SLOTS, (unsigned long long)s1.resident);
+    CHECK(omega_exec_native_f3(&a.realization, 10, 0, 0, &y) == 0 && y == 15, "a still right after eviction");
+
+    /* LRU victim: fill every slot, touch the oldest, add one more. The second oldest is evicted and
+     * the touched one stays resident. */
+    static OmegaProgram lru[OMEGA_EXEC_CACHE_SLOTS + 1];
+    omega_exec_native_cache_reset();
+    for (unsigned i = 0; i <= OMEGA_EXEC_CACHE_SLOTS; i++) mk(&lru[i], OP_ADD, 2000 + i);
+    for (unsigned i = 0; i < OMEGA_EXEC_CACHE_SLOTS; i++)
+        CHECK(omega_exec_native_f3(&lru[i].realization, 1, 0, 0, &y) == 0 && y == 2001ull + i, "lru fill %u", i);
+    CHECK(omega_exec_native_f3(&lru[0].realization, 1, 0, 0, &y) == 0 && y == 2001, "lru touch oldest");
+    CHECK(omega_exec_native_f3(&lru[OMEGA_EXEC_CACHE_SLOTS].realization, 1, 0, 0, &y) == 0 && y == 2001ull + OMEGA_EXEC_CACHE_SLOTS,
+          "lru one past capacity");
+    omega_exec_native_cache_stats(&s0);
+    CHECK(s0.evictions == 1 && s0.resident == OMEGA_EXEC_CACHE_SLOTS, "lru: exactly one eviction (got %llu)",
+          (unsigned long long)s0.evictions);
+    CHECK(omega_exec_native_f3(&lru[0].realization, 1, 0, 0, &y) == 0 && y == 2001, "lru touched entry result");
+    omega_exec_native_cache_stats(&s1);
+    CHECK(s1.hits == s0.hits + 1 && s1.misses == s0.misses, "lru: the recently touched entry is still resident");
+    CHECK(omega_exec_native_f3(&lru[1].realization, 1, 0, 0, &y) == 0 && y == 2002, "lru evicted entry result");
+    omega_exec_native_cache_stats(&s0);
+    CHECK(s0.misses == s1.misses + 1 && s0.hits == s1.hits, "lru: the least recently used entry was the one evicted");
+
+    printf("EXEC_NATIVE_CACHE: %s (%d failures)\n", fails ? "FAIL" : "PASS", fails);
+    return fails ? 1 : 0;
+}