Repository navigation
Pick host-FAR loops by the F32 math in their body (follow-up to #1814) - #1950
Conversation
#1814 made a long loop FAR on the host when a live parameter's top-level type is F32, which missed F32 held in a record or tuple and a generic parameter used at F32. SLP packs float arithmetic, so test the loop's emitted body for F32 ops instead: it sees every such case, at the same cost. The emitted C of all 1,867 benches, demos and tests is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
f500bd8 to
15dd428
Compare
|
Merged onto main 5c4d23e: repo 54/54, test 1783/1783, perf 124/124, ping 81/81, safe 0 false reject. Emitted C for the existing corpus matches main, as you said. The regex disagrees with main's type test in two directions, though, and one of them undoes part of #1814:
Suggestion: mark the segment when emit_intr emits an F32 arithmetic op (not conversions or compares), and OR that mark up from nested spins. This fixes 1 and 2 and drops the dependence on the text. A small test or pin that keeps nbody's loop FAR would guard #1814's gain. Nits: the header comment ("if it loops doing F32 math") should match whatever the check ends up doing, and "The host lets clang decide, but for a long F32 loop" reads better as "except for". |
Follow-up to #1814, which merged before this review point was addressed.
The change
#1814 made a long loop (
SPIN_FARchars,seg.spin) aFARcall on the host when one of its live parameters has top-level type F32 (ty_adt(A)?.k === "F32"). The reason is clang's SLP vectorizer. That type test misses:pos: Vec3), which still reaches the loop as separate 32-bit words;x: T) used at F32, sincety_adtof a type variable is null.SLP packs float arithmetic, not parameter types. This PR checks the loop's emitted C body for F32 ops instead (
f32_unbox(/f32_rewrap(, which every F32 op emits). That catches both cases above, because the body is fully concrete, and it skips a loop that only passes an F32 along without doing math on it. I also updated the comment onSPIN_FARand the runtime comment aboveDFAR, which still said "The host lets clang decide".Checks
Emitted C: all 1,867
.bendfiles underbench/runtime,demosandtests, compiled with-o x.con main and on this branch. Exit codes match (916 build, 951 fail, as on main). Every emitted file is byte-identical except the runtime comment line. The host-FARloops are still nbody's, raytrace's and one inapp_slash_boss_3d, so A long loop over F32 is a call on the host too: nbody 1.19x SEQ, 1.15x PAR (#1240) #1814's numbers still hold.Gates: repo 54/54, test 1783/1783. Ping is 80/81, and main fails the same case (a BendHub publish of
lic_bom--name.bend, which the local hub refuses). Perf is 123/124, and main shows the same: merkle's COMPILER cell sits at 1.14–1.16x on both, and main also went 123/124 in one run.Perf, alternating main and this branch (2 runs each):
No cell moves beyond run-to-run noise.
Size:
comp.tsis 65,917 ttok (main 65,907, cap 66,000).🤖 Generated with Claude Code