[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v3 07/13] x86: Add functions for 64-bit integer arithmetic



>>> On 31.12.15 at 04:03, <haozhong.zhang@xxxxxxxxx> wrote:
> --- /dev/null
> +++ b/xen/include/asm-x86/math64.h
> @@ -0,0 +1,105 @@
> +#ifndef __X86_MATH64
> +#define __X86_MATH64
> +
> +/*
> + * Functions defined in this file are derived from Linux kernel
> + * (include/linux/math64.h).
> + */

This is not true. At least mul64() doesn't exist in Linux (as of 4.4-rc8).

> +static inline void mul64(u64 *lo, u64 *hi, u64 a, u64 b)
> +{
> +    typedef union {
> +        u64 ll;
> +        struct {
> +            u32 low, high;
> +        } l;
> +    } LL;
> +    LL rl, rm, rn, rh, a0, b0;
> +    u64 c;
> +
> +    a0.ll = a;
> +    b0.ll = b;
> +
> +    rl.ll = (u64)a0.l.low * b0.l.low;
> +    rm.ll = (u64)a0.l.low * b0.l.high;
> +    rn.ll = (u64)a0.l.high * b0.l.low;
> +    rh.ll = (u64)a0.l.high * b0.l.high;
> +
> +    c = (u64)rl.l.high + rm.l.low + rn.l.low;
> +    rl.l.high = c;
> +    c >>= 32;
> +    c = c + rm.l.high + rn.l.high + rh.l.low;
> +    rh.l.low = c;
> +    rh.l.high += (u32)(c >> 32);
> +
> +    *lo = rl.ll;
> +    *hi = rh.ll;
> +}

For this one in particular, but likely also for the others: If this was
put in include/xen/math64.h I might buy it. As an x86-specific
implementation this could (and should) be done with a single asm()
statement using the MUL instruction (I didn't check whether gcc
also offers a built-in, which then could be used generically).

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.