Re: [PATCH] bring sanity to div64.h and do_div usage

Roman Zippel
2002-02-08T19:05:34Z

Hi,

Troy Benjegerdes wrote:

> +#else /* USE_SLOW_64BIT_DIVIDES */
> + /*
> + * Nasty ugly generic C 64 bit divide on 32 bit machine
> + * No one seems to want to take credit for this
> + */
> + unsigned long low, low2, high;
> + low = (t) & 0xffffffff;
> + high = (t) >> 32;
> + res = high % base;
> + high = high / base;
> + low2 = low >> 16;
> + low2 += res << 16;
> + res = low2 % base;
> + low2 = low2 / base;
> + low = low & 0xffff;
> + low += res << 16;
> + res = low % base;
> + low = low / base;
> + t = low + ((long long)low2 << 16) +
> + ((long long) high << 32);

IMO this is large enough to put under lib/..., the rest could also be
put into asm-generic, from where the archs could include it, this would
avoid this:

> +#ifdef __USE_ASM
> +/* yeah, this is a mess, and leaves out m68k.... */
> +# if defined(CONFIG_X86) || define(CONFIG_ARCH_S390) ||
defined(CONFIG_MIPS)
> +# define __USE_ASM__
> +# endif
> +#endif

bye, Roman