# size-pack: pack the Thumb tables (item result) **Outcome: no change kept. The success bar (thumbv6m bytes <= 18,500) was not reached, and no packing change lowered thumbv6m S on any seed.** The delivered `entry.c` is the unchanged base (sha256 `88617bb4…94060c3`), and `patch.diff` is empty. I tried three table changes inside the lever. All three are measured below and rejected, and their diffs are in `rejected/`. The main finding: the Thumb tables are already dense. 99.3% of their bytes are read, no row is duplicated, and every remaining byte of slack can only be removed by adding instructions on the hot path. The size target cannot be reached by packing tables. It needs a change to the algorithm or the table design, which is outside this lever. ## Setup (what actually ran) - Kit `conjectures-io/exact-integer-kernels-miner` @ `5a32428a…`. The machine has no pip/ensurepip and no gcc. I fetched the pinned wheels from PyPI and checked them against the hashes in `requirements.txt`, then unpacked them into a `--without-pip` venv. - `eik setup` ran with `EIK_HOST_CC` set to a wrapper around the kit's own `zig cc`, because gcc is missing. - Consequence: the **measurement fingerprint is `7c2a5228…`, not the brief's `2c8fd1f3…`**. The host-CC identity is one input of that fingerprint. The target builds (zig clang 0.17.1, unicorn 2.1.4) are the pinned ones. My base S (40.36/40.37/40.06) matches the brief's former-50 figure of 40.43 within seed noise, and the bytes match exactly (20,500). - Base `entry.c` from the prior repo @ `c5e3f912…`: sha256 `88617bb49e36a06cabd7d84ce6fe504ee337f8f41ad7c55bc72f696db94060c3` (matches the brief). - No other champion was scored. Nothing was registered, signed or submitted. ## Results table (delivered file = base) | seed | base S | new S | ratio | thumb bytes | rv32im S / bytes | |---|---|---|---|---|---| | 1001 | 40.3574 | 40.3574 | 1.0000 | 20,500 | 28.4863 / 18,960 (identical) | | 2002 | 40.3698 | 40.3698 | 1.0000 | 20,500 | 28.5180 / 18,960 (identical) | | 3003 | 40.0637 | 40.0637 | 1.0000 | 20,500 | 28.2202 / 18,960 (identical) | Base thumbv6m per-class means (typical / wide / hard / uniform): | seed | sigmoid | tanh | exp | |---|---|---|---| | 1001 | 37.767 / 28.619 / 47.747 / 18.504 | 37.072 / 20.642 / 76.370 / 14.695 | 42.824 / 34.677 / 57.367 / 20.369 | | 2002 | 37.870 / 29.139 / 46.940 / 18.633 | 36.884 / 20.803 / 71.950 / 14.281 | 42.928 / 34.483 / 60.147 / 19.898 | | 3003 | 38.031 / 29.578 / 45.450 / 18.468 | 36.958 / 19.867 / 67.507 / 14.722 | 43.012 / 34.088 / 56.587 / 19.932 | Ratio against the 0.939 takeover threshold: 1.000. This item contributes nothing toward the takeover. ## Size budget of the base thumbv6m object (`logs/symbols-base-thumbv6m.txt`) `.text` 4,636 + `.rodata` 15,740 + `.rodata.cst16` 16 + `.rodata.cst4` 4 + `.ARM.exidx` 104 = **20,500** (this is how the kit computes the size). Tables: `t_eps` 11,664 (729 rows of 16 B), `t_crows` 1,572 (131 × 12), `t_exp_lo` 1,024, `t_srow` 896 (56 × 16), `t_xrow` 384 (12 × 32), parameter structs about 230 in total. Getting to 18,500 means removing 2,000 B, which is 17% of `t_eps` or 13% of all rodata. ## Why packing cannot get there (evidence) 1. **Read coverage** (`tools/cov.py`, `logs/coverage-base.txt`). I put a unicorn memory-read hook on the scored thumbv6m guest image. Inputs, for each of the 3 functions: 20k uniform words, 256 exponents × 2 signs × 78 mantissas, and 160k dense values in |x|<110 plus 2^-30..2^7. This is a sample, not exhaustive. Bytes that were never read: - `t_eps`: 16 of 11,664 (field 3 of rows 512, 513, 727, 728). - `t_srow`: 12 of 896 (field 3 of rows 6, 32, 55). - `t_xrow`: 96 of 384 (`t_rz`/`t_rz2` of all 12 rows; they are always 0). - `t_m1t`: 8 of 32. `t_tanh_sg`: 4 of 16. - `t_crows`, `t_exp_lo` and all other parameter structs: every byte read. Total slack is about 136 B, 7% of the target. 2. **No duplicates** (`tools/dup.py`). 0 duplicate rows in `t_eps`, `t_srow`, `t_crows` or `t_xrow`. No `t_srow` row occurs in `t_eps`. No prefix/suffix overlap between tables. `t_exp_lo` has 5 repeated u16 values, which cannot be merged because the table is indexed directly. 3. **Narrowing** (`tools/eps.py`). All four `t_eps` fields need the full 32 bits over the table. Only field `t_p` of rows 0–383 fits in u16 (126…5986; 768 B of high halves). Even there, the reader at base line 2817 uses the full word (`(t_p - …) >> 15`). Rows 0–511 are also indexed with a fixed 16-byte stride (`m << 4`, a single `lsls`) by the exp path. Narrowing would need a stride that is not a power of two or a split table, which adds at least 1 instruction on the exp typical path. That instruction costs about 0.45% of S, against 0.44% for the 768 B saved (0.58%/KiB), and only if the whole 768 B were saved. 4. **Score conversion.** The slack in item 1 (about 136 B) is worth about 0.08% of S at best. One added instruction on one function's typical path costs about 0.45%. Every way of reclaiming that slack added at least 0.4 instruction to a typical mean (see below). ## Changes tried (all rejected; diffs in `rejected/`, measure JSON in `measure/`) | variant | change | bytes | S 1001 / 2002 / 3003 | ratio | typical-mean change | |---|---|---|---|---|---| | vA | reorder `t_xr` to `{B2,C,rb,M,K,B,z,z}` so both exp paths could use one 5-register `ldm` (speed, 0 B) | 20,504 | 40.5748 / 40.5834 / 40.2765 | 1.0054 / 1.0053 / 1.0053 | exp +0.99 on all seeds | | vB | vA + drop unread `t_rz,t_rz2` (stride 32→24, saves 96 B) | 20,412 | 40.7663 / 40.7712 / 40.4637 | 1.0101 / 1.0099 / 1.0100 | exp +1.99 on all seeds | | vC | store `t_skp`, `t_skn`, `t_bk0` in the unused 8-byte tails of `t_xrow` rows 0–2 (union tail, no punning, stride kept) | 20,472 | 40.6275 / 40.6322 / 40.3312 | 1.0067 / 1.0065 / 1.0067 | sigmoid +0.41, tanh +0.43, exp 0 | In all three, rv32im S and bytes stayed identical: 28.4863 / 28.5180 / 28.2202 and 18,960. The rv32im image hash differs only because the source file name is embedded in the object. vB's 96-byte saving became 88 B in the image. Likely causes, from the disassembly: in vB the 24-byte stride replaces a single `lsls #5` with a multiply-or-shift-add sequence. In vC the moved objects lose the shared base and literal they had with the neighbouring `t_sk*` structs. In vA the compiler did not form a single `ldm` for the reordered row and added an extra literal (+4 B). None of the variants reached a correctness check, because each was rejected on score first. Their correctness is **UNVERIFIED** (not needed, since none is delivered). ## Instruction-count notes (base thumbv6m, `tools/tdis.py` on the guest image) - exp entry dispatch: `push; add r7; asrs #23; adds #138; cmp #11; bls` = 6 instructions before the `t_xrow` branch (exponent class 118–129, negative x). - `t_xrow` reader, negative path: `lsls r1,r2,#5; ldr r2,=t_xrow; adds r5,r2,r1; ldm r5,{r1-r5}` = **4 instructions** for address plus 5-field load. - `t_xrow` reader, positive path (`t_s &= 255` branch): `lsls #5; ldr =t_xrow; adds; ldm r5!,{r1-r4}; ldr r5,[r5,#4]` = **5 instructions**. The `ldr` for `t_rB2` is the one instruction vA tried to remove; it failed (+0.99 on exp typical). - `t_eps` exp lookup: `lsrs r3,r1,#19; ldr r2,[r2,r3]`. The row index is pre-shifted, with no multiply, and the base comes from the `t_xrow` field `t_rb`, so no literal load is needed. Any change to the `t_eps` stride breaks this two-instruction lookup. - No `__aeabi_*` calls, spills or new frames on these paths in base. vA, vB and vC were rejected on measured counts, so their disassembly was not examined further. ## Correctness checks on the delivered file (= base) - `eik check`: **PASS**, 42 functions. Bytes rv32im 18,960 / thumbv6m 20,500 / thumbv7em 21,254. Stack bound 176 / 312 / 280 (`logs/check.log`). - `eik fullcheck --quick --seed 1001` for sigmoid, tanh and exp: **passed**, 0 mismatches, 134,217,728 words each, UBSan+ASan built with zig cc (`logs/fullcheck-quick-*.log`). Full fullchecks were not run, because no function changed. - `eik targetcheck --target thumbv6m`: **UNVERIFIED**, `qemu-arm is not installed` (`logs/targetcheck-exp.log`). It was not needed because nothing changed. - Caveat on the host checks: on x86-64 `EIK_SEL` selects the RV path (signed `wchar_t`), so host fullcheck never runs the Thumb `t_` tables. To check Thumb-table edits on the host, I built `tools/eq.c` + `tools/run.sh`: it compiles two entries with `-DEIK_SEL=0` and compares them on all 2^32 inputs. Check of the harness itself: base with `EIK_SEL=0` against base with `EIK_SEL=1` gave **0 mismatches on all 2^32 inputs for sigmoid, tanh and exp**. A 32-bit host build, which would match Thumb pointer width, is killed by this sandbox (SIGSYS). The x86-64 build uses 8-byte pointers, so struct layouts that alias pointers differ from Thumb. Treat it as a strong screen, not as a substitute for `targetcheck`. ## Next steps (for the integrator) 1. Packing gives at most about 0.08% here. Spend no more items on it. Getting to 18,500 B needs a table redesign: - Fewer `t_eps` rows. 512 exp rows at 16 B is 8 KiB; a 256-row table with one extra correction term would save about 4 KiB at about +2 instructions. - Or share a table between functions: exp's `2^(k/512)` against tanh/sigmoid's rows 384–722. Use the score math: 4 KiB ≈ 2.3%, while +2 instructions on exp typical ≈ 0.85% of S. That is a net gain, but it belongs to a speed/size algorithm item, not to packing. 2. `.ARM.exidx` costs 104 B (13 functions × 8 B) even with `-fno-unwind-tables`. Inlining small helpers is outside this item's scope, but would remove 8 B per helper removed. 3. Reuse `tools/eq.c`/`run.sh` (Thumb path, all 2^32 inputs, about 15 s per function on 4 cores) as a fast screen for any `t_` edit before the 2^32 targetcheck, which needs qemu-arm. ## Files `entry.c` (base, unchanged) · `patch.diff` (empty: no change kept) · `measure/base-{1001,2002,3003}.json` (base = final) and `measure/v{A,B,C}-*.json` · `rejected/v{A,B,C}.diff` · `logs/` (check, quick fullchecks, targetcheck error, coverage, symbol sizes) · `tools/` (coverage, dup and narrowing scans, disassembler, variant generators, measure script, 2^32 equivalence harness).