Re: do_div vs sector_t

Andrew Morton (akpm@osdl.org)
Fri, 11 Jul 2003 15:34:15 -0700


Matthew Wilcox <willy@debian.org> wrote:
>
> This almost works (the warning is harmless since gcc optimises away the call)
>
> # define do_div(n,base) ({ \
> uint32_t __base = (base); \
> uint32_t __rem; \
> if ((sizeof(n) < 8) || (likely(((n) >> 32) == 0))) { \
> __rem = (uint32_t)(n) % __base; \
> (n) = (uint32_t)(n) / __base; \
> } else \
> __rem = __div64_32(&(n), __base); \
> __rem; \
> })

Could we just do:

diff -puN include/asm-generic/div64.h~do_div-fix-43 include/asm-generic/div64.h
--- 25/include/asm-generic/div64.h~do_div-fix-43 Fri Jul 11 15:32:33 2003
+++ 25-akpm/include/asm-generic/div64.h Fri Jul 11 15:33:26 2003
@@ -34,7 +34,8 @@

extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);

-# define do_div(n,base) ({ \
+# define do_div(_n,base) ({ \
+ uint64_t n = _n; \
uint32_t __base = (base); \
uint32_t __rem; \
if (likely(((n) >> 32) == 0)) { \
@@ -42,6 +43,7 @@ extern uint32_t __div64_32(uint64_t *div
(n) = (uint32_t)(n) / __base; \
} else \
__rem = __div64_32(&(n), __base); \
+ _n = n; \
__rem; \
})

_

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