# tanh-typ-cells: result **Outcome: target missed. No change survived the keep rule, so `entry.c` is the base file unchanged (ratio 1.0000).** Thumb tanh typical mean stays at 36.88-37.07 against the target of <= 33.5. Two micro-changes were built and measured; both made thumbv6m S worse on all three seeds and were reverted. Nothing was registered, signed or submitted. ## Setup - Kit: conjectures-io/exact-integer-kernels-miner at 5a32428ad4aa23bce737d50a738ace24ddeeed2e; `python -m eik setup` succeeded. Measurement fingerprint 2c8fd1f3a6711f0639685319fb25262b02bfecf4c6589c52cb58928270a46322 (matches the brief). - The machine has no pip/venv module; the pinned wheels from requirements.txt were installed with `--require-hashes` into a pip-less venv. Sandbox mode reported by the kit: `none`. - Base: former-50 entry.c, sha256 88617bb49e36a06cabd7d84ce6fe504ee337f8f41ad7c55bc72f696db94060c3 (confirmed). - Command per seed: `python -m eik measure FILE --seed N --targets thumbv6m,rv32im --no-sample`. ## Result table (final = base) | seed | base S thumbv6m | new S | ratio | bytes thumbv6m | tanh typical | tanh wide | tanh hard | tanh uniform | rv32im S / bytes | |---|---|---|---|---|---|---|---|---|---| | 1001 | 40.3574 | 40.3574 | 1.0000 | 20,500 | 37.072 | 20.642 | 76.370 | 14.695 | 28.4863 / 18,960 | | 2002 | 40.3698 | 40.3698 | 1.0000 | 20,500 | 36.884 | 20.803 | 71.950 | 14.281 | 28.5180 / 18,960 | | 3003 | 40.0637 | 40.0637 | 1.0000 | 20,500 | 36.958 | 19.867 | 67.507 | 14.722 | 28.2202 / 18,960 | The brief quotes former 50 at S 40.43 and tanh typical 37.6; on the three shared seeds I measured the figures above (typical 36.9-37.1). Held-out seeds 4004/5005/6006 were not run (integration only). ## Rejected trials | trial | change | S 1001 / 2002 / 3003 | tanh typical 1001 / 2002 / 3003 | bytes | rv32im | verdict | |---|---|---|---|---|---|---| | 1 | \|x\| in [2, 6.75): read the sign/exponent base relative to the bank pointer (3 rows appended to `t_eps`) instead of through the `t_tanh_sg` literal; expected -1 instruction on 42% of typical | 41.3852 / 41.4091 / 41.1028 | 39.419 / 39.230 / 39.287 | 20,556 | S and bytes identical | rejected: +2.5% S | | 2 | e = 124..127: index the cells from `t_t >> 17` with a biased base, to drop the mask literal; expected -1 on 53% of typical | 40.9275 / 40.9393 / 40.6210 | 39.336 / 39.117 / 39.164 | 20,524 | S and bytes identical | rejected: +1.4% S | Why they lost, from the disassembly (`trials/*.dis`): - Trial 1: keeping the bank pointer alive across the cell needs a seventh live value, so the compiler saved r6. Five pushed registers in a non-leaf function forced `sub sp, #4` at entry and `add sp, #4` before every return: +2 instructions on every tanh call, including the 10-instruction tiny-input path. - Trial 2: the compiler rewrote the two shifts as shift + mask literal and did not fold the out-of-object offset into the symbol literal, so the index became 7 instructions instead of 5 (extra `ldr` + `adds`). ## Instruction counts on the typical path (base) Full notes: `notes/instruction-counts.md`; per-exponent profiles for each seed: `notes/profile-base-seed*.txt`. | inputs | share of typical (seed 1001) | instructions | |---|---|---| | \|x\| in [2, 6.75) | 41.9% | 35 (33 for part of [4, 6.75)) | | [1, 2) | 22.6% | 37 | | [0.5, 1) | 15.7% | 34, 37 for 11% of them | | [0.25, 0.5) | 9.8% | 37 | | [0.125, 0.25) | 4.7% | 39 | | [2^-7, 2^-3) | 4.6% | 41 | | rounding fallback | about 0.8% of calls | 106-120 | ## Why the lever does not reach 33.5 Reaching 33.5 means removing about 3.5 instructions from every typical call. What the disassembly shows: 1. **Frame pointer.** Every function, leaf or not, begins `push; add r7, sp, #N`. That instruction is fixed by the build, not by the C source. 2. **Only two free callee-saved registers.** The hot paths already use r0-r5 fully. A seventh live value costs 2 instructions on every call (trial 1), which rules out anything that keeps a pointer or constant across the cell. 3. **Dispatch and indexing are at the Thumb-1 floor for this table layout.** Each alternative I worked through on paper (range check by shifts, mask via `ldm`, index from `w` or from `t`, testing e = 127 first) costs the same count or moves the cost onto the small-input paths that dominate the wide and uniform classes. 4. **Sign/exponent assembly on [2, 6.75) cannot drop below 4 instructions with the current cells.** Y carries the 23-bit mantissa plus 9 guard bits, filling the word. The base needed is 0x3F000000 + sign, and no shift pair on `w` produces it; the nearest (`(w>>24)<<24`) is one exponent step off. The offset cannot be folded into Y without wrapping. 5. **The cubic cell (13 instructions) is the real cost.** A quadratic cell would save about 7 instructions on 42% of typical, but by my estimate needs roughly 690 cells (about 8.3 KiB against 3.4 KiB now) to keep the fallback rate near 1%. At 0.58% per KiB that costs more than the roughly 1.3% it gains. This estimate is UNVERIFIED: no table was generated. ## Checks on the final file | check | result | |---|---| | `eik check` | PASS; bytes rv32im 18,960, thumbv6m 20,500; stack bound thumbv6m 312 | | `eik fullcheck --function tanh` (all 2^32, ASan+UBSan) | passed, 0 mismatches, 4,294,967,296 words | | `eik fullcheck --quick` tanh / sigmoid / exp (seed 1001) | passed, 0 mismatches, 134,217,728 words each | | `eik targetcheck --function tanh --target thumbv6m` | **UNVERIFIED**: `qemu-arm is not installed (QEMU user mode)` on this machine | | rv32im object | unchanged (file is byte-identical to the base) | No function was changed, so no new rounding guard or table needs a bound. ## Next steps - Retry trial 1's idea only if eik_tanh can be made to need no fifth saved register; otherwise it cannot win. - Trial 2's saving (one instruction on 53% of typical) needs the biased base to reach the code as a single literal. Loading it from a const struct costs a second load and cancels the gain; I found no C form that the pinned clang folds. - A cell layout with 7 guard bits instead of 9 would let the sign/exponent base on [2, 6.75) take 3 instructions instead of 4 (the offset then fits in Y). It needs regenerated tables and a full recheck; the cells may be shared with sigmoid (`t_skp` points into the same rows), which I did not confirm. - The larger remaining costs are outside this item's scope: the frame-pointer instruction on every call and the 10-instruction tiny-input path. ## Files (in `artifacts/goal/items/tanh-typ-cells/`) - `entry.c` (identical to base), `patch.diff` (empty) - `measure/base-{1001,2002,3003}.json`, `measure/final-{1001,2002,3003}.json` (final is the same file, same reports) - `logs/check.log`, `logs/fullcheck-full-tanh.log`, `logs/fullcheck-quick-{tanh,sigmoid,exp}.log`, `logs/targetcheck-tanh.log` - `notes/instruction-counts.md`, `notes/base-eik_tanh-thumbv6m.dis`, `notes/profile-base-seed*.txt` - `trials/`: diffs, measure JSON and disassembly for the two rejected trials