aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2018-07-04 09:54:29 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2018-07-04 15:45:21 +0100
commitdd178df04fc58d05cc2bd4c92efdb52cbd0d1bad (patch)
tree04551664899d82f874ae5cd22026a037ec786368
parentbc4b90122bd3e281f8086a83ef0616357c1f5d33 (diff)
downloadarm-optimized-routines-dd178df04fc58d05cc2bd4c92efdb52cbd0d1bad.tar.gz
Change the return type of converttoint and document the semantics
The roundtoint and converttoint internal functions are only called with small values, so 32 bit result is enough for converttoint and it is a signed int conversion so the natural return type is int32_t. The original idea was to help the compiler keeping the result in uint64_t, then it's clear that no sign extension is needed and there is no accidental undefined or implementation defined signed int arithmetics. But it turns out gcc does a good job with inlining so changing the type has no overhead and the semantics of the conversion is less surprising this way. Since we want to allow the asuint64 (x + 0x1.8p52) style conversion, the top bits were never usable and the existing code ensures that only the bottom 32 bits of the conversion result are used.
-rw-r--r--math/math_config.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/math/math_config.h b/math/math_config.h
index ee44468..ce6fac8 100644
--- a/math/math_config.h
+++ b/math/math_config.h
@@ -64,19 +64,23 @@
#endif
#if HAVE_FAST_ROUND
+/* When set, the roundtoint and converttoint functions are provided with
+ the semantics documented below. */
# define TOINT_INTRINSICS 1
-/* Round x to nearest int, ties have to be rounded consistently with
- converttoint. The result is in [-2^31+1, 2^31-1]. */
+/* Round x to nearest int in all rounding modes, ties have to be rounded
+ consistently with converttoint so the results match. If the result
+ would be outside of [-2^31, 2^31-1] then the semantics is unspecified. */
static inline double_t
roundtoint (double_t x)
{
return round (x);
}
-/* Convert x to nearest int, ties have to be rounded consistently with
- roundtoint. The result is in [-2^31+1, 2^31-1]. */
-static inline uint64_t
+/* Convert x to nearest int in all rounding modes, ties have to be rounded
+ consistently with roundtoint. If the result is not representible in an
+ int32_t then the semantics is unspecified. */
+static inline int32_t
converttoint (double_t x)
{
# if HAVE_FAST_LROUND