Blame view

include/div64.h 1.19 KB
7b64fef33   Wolfgang Denk   Add AVR32 archite...
1
2
3
4
5
6
7
8
9
10
  #ifndef _ASM_GENERIC_DIV64_H
  #define _ASM_GENERIC_DIV64_H
  /*
   * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
   * Based on former asm-ppc/div64.h and asm-m68knommu/div64.h
   *
   * The semantics of do_div() are:
   *
   * uint32_t do_div(uint64_t *n, uint32_t base)
   * {
53677ef18   Wolfgang Denk   Big white-space c...
11
12
13
   *	uint32_t remainder = *n % base;
   *	*n = *n / base;
   *	return remainder;
7b64fef33   Wolfgang Denk   Add AVR32 archite...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   * }
   *
   * NOTE: macro parameter n is evaluated multiple times,
   *       beware of side effects!
   */
  
  #include <linux/types.h>
  
  extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
  
  /* The unnecessary pointer compare is there
   * to check for type safety (n must be 64bit)
   */
  # define do_div(n,base) ({				\
  	uint32_t __base = (base);			\
  	uint32_t __rem;					\
  	(void)(((typeof((n)) *)0) == ((uint64_t *)0));	\
  	if (((n) >> 32) == 0) {			\
  		__rem = (uint32_t)(n) % __base;		\
  		(n) = (uint32_t)(n) / __base;		\
53677ef18   Wolfgang Denk   Big white-space c...
34
  	} else						\
7b64fef33   Wolfgang Denk   Add AVR32 archite...
35
36
37
  		__rem = __div64_32(&(n), __base);	\
  	__rem;						\
   })
3feb647f3   Sergei Poselenov   Add a do_div() wr...
38
39
40
41
42
43
44
45
46
  /* Wrapper for do_div(). Doesn't modify dividend and returns
   * the result, not reminder.
   */
  static inline uint64_t lldiv(uint64_t dividend, uint32_t divisor)
  {
  	uint64_t __res = dividend;
  	do_div(__res, divisor);
  	return(__res);
  }
7b64fef33   Wolfgang Denk   Add AVR32 archite...
47
  #endif /* _ASM_GENERIC_DIV64_H */