Skip to content
Commit 39b0191d authored by Szabolcs Nagy's avatar Szabolcs Nagy
Browse files

Clean up roundtoint and converttoint

Ideally single instruction is used for rounding and conversion that
round to the nearest integer independently of the current rounding mode,
otherwise the argument reduction in expf is not reducing into the
optimal range in non-nearest rounding mode.

AArch64 has the necessary instructions, both for rounding ties away from
zero (round function in C) and rounding ties to even (roundeven function
in TS 18661), originally the later was used, but the former can be
expressed in portable C code without relying on ACLE intrinsics.

A bit of complication is that round and lround are not always inlined as
a single instruction:
- gcc inlines lround with -fno-math-errno, but fails to inline
  (long)round as a single instruction (at least up to gcc-8).
- clang inlines (long)round, but not lround.

Portable code is still better than relying on arm_neon.h, so use the
round function when it works and keep the shift based rounding as
fallback (which only gives precise results in nearest rounding mode,
but is the optimal implementation for most targets).

HAVE_FAST_ROUND and HAVE_FAST_LROUND are set based on preprocessor
heuristics (user can override them with CFLAGS) for now, once there is
a configure script we can detect these at configure time.
parent 0d51c045
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment