aboutsummaryrefslogtreecommitdiff
path: root/soft-fp/extended.h
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2014-11-04 16:34:49 +0000
committerJoseph Myers <joseph@codesourcery.com>2014-11-04 16:34:49 +0000
commit2004e7fb76bd6806253436d63ab3bda7e24c9cc1 (patch)
treef3b91ec17f5d05879524bc75c2fd67d12c4290e0 /soft-fp/extended.h
parent97827bfc5f5e039f29766369035cf73f0df27888 (diff)
downloadglibc-2004e7fb76bd6806253436d63ab3bda7e24c9cc1.zip
glibc-2004e7fb76bd6806253436d63ab3bda7e24c9cc1.tar.gz
glibc-2004e7fb76bd6806253436d63ab3bda7e24c9cc1.tar.bz2
soft-fp: Add _FP_TO_INT_ROUND.
Continuing the series of patches adding soft-fp features from the kernel version of soft-fp to glibc so that glibc's version is able to replace the old fork of soft-fp in the kernel, this patch adds the last major such feature: _FP_TO_INT_ROUND, converting a floating-point number to an integer with rounding according to the current rounding direction (as opposed to truncating towards zero, which _FP_TO_INT does). The general structure of the implementation follows that of _FP_TO_INT, but of course is more complicated. As with glibc's _FP_TO_INT it works with raw input (the kernel versions of these macros predate the conversion of _FP_TO_INT and many other macros to raw or semi-raw input). I have not tried to work out what bugs there might be in the kernel version that this might fix; it's a from-scratch implementation based on _FP_TO_INT. Tested for powerpc (soft-float) that there is no change to the installed shared libraries; also tested with the libm tests with lrint / lrintf / llrint / llrintf made to use _FP_TO_INT_ROUND, to provide some test of the functionality. As we don't have benchmarks for those functions, I haven't actually included the soft-fp versions of them, although I expect them to be faster than the existing code (given that the existing code involves adding and subtracting numbers such as 0x1p52 to achieve the desired rounding, which is not particularly efficient when the underlying floating point is software floating point). 2014-11-04 Joseph Myers <joseph@codesourcery.com> * soft-fp/op-common.h (_FP_TO_INT_ROUND): New macro. * soft-fp/double.h [_FP_W_TYPE_SIZE < 64] (FP_TO_INT_ROUND_D): New macro. [_FP_W_TYPE_SIZE >= 64] (FP_TO_INT_ROUND_D): Likewise. * soft-fp/extended.h [_FP_W_TYPE_SIZE < 64] (FP_TO_INT_ROUND_E): New macro. [_FP_W_TYPE_SIZE >= 64] (FP_TO_INT_ROUND_E): Likewise. * soft-fp/quad.h [_FP_W_TYPE_SIZE < 64] (FP_TO_INT_ROUND_Q): New macro. [_FP_W_TYPE_SIZE >= 64] (FP_TO_INT_ROUND_Q): Likewise. * soft-fp/single.h (FP_TO_INT_ROUND_S): New macro.
Diffstat (limited to 'soft-fp/extended.h')
-rw-r--r--soft-fp/extended.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/soft-fp/extended.h b/soft-fp/extended.h
index d16fa66..117abfc 100644
--- a/soft-fp/extended.h
+++ b/soft-fp/extended.h
@@ -292,6 +292,8 @@ union _FP_UNION_E
# define FP_CMP_UNORD_E(r, X, Y, ex) _FP_CMP_UNORD (E, 4, (r), X, Y, (ex))
# define FP_TO_INT_E(r, X, rsz, rsg) _FP_TO_INT (E, 4, (r), X, (rsz), (rsg))
+# define FP_TO_INT_ROUND_E(r, X, rsz, rsg) \
+ _FP_TO_INT_ROUND (E, 4, (r), X, (rsz), (rsg))
# define FP_FROM_INT_E(X, r, rs, rt) _FP_FROM_INT (E, 4, X, (r), (rs), rt)
# define _FP_FRAC_HIGH_E(X) (X##_f[2])
@@ -494,6 +496,8 @@ union _FP_UNION_E
# define FP_CMP_UNORD_E(r, X, Y, ex) _FP_CMP_UNORD (E, 2, (r), X, Y, (ex))
# define FP_TO_INT_E(r, X, rsz, rsg) _FP_TO_INT (E, 2, (r), X, (rsz), (rsg))
+# define FP_TO_INT_ROUND_E(r, X, rsz, rsg) \
+ _FP_TO_INT_ROUND (E, 2, (r), X, (rsz), (rsg))
# define FP_FROM_INT_E(X, r, rs, rt) _FP_FROM_INT (E, 2, X, (r), (rs), rt)
# define _FP_FRAC_HIGH_E(X) (X##_f1)