Re: [PATCH 1/4] introduce explicit signed/unsigned 64bit divide

From: Roman Zippel
Date: Fri Mar 14 2008 - 13:45:45 EST


Hi,

On Thu, 13 Mar 2008, Andrew Morton wrote:

> I think what happened was that [patch 3/4] fixed this up. Of course,
> that patch doesn't apply on this updated [1/4]. I _could_ just take the
> old [1/4] (I think), but I don't know if that wouild be bisection-friendly.
>
> Anyway, please redo&resend? Thanks.

Done.

> Please have a think about that code in arch/x86/kvm/i8254.c too. It is
> painful to see remote subsystems (re)implementing generic infrastructure.
> Can KVM use existing code? Should we hoist what KVM has done there into
> generic code? Did it have to use a(nother bleeding) macro?

Looker closer at it, div64_u64() seems to be a bit overkill, as the
divisor is a 32bit value, so the following should do the same job (only
compile tested):

u64 muldiv64(u64 a, u32 b, u32 c)
{
union {
u64 ll;
struct {
u32 low, high;
};
} u, res, rl, rh;

u.ll = a;
rl.ll = (u64)b * u.low;
rh.ll = (u64)b * u.high;
rh.ll += rl.high;
res.high = div_u64_rem(rh.ll, c, &rl.high);
res.low = div_u64(rl.ll, c);
return res.ll;
}

Moving it to a more generic location shouldn't be a big problem.

bye, Roman
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/