# exp-neg-direct-b: eik_exp Thumb negative domain, second independent attempt **Outcome: no improvement found. The best entry is the base itself (former-50 `entry.c`, unchanged).** None of the ideas tried here lowered thumbv6m S without breaking exactness or making the code larger. The success bar (thumbv6m exp typical mean <= 38.5) was **missed**: it stays at 42.82 / 42.93 / 43.01, which is 4.3 to 4.5 instructions short. `patch.diff` against the base is **empty**. The deliverable `entry.c` is byte-identical to the base (sha256 `88617bb49e36a06cabd7d84ce6fe504ee337f8f41ad7c55bc72f696db94060c3`). Only `result.md` and `sources.json` are delivered. The brief says "Write nothing else", and the patch is empty anyway. ## Setup (what actually ran, and how it differs from the reference setup) - Kit: `conjectures-io/exact-integer-kernels-miner` at `5a32428ad4aa23bce737d50a738ace24ddeeed2e`. Base: the prior repo at `c5e3f912…`, file `eik-work/baselines/former-50/entry.c`. Its sha256 matched `88617bb4…94060c3`. - `python3 -m venv` failed on this host because ensurepip is missing. I made a `venv --without-pip` and unpacked the pinned wheels by hand: capstone 5.0.9, pyelftools 0.33, unicorn 2.1.4, ziglang 0.17.1. All four sha256 values match `requirements.txt`. - **The host has no gcc.** `EIK_HOST_CC` was pointed at a wrapper that runs `zig cc` (the kit reads this variable: `HOST_CC = os.environ.get("EIK_HOST_CC", "gcc")`). `EIK_SANDBOX=none` was needed because bwrap's restricted PATH could not see the wrapper. - Because of these substitutions, the local **measurement fingerprint is `7c2a5228…6f55`, not the pinned `2c8fd1f3…46322`**. Instruction counts come from the pinned clang (ziglang 0.17.1) and unicorn 2.1.4, so they should match the reference. The host-compiler part of the fingerprint differs. **UNVERIFIED:** whether zig cc's ASan/UBSan give the same coverage as gcc's in fullcheck. - `python -m eik setup` then passed: "incumbent registered as champion of rv32im, thumbv6m, overall". ## Baseline = final (seeds 1001 / 2002 / 3003, `--targets thumbv6m,rv32im --no-sample`) The final entry is the base, so new S = base S and the ratio is 1.0000 on every seed. | seed | base S thumbv6m | new S | ratio | bytes thumb / rv32 | rv32im S | exp typical | exp wide | exp hard | exp uniform | |---|---|---|---|---|---|---|---|---|---| | 1001 | 40.3574 | 40.3574 | 1.0000 | 20500 / 18960 | 28.4863 | 42.824 | 34.677 | 57.367 | 20.369 | | 2002 | 40.3698 | 40.3698 | 1.0000 | 20500 / 18960 | 28.5180 | 42.928 | 34.483 | 60.147 | 19.898 | | 3003 | 40.0637 | 40.0637 | 1.0000 | 20500 / 18960 | 28.2202 | 43.012 | 34.088 | 56.587 | 19.932 | Other thumbv6m classes, for reference: | seed | sigmoid typ / wide / hard | tanh typ / wide / hard | |---|---|---| | 1001 | 37.767 / 28.619 / 47.747 | 37.072 / 20.642 / 76.370 | | 2002 | 37.870 / 29.139 / 46.940 | 36.884 / 20.803 / 71.950 | | 3003 | 38.031 / 29.578 / 45.450 | 36.958 / 19.867 / 67.507 | These agree with the objective's figures for former 50 (S 40.43, 20,500 bytes, exp typical about 42.9). Held-out seeds 4004/5005/6006 were not run because there is no candidate to integrate. ## Instruction-count notes (thumbv6m, base) I profiled all 6000 typical exp inputs (seeds 1001+2002+3003 together) in the kit emulator. Mean 42.92. - **Negative x, |x| in [2^-9, 8)** (biased exponent 118..129, about 81% of typical inputs): **41 instructions** on the fast exit. **90** when the guard band trips, which is about 2% of these inputs (e.g. e=127: 1254x41, 27x90). - Negative x, |x| in [8,16) (e=130): 65 instructions, 33 of 6000 inputs. - Positive x (about 18%, out of scope): 48 fast, 98 slow. Annotated 41-instruction negative fast path (x = -1.5, `0xBFC00000`): ``` push {r4,r5,r7,lr}; add r7,sp,#8 2 prologue + frame pointer asrs r2,r0,#23; adds r2,#138; cmp r2,#11; bls 4 s = exponent row index lsls r1,r2,#5; ldr r2,=t_xrow; adds r5,r2,r1; ldm r5,{r1-r5} 4 row C,tb,M,K,B muls(M*w); lsrs(w>>9); muls(*C); adds(+B); lsrs(kb=>>15); muls(K*kb); rors(kb,B); adds(P0); lsrs(kb>>19) 9 argument reduction, kb rotate ldr T,[tb,idx] 1 table cell (t_eps[j].t_aux) lsls/lsrs(c2=(T<<10)>>17); lsrs(c1=T>>22); asrs(P0>>10); muls; asrs>>17; adds; asrs(P0>>16); muls; asrs>>9; adds; asrs>>9; adds(Z=T+..) 12 degree-2 polynomial bpl (Z<0 means no binade crossing) 1 uxtb; cmp #5; bhs 3 guard band (Z&255) >= 5 lsls(kb<<23); lsrs(Z>>8); adds; pop {..,pc} 4 pack result, return ``` There were no `__aeabi_*` calls, spills or stack traffic on this path. The slow exit is `bl t_exp_res`, a separate function with its own push/`add r7`/pop, about 5 instructions of call overhead plus 3 literal loads. That path costs 49 extra instructions. ## Ideas tried (all rejected, with evidence) All error and mismatch checks below were exhaustive over the input range they touch: 2^23 inputs per exponent row. They used a native harness (zig cc, `#define EIK_SEL 0` so the t_ paths run on the host), compared bit-for-bit with the base `eik_exp`. The base had passed a 3% fullcheck (below), and the base is the validator-accepted former champion. ### 1. Measured error of the fast estimate Z (needed for any band or guard change) Define err = Z − 256·(m + 0.5), where m is the exact scaled mantissa from `expl`. Over all 100,658,830 negative fast-path inputs (s = 0..11, plus 4,466 binade-crossing tail inputs), err lies in **[−0.614, +5.269]** Z-units (1 unit = 2^-8 ulp). The upper bound grows with |x|: s=0..4 ≤ 3.07, s=5 3.34, s=6 3.56, s=7 3.94, s=8 4.21, s=9 4.34, s=10 4.58, s=11 5.27. The growth comes from the reduction constant K = 1317922824 = 2^32 − 2977044472, where 2977044472 = round(ln2·2^32). Its rounding error is about 0.18 units of 2^-41 per step of kb, and kb runs up to about 64.5k because of the 126·512 exponent bias. Consequence: the error spread is about 5.9 units wide, so a 2-instruction `lsls #24; beq` guard (band 1) is impossible without a more accurate polynomial, and that would cost more than the 1 instruction it saves. ### 2. Narrower guard band (cmp #5 → #4 or #3): zero code-size cost, fewer slow exits Exhaustive mismatches with the base rows: | s (|x| range) | band 3 | band 4 | |---|---|---| | 0 [2^-9,2^-8) | 51 | 0 | | 1–4 | 0 | 0 | | 5 | 581 | 0 | | 6 | 687 | 0 | | 7 | 2492 | 0 | | 8 [0.5,1) | 2987 | 9 | | 9 [1,2) | 4752 | 39 | | 10 [2,4) | 9047 | 209 | | 11 [4,8) | 22718 | 2992 | Then I re-tuned each row's kb rounding offset (the residual in `t_rB`, scanned 16384..49152 in steps of 512, 65 values per row) to see whether band 4 could become exact for s=8..11. Best mismatch counts: s=8 → 7, s=9 → 32, s=10 → 200, s=11 → 2969. **None reaches 0, so band 4 is rejected.** Even if it had worked, the gain was at most 1/256·49·0.82 ≈ 0.16 instructions of typical mean (about 0.07% of S). A per-row band for s=0..7 only (free through the spare `t_rz` field in the `ldm`) would be worth about 0.03 instructions and was not pursued. ### 3. Extend the `t_xrow` direct path to |x| in [8,64) (s = 12..14) Reverse-engineered row layout, checked against all 12 base rows: - C = −round(2^(s+1)/ln2) - M = −(512<>17` it replaces, so no gain. Changing shared cells would break the other functions. - **Dropping the push/frame pointer (2 instructions)** by keeping the fast path in r0–r3: splitting the 5-register `ldm` into two `ldm`s plus a literal for `tb` adds about 2 instructions, so the net is about 0. Not built. - **Floor reduction** to remove the `bpl`/tail branch: |r| doubles, the cubic term adds about 1.8 units of spread (band ≥ 7), and the slow path would also need rework. The estimated net is ≤ 0. Not built. - **Inlining `t_exp_res` on the slow exit:** saves about 4 instructions × 2% ≈ 0.08 instructions but adds about 110 bytes. The size cost (≈ 0.06% of S) is larger than the gain (≈ 0.04%). Rejected. **Which idea wins between this item and `exp-neg-direct`:** none of this item's ideas improves S. Whatever `exp-neg-direct` produces should be preferred if it passes the checks. This item's useful output is the bounds above, which rule out the band-narrowing and row-extension routes. ## Correctness checks on the final file (= base) - `python -m eik check entry.c`: **PASS** `{"functions": 42, "bytes": {"rv32im": 18960, "thumbv6m": 20500, "thumbv7em": 21254}, "stack_bound": {"rv32im": 176, "thumbv6m": 312, "thumbv7em": 280}}` - `python -m eik fullcheck entry.c --function exp --quick`: **passed**, mismatches 0, words_checked 134,217,728. The host build used zig cc, not gcc (see the setup notes). - Full 2^32 fullcheck and `targetcheck`: **not run** (UNVERIFIED locally). No function was changed, and the brief requires those only for changed functions. qemu-user is not installed here. - rv32im object: unchanged (same source; 18,960 bytes, image sha `4273ba33…71a6` on all seeds). ## Next steps (ranked by expected value) 1. **Make the reduction more exact without extra instructions.** The 5.9-unit error spread is dominated by K·kb quantisation (s ≥ 8). Re-basing kb so the 126·512 bias is not multiplied by K (for example, folding the bias into the table index or into B) would shrink the spread. That could allow band 4 or lower for s=8..11 (about 0.16 instr) and would make rows s=12..14 feasible (about 0.3% of S). Each attempt can be screened exhaustively in about 2 seconds per row with the harness described above. 2. The largest remaining in-scope lever is the 41-instruction fast path itself. The 12-instruction polynomial and 4-instruction pack/return look minimal for this table format, so a real gain probably needs a different cell encoding (new table, at 0.58% per KiB) that takes c1 and c2 with a single shift each. 3. This item does not support a takeover. On its own it cannot get near 0.939x former 50. Never registered, signed, submitted or spent TAO.