kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit e16a6ff438645bc74c6d4945681f8874801fc981
parent adf6b8fb78ceaaaf20abd899d484bc97a691696b
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Tue, 26 May 2026 15:40:46 -0700

rt: fix __fixtfsi overflow and auto-detect native runtime variant

Replace the generic __fixtfsi implementation with an explicit soft-float
conversion that handles exponent values >= 31 (saturating to INT_MIN/INT_MAX)
instead of invoking undefined behaviour through the shared fixint template.

Rewrite the default runtime-variant list to detect the host architecture and
OS at build time, so  builds only the native variant by default.
Add an explicit error when the host combination is unsupported.

Diffstat:
Mrt/lib/fp_tf/fp_tf.c | 33++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/rt/lib/fp_tf/fp_tf.c b/rt/lib/fp_tf/fp_tf.c @@ -415,7 +415,38 @@ COMPILER_RT_ABI fp_t __floatuntitf(tu_int a) { return __floatXiYf__(a); } #define FP_FIX_SUFFIX fixtfsi #include "fp_fixint_impl.inc" -COMPILER_RT_ABI si_int __fixtfsi(fp_t a) { return __fixint(a); } +COMPILER_RT_ABI si_int __fixtfsi(fp_t a) { + union { + fp_t f; + du_int u[2]; + } bits; + du_int lo; + du_int hi; + du_int sig_hi; + du_int mag; + int sign; + int exp; + int e; + + bits.f = a; + lo = bits.u[0]; + hi = bits.u[1]; + sign = (int)(hi >> 63); + exp = (int)((hi >> 48) & 0x7fffu); + if (!exp) return 0; + e = exp - 16383; + if (e < 0) return 0; + if (e >= 31) return sign ? (si_int)0x80000000u : (si_int)0x7fffffffu; + + sig_hi = (hi & 0x0000ffffffffffffull) | 0x0001000000000000ull; + if (e <= 48) { + mag = sig_hi >> (unsigned)(48 - e); + } else { + mag = (sig_hi << (unsigned)(e - 48)) | + (lo >> (unsigned)(112 - e)); + } + return sign ? -(si_int)mag : (si_int)mag; +} #undef fixint_t #undef fixuint_t