math: optimize lrint on 32bit targets
commitca577951138127dcf4190a2eb3c7148b2ad6d779
authorSzabolcs Nagy <nsz@port70.net>
Mon, 16 Sep 2019 20:33:11 +0000 (16 20:33 +0000)
committerRich Felker <dalias@aerifal.cx>
Fri, 27 Sep 2019 15:18:59 +0000 (27 11:18 -0400)
treec8f2686823505275503dd12f38ab0c96bdb41fbf
parent604f8d3d8b08ee4f548de193050ef93a7753c2e0
math: optimize lrint on 32bit targets

lrint in (LONG_MAX, 1/DBL_EPSILON) and in (-1/DBL_EPSILON, LONG_MIN)
is not trivial: rounding to int may be inexact, but the conversion to
int may overflow and then the inexact flag must not be raised. (the
overflow threshold is rounding mode dependent).

this matters on 32bit targets (without single instruction lrint or
rint), so the common case (when there is no overflow) is optimized by
inlining the lrint logic, otherwise the old code is kept as a fallback.

on my laptop an i486 lrint call is asm:10ns, old c:30ns, new c:21ns
on a smaller arm core: old c:71ns, new c:34ns
on a bigger arm core: old c:27ns, new c:19ns
src/math/lrint.c