The FP fast paths of the lifted code check FPCR.RMode inside the result compare and pass vector slow-path operands through the Cpu

The result check of every scalar and vector FP op compares |r| against a per-thread threshold in the Cpu (fp_th_s,
fp_th_d): the smallest normal in round-to-nearest, NaN under a directed RMode, so a directed mode sends every result
to the redo path and the separate load and test of c->fpcr per op goes. rt_fpcr_threshold sets it; rt_fpcr_sync
calls it on every host, and the Cpu inits and the fiber switch's fpcr copy call it too.

The vector slow path FN(vredo) takes its operands from c->fp_arg instead of three stack copies per call site, which
takes ___chkstk_ms out of the large lifted functions (275 call sites in main to 5). It reruns only the lanes that
failed the check. A NaN result in round-to-nearest goes from redo straight to fix with the FZ-flushed operands. The
static FP helpers use preserve_most, so their cold call sites do not spill the caller-saved registers.

Results are bit-identical to the old headers (equivalence harness of build/v143-genko/static2, 200M cases).
On the 42 hottest 1.4.3 functions: instructions -8.2%, bytes -8.8%, hot-path instructions -4.3%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-15 00:31:00 +03:00
1 parent 94eb3d4628
commit 5c48f62fca
8 files changed
+89 -12

No files matched your search

+15
View File
@@ -17,7 +17,17 @@
typedef __uint128_t u128;
#define SI static inline __attribute__((always_inline))
// The noinline FP helpers are the slow paths of inline fast paths, called from cold blocks inside the lifted
// functions. preserve_most makes the helper save the caller-saved GPRs it clobbers, so a call site does not spill and
// reload its live values around the call. The helpers are static, so the convention never crosses a module boundary.
#if defined(__has_attribute)
#if __has_attribute(preserve_most)
#define SN static __attribute__((noinline, preserve_most))
#endif
#endif
#ifndef SN
#define SN static __attribute__((noinline))
#endif
#define SIMD_CAT2(a, b) a##_##b
#define SIMD_CAT(a, b) SIMD_CAT2(a, b)
@@ -274,6 +284,11 @@ SI void simd_rm_leave(unsigned old) {
// plain host FP gives the ARM result unless FPCR.RMode asks for directed rounding, which the slow paths handle.
SI int simd_directed(const Cpu *c) { return __builtin_expect((c->fpcr & FPCR_RM) != 0, 0); }
// FP result check threshold of the thread (cpu.h rt_fpcr_threshold), for one lane and for a whole vector.
SI float simd_th_s(const Cpu *c) { return c->fp_th_s[0]; }
SI double simd_th_d(const Cpu *c) { return c->fp_th_d[0]; }
SI vf32 simd_thv_s(const Cpu *c) { return *(const vf32 *)c->fp_th_s; }
SI vf64 simd_thv_d(const Cpu *c) { return *(const vf64 *)c->fp_th_d; }
#define F s
#define T float
#define U uint32_t