# size-cold-tables: result **Outcome: no change kept. The 0.99x target was missed; the best entry for this lever is the unchanged base (ratio 1.0000).** Every table swap that could be built saved bytes but added instructions on a scored path, and lost on all three seeds. `entry.c` is byte-identical to the base (sha256 `88617bb49e36a06cabd7d84ce6fe504ee337f8f41ad7c55bc72f696db94060c3`), so `patch.diff` is empty. The rejected patches and their measurements are in `rejected/`. Nothing was registered, signed, submitted or spent. ## Setup - Kit at `5a32428ad4aa23bce737d50a738ace24ddeeed2e`; `python -m eik setup` succeeded. - Measurement fingerprint `2c8fd1f3a6711f0639685319fb25262b02bfecf4c6589c52cb58928270a46322` (matches the brief). Sandbox mode `none`: bubblewrap cannot nest on this machine. - The machine has no pip or venv, so the four pinned wheels were fetched from PyPI and their sha256 checked against `requirements.txt`. - Only the base was scored; no other former champion. ## Final table (final = base) thumbv6m, `--no-sample`. Per-class values are mean retired instructions (typical / wide / hard). | seed | base S | new S | ratio | bytes | sigmoid t/w/h | tanh t/w/h | exp t/w/h | |---|---|---|---|---|---|---|---| | 1001 | 40.3574 | 40.3574 | 1.0000 | 20500 | 37.77 / 28.62 / 47.75 | 37.07 / 20.64 / 76.37 | 42.82 / 34.68 / 57.37 | | 2002 | 40.3698 | 40.3698 | 1.0000 | 20500 | 37.87 / 29.14 / 46.94 | 36.88 / 20.80 / 71.95 | 42.93 / 34.48 / 60.15 | | 3003 | 40.0637 | 40.0637 | 1.0000 | 20500 | 38.03 / 29.58 / 45.45 | 36.96 / 19.87 / 67.51 | 43.01 / 34.09 / 56.59 | - rv32im: 18,960 bytes, S 28.4863 / 28.5180 / 28.2202 on the three seeds; unchanged because the file is unchanged. - Size factor 1.1458, tail factor 1.0 for all three functions. - The per-class means are not in the `eik measure` report. They come from calling the kit's `eik.score.measure` directly on the same seeds (`measure/perclass_thumbv6m_base_seed*.json`). - Held-out seeds 4004/5005/6006 were not run (integration only). ## Size math used From the kit: S carries a factor `(1 + bytes/65536)^0.5`. At 20,500 bytes that is d lnS = 0.5 / 86,036 = 5.81e-6 per byte, so 1 KiB = 0.595% (the brief says 0.58%). One instruction is worth (class weight / 3) / class mean: about 0.43% on exp typical, 0.49% on sigmoid or tanh typical, and 0.06% on exp hard. So one typical-path instruction costs as much as about 740 to 840 bytes save. ## Swaps scored | swap | bytes | size gain (lnS) | measured S ratio, seeds 1001 / 2002 / 3003 | verdict | |---|---|---|---|---| | P1: `t_xrow` rows 32 -> 16 bytes; constant columns `t_rb`, `t_rK` become literals, two zero pad words dropped | 20500 -> 20320 | -0.105% | 1.01480 / 1.01452 / 1.01458 | rejected | | P2: four 8-byte constant structs (`t_skp`, `t_skn`, `t_skm`, `t_bk0`) hosted in the `t_xrow` pad words | 20500 -> 20468 | -0.019% | 1.00734 / 1.00714 / 1.00736 | rejected | | q-skp: `t_skp` alone | 20500 -> 20492 | -0.005% | 1.00156 / 1.00150 / 1.00157 | rejected | | q-skn: `t_skn` alone | 20500 -> 20492 | -0.005% | 1.00152 / 1.00150 / 1.00152 | rejected | | q-skm: `t_skm` alone | 20500 -> 20492 | -0.005% | 1.00062 / 1.00062 / 1.00066 | rejected | | q-bk0: `t_bk0` alone | 20500 -> 20492 | -0.005% | 1.00363 / 1.00352 / 1.00360 | rejected | | `t_exp_lo` (1024 bytes) replaced by computation | not built | -0.595% at most | not measured | rejected on the bound below | For every built variant the rv32im score and its `.text`/`.rodata` were identical to the base. The rv32im object file as a whole differs only in symbol and debug metadata. Per-class effect of the two main rejects, seed 1001 (the other seeds agree, see `rejected/perclass_*`): | variant | function | typical | wide | hard | |---|---|---|---|---| | P1 | exp | 42.82 -> 45.80 | 34.68 -> 35.70 | 57.37 -> 58.05 | | P2 | sigmoid | 37.77 -> 38.25 | 28.62 -> 28.88 | 47.75 -> 47.94 | | P2 | tanh | 37.07 -> 37.50 | 20.64 -> 20.84 | 76.37 -> 76.54 | ### Why they lose - **`t_xrow` (384 bytes).** It looks redundant: two columns are the same in all 12 rows and two are zero. But the exp main path loads five row words with one `ldm r5,{r1-r5}`, and the 32-byte stride makes the index one `lsls #5`. Moving the constants to literals turns one load into three and adds moves: about +3 instructions on exp typical for 180 bytes, when 180 bytes pays for about 0.24 of one. - **Pad-word hosting.** `.text` stays 4636 bytes, but clang then sees the selected pointers as offsets into one global and rewrites the selects, adding 0.07 to 0.5 instructions to the sigmoid and tanh means for 8 bytes each. - **`t_exp_lo` (1024 bytes).** This is the only Thumb table used solely on hard-case paths (`t_exp_res`, `t_mt`, `t_mn`). I checked numerically that `lo[m]` tracks the residual of 512·log2(`t_eps[m].t_aux` - 132) below the 2^-40 level (slope about 0.174 per 2^-40 on six sampled rows). It is a rounding residual with 16 unpredictable bits per row. - Recomputing it needs a logarithm or 2^(m/512) good to roughly 58 bits, on a core with no 32x32 -> 64 multiply. That is hundreds of instructions. - The budget is small: the hard means are 45 to 76, and one instruction on all three hard paths costs 0.033 x (1/57 + 1/72 + 1/47) = 0.17% of lnS. Break-even for the whole table is about 3.5 instructions (about 10 if only exp paid). - Narrowing it to 8 bits is not exact: the value enters `t_acc` shifted left 11, so dropping 8 bits moves a sign test on a 2^31 scale by up to 2^19. That flips about 1 in 4096 of the inputs that reach `t_exp_res`. UNVERIFIED by a build; the estimate was enough to drop it. - **No other cold table exists on the Thumb side.** `t_eps` has no zero or constant column. `t_crows` serves sigmoid for x <= -3.42, which typical draws hit often. `t_srow` and all 15 small constant structs are on scored paths. The sparse-fix and exception tables (`ext_r`, `tsr_r`, `small_exp_rows`) belong to the RV32IM path and are not in the Thumb object. `.rodata` has no alignment padding (symbol sizes sum to 15,740). ## Correctness of the delivered file (= base) | check | result | |---|---| | `eik check` | PASS, 42 functions, stack bound thumbv6m 312, rv32im 176 | | `eik fullcheck --function sigmoid` (all 2^32, ASan+UBSan) | passed, 0 mismatches, 4,294,967,296 words | | `eik fullcheck --function tanh` | passed, 0 mismatches, 4,294,967,296 words | | `eik fullcheck --function exp` | passed, 0 mismatches, 4,294,967,296 words | | `--quick` fullcheck, all three | passed, 0 mismatches | | `eik targetcheck --target thumbv6m` | **UNVERIFIED**: `qemu-arm is not installed (QEMU user mode)` | The rejected variants were measured only; none had a fullcheck, so their correctness is UNVERIFIED. ## Next steps 1. Stop spending on Thumb table size. The removable slack is under 200 bytes (0.1%) and each attempt disturbs code generation the base depends on. 2. If bytes are still wanted, the place is `.ARM.exidx`: 104 bytes, 8 per non-inlined function (13 functions). Merging two cold helpers saves 8 bytes each with no table change. That is outside this item's scope and UNVERIFIED. 3. Any item that edits `t_xrow`, the small `t_sk*`/`t_bk*` structs or their field order should expect the same effect: keep the five-word row and the 32-byte stride, and keep each constant struct a separate object. 4. The 0.939x takeover needs about 6% from instruction count on the typical paths; this lever contributes nothing towards it. ## Files in this directory - `entry.c` (= base), `patch.diff` (empty), `instruction-notes.md` - `measure/`: base and final reports per seed (identical), per-class JSON per seed - `logs/`: `check.log`, full and quick fullcheck logs, the targetcheck error, base `eik_exp` disassembly - `rejected/`: diffs, measure reports and per-class JSON for P1, P2 and the four single-struct variants, P1 disassembly