div64.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2000, 2004 Maciej W. Rozycki
  3. * Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org)
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. */
  9. #ifndef __ASM_DIV64_H
  10. #define __ASM_DIV64_H
  11. #include <asm-generic/div64.h>
  12. #if BITS_PER_LONG == 64
  13. #include <linux/types.h>
  14. /*
  15. * No traps on overflows for any of these...
  16. */
  17. #define __div64_32(n, base) \
  18. ({ \
  19. unsigned long __cf, __tmp, __tmp2, __i; \
  20. unsigned long __quot32, __mod32; \
  21. unsigned long __high, __low; \
  22. unsigned long long __n; \
  23. \
  24. __high = *__n >> 32; \
  25. __low = __n; \
  26. __asm__( \
  27. " .set push \n" \
  28. " .set noat \n" \
  29. " .set noreorder \n" \
  30. " move %2, $0 \n" \
  31. " move %3, $0 \n" \
  32. " b 1f \n" \
  33. " li %4, 0x21 \n" \
  34. "0: \n" \
  35. " sll $1, %0, 0x1 \n" \
  36. " srl %3, %0, 0x1f \n" \
  37. " or %0, $1, %5 \n" \
  38. " sll %1, %1, 0x1 \n" \
  39. " sll %2, %2, 0x1 \n" \
  40. "1: \n" \
  41. " bnez %3, 2f \n" \
  42. " sltu %5, %0, %z6 \n" \
  43. " bnez %5, 3f \n" \
  44. "2: \n" \
  45. " addiu %4, %4, -1 \n" \
  46. " subu %0, %0, %z6 \n" \
  47. " addiu %2, %2, 1 \n" \
  48. "3: \n" \
  49. " bnez %4, 0b\n\t" \
  50. " srl %5, %1, 0x1f\n\t" \
  51. " .set pop" \
  52. : "=&r" (__mod32), "=&r" (__tmp), \
  53. "=&r" (__quot32), "=&r" (__cf), \
  54. "=&r" (__i), "=&r" (__tmp2) \
  55. : "Jr" (base), "0" (__high), "1" (__low)); \
  56. \
  57. (__n) = __quot32; \
  58. __mod32; \
  59. })
  60. #endif /* BITS_PER_LONG == 64 */
  61. #endif /* __ASM_DIV64_H */