This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2] Use long for mantissa for generic mp code
- From: Richard Henderson <rth at twiddle dot net>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 13 Mar 2013 09:46:40 -0700
- Subject: Re: [PATCH v2] Use long for mantissa for generic mp code
- References: <20130226154206.GY21039@spoyarek.pnq.redhat.com> <512D04C2.4020505@twiddle.net> <CAAHN_R2buNZ6N0Q6K86yaTq2hz_uc-8MoNyrnTZO3DfC62q2ig@mail.gmail.com> <512D7D56.2030209@twiddle.net> <20130308123807.GA21984@spoyarek.pnq.redhat.com>
On 03/08/2013 04:38 AM, Siddhesh Poyarekar wrote:
> +typedef long mantissa_t;
> +typedef int64_t mantissa_store_t;
> +
> +#define TWOPOW(i) (1L << i)
> +
> +#define RADIX TWOPOW (24) /* 2^24 */
> +
> +/* Divide D by RADIX and put the remainder in R. D must be a non-negative
> + integral value. */
> +#define DIV_RADIX(d, r) \
> + ({ \
> + r = ((uint64_t) d) % RADIX; \
> + d /= RADIX; \
> + })
One unsigned divide and one signed divide is even worse than two signed
divides, surely. Perhaps it would be easier to just write
r = d & (RADIX - 1);
d >>= LG2_RADIX;
or whatever? Or just give up on being able to avoid the signed divide?
> +
> +/* Put the integer component of a double X in R and retain the fraction in
> + X. */
> +#define INTEGER_OF(x, i) \
> + ({ \
> + i = (mantissa_t) x; \
> + x -= i; \
> + })
We need a better comment here, since we're no longer talking about doubles.
Otherwise the patch looks good to me.
r~