# sig-small-wide — result **Outcome: target missed. No change is kept; the delivered `entry.c` is the base, byte for byte.** The success criterion (thumbv6m sigmoid wide mean <= 25 with typical not up) was not reached. Every candidate inside this lever raised thumbv6m S on all three seeds, so by the keep rule ("keep only if thumbv6m S falls on all three seeds") none was kept. Best wide mean reached by a (rejected) candidate: 28.53 / 29.11 / 29.43 against base 28.62 / 29.14 / 29.58. Nothing was registered, signed, submitted or spent. ## 1. Setup | item | value | |---|---| | kit | conjectures-io/exact-integer-kernels-miner at 5a32428ad4aa23bce737d50a738ace24ddeeed2e | | `python -m eik setup` | passed ("incumbent registered as champion of rv32im, thumbv6m, overall") | | measurement fingerprint | 2c8fd1f3a6711f0639685319fb25262b02bfecf4c6589c52cb58928270a46322 (matches the brief) | | verifier fingerprint | ebbf9d5cac596a718532b34798dc452e4050d6940594005c44f9a729c699c5a8 | | harness mode | development, sandbox `none` (bubblewrap cannot nest on this machine) | | base entry.c sha256 | 88617bb49e36a06cabd7d84ce6fe504ee337f8f41ad7c55bc72f696db94060c3 (matches the brief) | | pinned wheels | capstone 5.0.9, pyelftools 0.33, unicorn 2.1.4, ziglang 0.17.1, installed with `--require-hashes` | No other former champion was scored. ## 2. Result table (delivered entry = base) `python -m eik measure entry.c --seed N --targets thumbv6m,rv32im --no-sample` | seed | base S (thumbv6m) | new S | ratio | thumbv6m bytes | sigmoid typical | sigmoid wide | sigmoid hard | sigmoid uniform | rv32im S | rv32im bytes | |---|---|---|---|---|---|---|---|---|---|---| | 1001 | 40.3574 | 40.3574 | 1.00000 | 20500 | 37.767 | 28.619 | 47.747 | 18.504 | 28.486294 | 18960 | | 2002 | 40.3698 | 40.3698 | 1.00000 | 20500 | 37.870 | 29.139 | 46.940 | 18.633 | 28.517988 | 18960 | | 3003 | 40.0637 | 40.0637 | 1.00000 | 20500 | 38.031 | 29.578 | 45.450 | 18.468 | 28.220217 | 18960 | Ratio to former 50 is 1.000 on every seed; the takeover threshold 0.939 is not approached by this item. `patch.diff` against the base is empty. ### Rejected candidates (measured, not kept) All three are the same idea (section 4, "guarded linear shortcut") in different shapes. | candidate | seed | S | ratio vs base | bytes | sig typical | sig wide | sig hard | sig uniform | |---|---|---|---|---|---|---|---|---| | v1: exps 116..118, 3 guard bits | 1001 | 40.4344 | 1.00191 | 20544 | 38.048 | 28.529 | 48.680 | 18.462 | | | 2002 | 40.4454 | 1.00187 | 20544 | 38.135 | 29.113 | 47.570 | 18.615 | | | 3003 | 40.1271 | 1.00158 | 20544 | 38.277 | 29.433 | 46.327 | 18.463 | | v3: exps 116..117, 5 guard bits | 1001 | 40.4498 | 1.00229 | 20544 | 38.052 | 28.661 | 48.513 | 18.479 | | | 2002 | 40.4399 | 1.00174 | 20544 | 38.139 | 29.092 | 47.403 | 18.651 | | | 3003 | 40.1256 | 1.00155 | 20544 | 38.286 | 29.443 | 46.160 | 18.470 | | v4: v1 with an unshared return tail | 1001 | 40.4460 | 1.00219 | 20556 | 38.050 | 28.586 | 48.680 | 18.474 | | | 2002 | 40.4572 | 1.00217 | 20556 | 38.136 | 29.174 | 47.570 | 18.625 | | | 3003 | 40.1403 | 1.00191 | 20556 | 38.279 | 29.503 | 46.327 | 18.474 | A fourth shape (v2: the shortcut moved to the end of the function with `goto`) compiled to exactly the same code as v1 (identical S, bytes and class means on all three seeds). For all rejected candidates rv32im S and bytes were identical to base, and the rv32im object's code and data sections were identical; only `.debug_*` and `.symtab` differed (line numbers). The harness's rv32im *image* hash therefore differs for them; for the delivered entry everything is identical because the file is the base. ## 3. Instruction-count notes (thumbv6m, base) Counted by tracing executed instructions in the kit's own emulator (`eik.emu.Core`, the same counter the score uses). `zig objdump` is not shipped in the pinned ziglang wheel, so the listing came from capstone on the executed blocks rather than from objdump. Wide inputs are drawn uniformly over biased exponents 96..134 and both signs (kit `eik/inputs.py`), so the wide mean is the mean of 78 exponent/sign cells. Base per-cell cost (300 random mantissas per cell): | biased exponent | meaning | positive | negative | path | |---|---|---|---|---| | 96..102 | abs(x) < 2^-24 | 14 | 14 | returns 0.5 | | 103..115 | 2^-24 .. 2^-11 | 23 | 23 | linear 0.5 + x/4 | | 116..121 | 2^-11 .. 2^-5 | 37.0..37.3 | 36.0..36.6 | cubic, 3 multiplies | | 122..124 | 2^-5 .. 0.25 | 42.0..42.8 | 43.3..44.0 | table | | 125..127 | 0.25 .. 2 | 32.5..32.8 | 32.0..36.0 | table (typical hot path) | | 128..130 | 2 .. 16 | 36.0..38.5 | 45.7 / 58.5 / 81.7 | table; negative side becomes exp-like | | 131..133 | 16 .. 128 | 17.9 / 16 / 16 | 71.9 / 68.7 / 58.4 | positive: returns 1.0; negative: exp path | | 134 | 128 .. 256 | 16 | 21 | returns 1.0 / 0 | Sum over the 78 cells is 2272 (mean 29.13). A wide mean of 25 needs the sum at 1950, i.e. 322 instructions removed across the cells. Exact traces of the in-scope paths: - **Returns 0.5 (14):** `push {r4,r5,r7,lr}; add r7,sp,#8; lsls r1,r0,#1; bmi; asrs r1,r1,#24; cmp r1,#0x7d; blt; cmp r1,#0x73; bgt; cmp r1,#0x67; bge; movs r0,#0x3f; lsls r0,r0,#24; pop`. Eleven of the 14 are prologue plus dispatch, three are the return. - **Linear (23):** the same 11, then `ldr r2,=0x7fffff; asrs r3,r0,#31; ands r0,r2; adds r0,r0,r2; subs r1,r3,r1; adds r1,#0x7f; lsrs r0,r1; eors r0,r3; ldr r1,=0x7e000001; adds r0,r0,r1; asrs r0,r0,#1; pop`. - **Returns 1.0 (16):** `push; add r7; lsls; bmi; cmp r0,#0; bmi; ldr r5; ldm r5!,{r1,r2}; subs r1,r1,r0; bmi; asrs r1,r1,#22; adds r1,#0xf8; cmp r1,#0xf6; bhi; ldr r0,[r2,#16]; pop`. - **Returns 0 (21):** `push; add r7; lsls; bmi; cmp r0,#0; bmi; ldr r5; ldm r5!,{r1,r2}; subs r2,r0,r2; bhs; lsrs r3,r2,#16; cmp r3,#0x82; bhi; lsrs r2,r2,#22; cmp r2,#9; bhs; subs r2,#10; cmp r2,#0xf2; blo; movs r0,#0; pop`. No stack spill, literal-pool surprise, outlined call or `__aeabi_*` helper appears on any of these paths. The single prologue `push {r4,r5,r7,lr}; add r7,sp,#8` is paid by every call because the function is non-leaf (rare branches call `t_sr`, `t_nr`, `t_mn`, `t_drb`, `t_sgr`, `t_exp_den`) and the compiler does not shrink-wrap it. ## 4. What was tried and why each was dropped ### 4.1 Guarded linear shortcut for exponents 116..118 (measured; rejected) Idea: inside the existing `t_es < 122` cubic branch, serve exponents 116..118 with the linear formula plus guard bits, falling through to the cubic code when the guard bits are all zero. Diff of v1 against the base: ```diff if (t_es < 122) { + if (t_es < 119) + { + uint32_t t_gs = (uint32_t) (((int32_t) t_w) >> 31); + uint32_t t_gq = ((t_w & 0x7fffffu) + 0x7fffffu) >> ((124u - ((uint32_t) t_es)) + t_gs); + if ((t_gq & 7u) != 0u) + { + return (uint32_t) (((int32_t) (((t_gq >> 3) ^ t_gs) + 0x7e000001u)) >> 1); + } + } uint32_t t_rr = 121u - ((uint32_t) t_es); ``` Integer bound (why it is exact). Write abs(x) = m * 2^(e-150) with m in [2^23, 2^24) and e in {116,117,118}. For x > 0 the series alternates with decreasing terms, so 1/2 + x/4 - x^3/48 < sigmoid(x) < 1/2 + x/4. In units u = 2^-25 (half an ulp in [0.5,1)), x/4 = m / 2^k with k = 127 - e, and the cubic term is d = x^3/48 / u < 2^(3(e-126)) * 2^25 / 48, which is at most 2^-24 * 2^25 / 48 = 0.0417 u (e = 118). The result is 0x3f000000 + floor((floor(v) + 1) / 2) with v = m/2^k - d. The linear code uses floor((m-1)/2^k) in place of floor(v). The two differ only if an odd integer j satisfies m/2^k - d < j <= (m-1)/2^k, which forces the fractional part of (m-1)/2^k to lie in [0, d). The code keeps 3 fraction bits of (m-1)/2^k and uses the fast result only when they are not all zero, i.e. fraction >= 0.125 > 0.0417. For x < 0, sigmoid(x) = 1 - sigmoid(-x); the unit is u' = 2^-26, the shift is one less (the `+ t_gs` term), and the cubic term is at most 0.0834 u' < 0.125, so the same 3-bit guard holds. v3 keeps 5 bits for e <= 117 (bounds 0.0052 u and 0.0104 u' against 0.03125). Confirmed exhaustively: `python -m eik fullcheck v1/entry.c --function sigmoid` gave 0 mismatches over 4,294,967,296 words under ASan+UBSan (sha256 prefix fffb8e7653e618b1). v3 and v4 were only checked by the measure run (0 wrong outputs on the scored inputs); their full-domain check is UNVERIFIED. Why it lost, from the traces and the per-exponent profile: | cells | base | v1 | cause | |---|---|---|---| | exp 116..118, both signs | 36.0..37.3 | 32.0..32.9 (fast path 30) | the shortcut; 1 in 8 inputs fall back at 49 | | exp 119..121, both signs | 36.0..37.3 | 39.0..39.6 | new `cmp r1,#0x76; bls` plus one relocated `b` | | exp 125..127 negative | 32.0 / 32.8 / 36.0 | 33.0 / 33.8 / 36.9 | block layout changed: `bhi` became `bls; b` on the hot typical path | | exp 130..131 positive | 38.5 / 17.9 | 38.8 / 18.1 | same layout effect on a rare branch | Net: wide -0.03 to -0.15, typical +0.25 to +0.28, hard +0.63 to +0.93, bytes +44. With the objective's score math (typical 0.183/mean, wide 0.1/mean) that is about +0.13% from typical and -0.03% from wide; measured S rose 0.16% to 0.19%. The 44 bytes added in the first quarter kilobyte of the function are enough to make clang's block placement add one unconditional branch to the negative 0.25..2 path, which carries about a quarter of typical inputs. Even with a perfect layout the idea is worth little: about -4.5 on 6 cells and +2 on 6 cells is -0.2 on the wide mean (about -0.07% S), minus 0.025% for the bytes. ### 4.2 Analysed and not built (no instruction saved, or others pay) These were worked out on the disassembly; none was measured, so each conclusion is by instruction counting, UNVERIFIED by a build. - **Frameless exit for abs(x) < 2^-11 through a leaf wrapper that tail-calls the rest.** Saves 2 on 40 wide cells, but every other input pays at least the extra `b` (and the exponent test again if the wrapper only tests "small"). Count: typical +1 on about 95% of inputs is +0.46% S; wide gains at most 0.54 instructions, -0.19% S. Net loss. This is the same failure as the prior job's shared guard. Whether clang emits a Thumb-1 tail call here at all was not tested. - **Reordering the four-way split below exponent 125.** Today each of the four ranges pays two compare/branch pairs. Testing "abs(x) < 2^-24" first takes 2 off 14 wide cells and 40% of uniform inputs but adds 2 to either the linear range (26 cells) or the 122..124 range (7.7% of typical). Every ordering is a net loss. - **Shorter linear formula.** The 11 instructions are: 3 for (frac + 0x7fffff), 1 for the sign mask, 2 for the shift count, 1 shift, 1 xor, 3 for the rounding constant and final shift. A sign branch instead of the mask and xor costs the same 2. A left-shift form overflows 32 bits. A rotate (to get a modulo-32 count for free) leaves the dropped bits in the word and needs a clearing instruction. A shift count of 32 or more would merge the 0.5 range into the formula on ARM but is undefined in C and would fail the UBSan full check. No 10-instruction form was found. - **Return of 0.5 in two instructions.** Needs a literal load instead of `movs; lsls`; clang's choice, not expressible in C without a table (which costs an address load). - **Saturation exits.** Returning 1.0 costs 6 instructions after the shared table-limit test, of which 4 are one range check that separates "near 1", "exactly 1" and NaN at once; any replacement with direct compares needs two 32-bit literals and is longer. Returning 0 could be made 1 to 3 shorter only by adding 1 to 2 instructions to the exp-like path that serves negative exponents 129..133 (about 4.5 wide cells against 1). - **Removing the `(t_w * t_w) == 5u` block in the cubic branch.** It is unreachable (a square is 0, 1 or 4 mod 8), but its `goto`s into the table paths are what make clang keep the table descriptors as `ldm` multi-loads. Left untouched. ### 4.3 Where the 322 instructions actually are The in-scope cells cannot supply them: the 0.5 and linear cells total 794, the saturating cells 85, and their prologue-plus-dispatch floor is 11 and 10 instructions. The mass is on the negative side of exponents 128..133, 385 instructions over 6 cells (mean 64, peak 81.7 at exponent 130), where sigmoid runs an inlined exp kernel of about 60 instructions. Bringing those six cells to the positive side's cost (about 37) would by itself take the wide mean from 29.1 to about 27; it is outside "small and saturating" and was left for the item that owns that path. ## 5. Correctness of the delivered file (the base) | check | result | |---|---| | `python -m eik check entry.c` | PASS; 42 functions; bytes rv32im 18960, thumbv6m 20500; stack bound rv32im 176, thumbv6m 312 | | `fullcheck --function sigmoid` (all 2^32, ASan+UBSan) | passed, 0 mismatches, 4,294,967,296 words | | `fullcheck --function tanh --quick` | passed, 0 mismatches, 134,217,728 words | | `fullcheck --function exp --quick` | passed, 0 mismatches, 134,217,728 words | | `targetcheck --function sigmoid --target thumbv6m` | **UNVERIFIED**: the harness answered `InfraError: qemu-arm is not installed (QEMU user mode)` | | measure, seeds 1001/2002/3003, thumbv6m and rv32im | verdict passed, 0 wrong outputs, thumbv6m peak stack 60 bytes | Held-out seeds 4004/5005/6006 were not used (integration only). ## 6. Next steps for the goal 1. Treat the function's block layout as part of the measurement: a 44-byte insertion early in `t_eik_sigmoid` cost +0.27 on typical by itself. Any item that adds code to this function should re-profile exponents 125..129 on both signs and place new code after the hot blocks or in a callee. 2. The remaining wide mass in sigmoid is the negative exp-like path (exponents 129..133). A shorter kernel there, or a dedicated table for x in [-16, -8), is the only place where wide can fall by whole instructions. 3. One instruction on every call would come from making the prologue cheaper (a leaf function has no need for `lr` and `r7`), which requires every rare-path helper to be inlined or tail-called. Untested here; it changes the whole function and so belongs to a single item, not to several. ## 7. Files Only this file and `sources.json` are uploaded. The following sit beside it in `artifacts/goal/items/sig-small-wide/` on the worker and are not uploaded (the directory is git-excluded): `entry.c` (base, unchanged), `patch.diff` (empty), `measure/{base,final}-{1001,2002,3003}.json`, `measure/rejected-{v1,v3,v4}-*.json`, `rejected/{v1,v3,v4}.diff`, `logs/` (check, fullcheck reports, per-exponent profiles, rv32 object comparison, the targetcheck error).