div64.h (c203e45f069af47ca7623e4dcd8c00bfba2722e4) | div64.h (911918aa7ef6f868c135505b0015e42072c54682) |
---|---|
1#ifndef _ASM_GENERIC_DIV64_H 2#define _ASM_GENERIC_DIV64_H 3/* 4 * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com> 5 * Based on former asm-ppc/div64.h and asm-m68knommu/div64.h 6 * 7 * The semantics of do_div() are: 8 * --- 18 unchanged lines hidden (view full) --- 27 uint32_t __rem; \ 28 __rem = ((uint64_t)(n)) % __base; \ 29 (n) = ((uint64_t)(n)) / __base; \ 30 __rem; \ 31 }) 32 33#elif BITS_PER_LONG == 32 34 | 1#ifndef _ASM_GENERIC_DIV64_H 2#define _ASM_GENERIC_DIV64_H 3/* 4 * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com> 5 * Based on former asm-ppc/div64.h and asm-m68knommu/div64.h 6 * 7 * The semantics of do_div() are: 8 * --- 18 unchanged lines hidden (view full) --- 27 uint32_t __rem; \ 28 __rem = ((uint64_t)(n)) % __base; \ 29 (n) = ((uint64_t)(n)) / __base; \ 30 __rem; \ 31 }) 32 33#elif BITS_PER_LONG == 32 34 |
35#include <linux/log2.h> 36 |
|
35extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); 36 37/* The unnecessary pointer compare is there 38 * to check for type safety (n must be 64bit) 39 */ 40# define do_div(n,base) ({ \ 41 uint32_t __base = (base); \ 42 uint32_t __rem; \ 43 (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ | 37extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); 38 39/* The unnecessary pointer compare is there 40 * to check for type safety (n must be 64bit) 41 */ 42# define do_div(n,base) ({ \ 43 uint32_t __base = (base); \ 44 uint32_t __rem; \ 45 (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ |
44 if (likely(((n) >> 32) == 0)) { \ | 46 if (__builtin_constant_p(__base) && \ 47 is_power_of_2(__base)) { \ 48 __rem = (n) & (__base - 1); \ 49 (n) >>= ilog2(__base); \ 50 } else if (likely(((n) >> 32) == 0)) { \ |
45 __rem = (uint32_t)(n) % __base; \ 46 (n) = (uint32_t)(n) / __base; \ 47 } else \ 48 __rem = __div64_32(&(n), __base); \ 49 __rem; \ 50 }) 51 52#else /* BITS_PER_LONG == ?? */ 53 54# error do_div() does not yet support the C64 55 56#endif /* BITS_PER_LONG */ 57 58#endif /* _ASM_GENERIC_DIV64_H */ | 51 __rem = (uint32_t)(n) % __base; \ 52 (n) = (uint32_t)(n) / __base; \ 53 } else \ 54 __rem = __div64_32(&(n), __base); \ 55 __rem; \ 56 }) 57 58#else /* BITS_PER_LONG == ?? */ 59 60# error do_div() does not yet support the C64 61 62#endif /* BITS_PER_LONG */ 63 64#endif /* _ASM_GENERIC_DIV64_H */ |