longlong.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
  2. Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000
  3. Free Software Foundation, Inc.
  4. This definition file is free software; you can redistribute it
  5. and/or modify it under the terms of the GNU General Public
  6. License as published by the Free Software Foundation; either
  7. version 2, or (at your option) any later version.
  8. This definition file is distributed in the hope that it will be
  9. useful, but WITHOUT ANY WARRANTY; without even the implied
  10. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. /* Borrowed from gcc-3.4.3 */
  17. #define __BITS4 (W_TYPE_SIZE / 4)
  18. #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
  19. #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
  20. #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
  21. #define count_leading_zeros(count, x) ((count) = __builtin_clz(x))
  22. #define __udiv_qrnnd_c(q, r, n1, n0, d) \
  23. do { \
  24. UWtype __d1, __d0, __q1, __q0; \
  25. UWtype __r1, __r0, __m; \
  26. __d1 = __ll_highpart (d); \
  27. __d0 = __ll_lowpart (d); \
  28. \
  29. __r1 = (n1) % __d1; \
  30. __q1 = (n1) / __d1; \
  31. __m = (UWtype) __q1 * __d0; \
  32. __r1 = __r1 * __ll_B | __ll_highpart (n0); \
  33. if (__r1 < __m) \
  34. { \
  35. __q1--, __r1 += (d); \
  36. if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
  37. if (__r1 < __m) \
  38. __q1--, __r1 += (d); \
  39. } \
  40. __r1 -= __m; \
  41. \
  42. __r0 = __r1 % __d1; \
  43. __q0 = __r1 / __d1; \
  44. __m = (UWtype) __q0 * __d0; \
  45. __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
  46. if (__r0 < __m) \
  47. { \
  48. __q0--, __r0 += (d); \
  49. if (__r0 >= (d)) \
  50. if (__r0 < __m) \
  51. __q0--, __r0 += (d); \
  52. } \
  53. __r0 -= __m; \
  54. \
  55. (q) = (UWtype) __q1 * __ll_B | __q0; \
  56. (r) = __r0; \
  57. } while (0)
  58. #define udiv_qrnnd __udiv_qrnnd_c
  59. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  60. do { \
  61. UWtype __x; \
  62. __x = (al) - (bl); \
  63. (sh) = (ah) - (bh) - (__x > (al)); \
  64. (sl) = __x; \
  65. } while (0)
  66. #define umul_ppmm(w1, w0, u, v) \
  67. do { \
  68. UWtype __x0, __x1, __x2, __x3; \
  69. UHWtype __ul, __vl, __uh, __vh; \
  70. \
  71. __ul = __ll_lowpart (u); \
  72. __uh = __ll_highpart (u); \
  73. __vl = __ll_lowpart (v); \
  74. __vh = __ll_highpart (v); \
  75. \
  76. __x0 = (UWtype) __ul * __vl; \
  77. __x1 = (UWtype) __ul * __vh; \
  78. __x2 = (UWtype) __uh * __vl; \
  79. __x3 = (UWtype) __uh * __vh; \
  80. \
  81. __x1 += __ll_highpart (__x0);/* this can't give carry */ \
  82. __x1 += __x2; /* but this indeed can */ \
  83. if (__x1 < __x2) /* did we get it? */ \
  84. __x3 += __ll_B; /* yes, add it in the proper pos. */ \
  85. \
  86. (w1) = __x3 + __ll_highpart (__x1); \
  87. (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
  88. } while (0)