From 2004e7fb76bd6806253436d63ab3bda7e24c9cc1 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 4 Nov 2014 16:34:49 +0000 Subject: 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 * 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. --- soft-fp/quad.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'soft-fp/quad.h') diff --git a/soft-fp/quad.h b/soft-fp/quad.h index b8cd3108a3..8b7f0a04c5 100644 --- a/soft-fp/quad.h +++ b/soft-fp/quad.h @@ -187,6 +187,8 @@ union _FP_UNION_Q # define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 4, (r), X, Y, (ex)) # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 4, (r), X, (rsz), (rsg)) +# define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \ + _FP_TO_INT_ROUND (Q, 4, (r), X, (rsz), (rsg)) # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 4, X, (r), (rs), rt) # define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_4 (X) @@ -311,6 +313,8 @@ union _FP_UNION_Q # define FP_CMP_UNORD_Q(r, X, Y, ex) _FP_CMP_UNORD (Q, 2, (r), X, Y, (ex)) # define FP_TO_INT_Q(r, X, rsz, rsg) _FP_TO_INT (Q, 2, (r), X, (rsz), (rsg)) +# define FP_TO_INT_ROUND_Q(r, X, rsz, rsg) \ + _FP_TO_INT_ROUND (Q, 2, (r), X, (rsz), (rsg)) # define FP_FROM_INT_Q(X, r, rs, rt) _FP_FROM_INT (Q, 2, X, (r), (rs), rt) # define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_2 (X) -- cgit v1.2.1