[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20100917000016.GA23616@redhat.com>
Date: Fri, 17 Sep 2010 02:00:16 +0200
From: Oleg Nesterov <oleg@...hat.com>
To: Brian Behlendorf <behlendorf1@...l.gov>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Ben Woodard <bwoodard@...l.gov>,
Jeremy Fitzhardinge <jeremy@...p.org>,
Mark Grondona <mgrondona@...l.gov>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Make div64_u64() precise on 32bit platforms
On 08/09, Brian Behlendorf wrote:
>
> > On Mon, 2 Aug 2010 18:09:51 +0200
> >
> > Oleg Nesterov <oleg@...hat.com> wrote:
> > > We have a bugreport which blames div64_u64() on 32bit platforms.
> > >
> > > However, the code obviously doesn't even try to pretend it can do
> > > the 64bit division precisely. If there is something in the high
> > > word of divisor, div64_u64() just shifts both arguments and throws
> > > out the low bits.
> >
> > Well that was a bit lazy of us - I wonder how hard it is to fix.
> >
> > At present people will test their code on 64-bit only to find out later
> > that it doesn't work correctly on 32-bit. Bad. Perhaps we should
> > similarly break the 64-bit version :)
>
> Here's an even crazier idea, let's just fix the 32-bit version. :)
>
> The attached patch fully implements div64_u64() such that it will return
> precisely the right quotient even when the divisor exceeds 32-bits. The
> patch also adds a div64_s64() function to fully support signed 64-bit
> division.
Well, since nobody commented this patch...
Personally I agree, it makes sense to make it precise/correct. I think
you should add CC's and resend the patch. Although I do not know who
can ack it authoritatively (probably Andrew ;).
I have no idea how much the fixed version is slower, and afaics the
current callers do not really care about precision. But we can always
add the old code back as div64_64_sucks_on_32_bit_but_faster().
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -162,6 +162,11 @@ extern int _cond_resched(void);
> (__x < 0) ? -__x : __x; \
> })
>
> +#define abs64(x) ({ \
> + s64 __x = (x); \
> + (__x < 0) ? -__x : __x; \
> + })
> +
Can't we just improve abs? Say,
#define abs(x) ({ \
typeof(x) __x = (x); \
(__x < 0) ? -__x : __x; \
})
> u64 div64_u64(u64 dividend, u64 divisor)
> {
> ...
> + } else {
> + n = __builtin_clzll(divisor);
This is a bit unusual. I mean, it is not that common to use gcc builtins
in the normal code. And, it seems, we can use __fls(divisor >> 32) or
just fls64() instead ?
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists