diff options
author | Joseph Myers <joseph@codesourcery.com> | 2014-11-04 16:34:49 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2014-11-04 16:34:49 +0000 |
commit | 2004e7fb76bd6806253436d63ab3bda7e24c9cc1 (patch) | |
tree | f3b91ec17f5d05879524bc75c2fd67d12c4290e0 /soft-fp/double.h | |
parent | 97827bfc5f5e039f29766369035cf73f0df27888 (diff) | |
download | glibc-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/double.h')
-rw-r--r-- | soft-fp/double.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/soft-fp/double.h b/soft-fp/double.h index 36a11a5..96d2432 100644 --- a/soft-fp/double.h +++ b/soft-fp/double.h @@ -182,6 +182,8 @@ union _FP_UNION_D # define FP_CMP_UNORD_D(r, X, Y, ex) _FP_CMP_UNORD (D, 2, (r), X, Y, (ex)) # define FP_TO_INT_D(r, X, rsz, rsg) _FP_TO_INT (D, 2, (r), X, (rsz), (rsg)) +# define FP_TO_INT_ROUND_D(r, X, rsz, rsg) \ + _FP_TO_INT_ROUND (D, 2, (r), X, (rsz), (rsg)) # define FP_FROM_INT_D(X, r, rs, rt) _FP_FROM_INT (D, 2, X, (r), (rs), rt) # define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_2 (X) @@ -304,6 +306,8 @@ union _FP_UNION_D # define FP_CMP_UNORD_D(r, X, Y, ex) _FP_CMP_UNORD (D, 1, (r), X, Y, (ex)) # define FP_TO_INT_D(r, X, rsz, rsg) _FP_TO_INT (D, 1, (r), X, (rsz), (rsg)) +# define FP_TO_INT_ROUND_D(r, X, rsz, rsg) \ + _FP_TO_INT_ROUND (D, 1, (r), X, (rsz), (rsg)) # define FP_FROM_INT_D(X, r, rs, rt) _FP_FROM_INT (D, 1, X, (r), (rs), rt) # define _FP_FRAC_HIGH_D(X) _FP_FRAC_HIGH_1 (X) |