This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] New function to generate mp_no from powers of two
- From: Carlos O'Donell <carlos at systemhalted dot org>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 17 Jan 2013 09:43:08 -0500
- Subject: Re: [PATCH] New function to generate mp_no from powers of two
- References: <20130117110524.GE25252@spoyarek.pnq.redhat.com>
On 01/17/2013 06:05 AM, Siddhesh Poyarekar wrote:
> Hi,
>
> The __mpexp_twomm1 array (and a lot of unnecessary computation around
> it) is required in mpexp because there is currently no way to generate
> mp_no numbers that are powers of two. These are actually very simple
> numbers since they just have the exponent, sign and the first mantissa
> digit set and hence are a good special case to have (although I
> haven't done a code search to see yet if it's useful in any other
> functions). Attached patch implements an inline function __pow_mp
> (inline since it is not a very big or complicated function) and
> implements it in its first user, which is the __mpexp function. I
> have verified that this does not break any test cases on x86_64.
>
> Performance:
>
> With the patch:
>
> Total:26237847075, Fastest:255700, Slowest:893136, Avg:262378.470750
>
> Without the patch:
>
> Total:26245174617, Fastest:256384, Slowest:895106, Avg:262451.746170
>
> That's a miniscule improvement in performance (0.2% in the fastest
> case and barely 0.02% in the average case) but the real advantage is
> that the code is cleaner. The numbers are on top of the fast
> multiplication patch[1], which is why they're so low.
>
> OK to commit?
I like that you compute these numbers efficiently and just-in-time
with minimal text and data space used.
> [1] http://sourceware.org/ml/libc-alpha/2013-01/msg00614.html
>
>
> * sysdeps/ieee754/dbl-64/mpa.h (__pow_mp): New function to get an
> mp_no from a power of two.
> * sysdeps/ieee754/dbl-64/mpexp.c (__mpexp): Remove
> __mpexp_twomm1. Use __pow_mp.
>
>
> diff --git a/sysdeps/ieee754/dbl-64/mpa.h b/sysdeps/ieee754/dbl-64/mpa.h
> index debb3b2..70a3614 100644
> --- a/sysdeps/ieee754/dbl-64/mpa.h
> +++ b/sysdeps/ieee754/dbl-64/mpa.h
> @@ -123,3 +123,25 @@ extern void __mpsqrt (mp_no *, mp_no *, int);
> extern void __mpexp (mp_no *, mp_no *, int);
> extern void __c32 (mp_no *, mp_no *, mp_no *, int);
> extern int __mpranred (double, mp_no *, int);
> +
> +/* Given a power POW, build a multiprecision number 2^POW. */
> +static inline void
> +__pow_mp (int pow, mp_no *y, int p)
> +{
> + int i, rem;
> +
> + EY = pow / 24;
> + rem = pow - EY * 24;
> + EY++;
> +
> + if (rem < 0)
> + {
> + EY--;
> + rem += 24;
> + }
> + Y[0] = ONE;
> + Y[1] = 1 << rem;
> +
> + for (i = 2; i <= p; i++)
> + Y[i] = ZERO;
> +}
OK to commit if add a few more comments __pow_mp describing what
each step does.
Cheers,
Carlos.