muldi3.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* muldi3.c extracted from gcc-2.7.2.3/libgcc2.c and
  2. gcc-2.7.2.3/longlong.h which is: */
  3. /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  4. This file is part of GNU CC.
  5. GNU CC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU CC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details. */
  13. #ifdef CONFIG_CPU_HAS_NO_MULDIV64
  14. #define SI_TYPE_SIZE 32
  15. #define __BITS4 (SI_TYPE_SIZE / 4)
  16. #define __ll_B (1L << (SI_TYPE_SIZE / 2))
  17. #define __ll_lowpart(t) ((USItype) (t) % __ll_B)
  18. #define __ll_highpart(t) ((USItype) (t) / __ll_B)
  19. #define umul_ppmm(w1, w0, u, v) \
  20. do { \
  21. USItype __x0, __x1, __x2, __x3; \
  22. USItype __ul, __vl, __uh, __vh; \
  23. \
  24. __ul = __ll_lowpart (u); \
  25. __uh = __ll_highpart (u); \
  26. __vl = __ll_lowpart (v); \
  27. __vh = __ll_highpart (v); \
  28. \
  29. __x0 = (USItype) __ul * __vl; \
  30. __x1 = (USItype) __ul * __vh; \
  31. __x2 = (USItype) __uh * __vl; \
  32. __x3 = (USItype) __uh * __vh; \
  33. \
  34. __x1 += __ll_highpart (__x0);/* this can't give carry */ \
  35. __x1 += __x2; /* but this indeed can */ \
  36. if (__x1 < __x2) /* did we get it? */ \
  37. __x3 += __ll_B; /* yes, add it in the proper pos. */ \
  38. \
  39. (w1) = __x3 + __ll_highpart (__x1); \
  40. (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
  41. } while (0)
  42. #else
  43. #define umul_ppmm(w1, w0, u, v) \
  44. __asm__ ("mulu%.l %3,%1:%0" \
  45. : "=d" ((USItype)(w0)), \
  46. "=d" ((USItype)(w1)) \
  47. : "%0" ((USItype)(u)), \
  48. "dmi" ((USItype)(v)))
  49. #endif
  50. #define __umulsidi3(u, v) \
  51. ({DIunion __w; \
  52. umul_ppmm (__w.s.high, __w.s.low, u, v); \
  53. __w.ll; })
  54. typedef int SItype __attribute__ ((mode (SI)));
  55. typedef unsigned int USItype __attribute__ ((mode (SI)));
  56. typedef int DItype __attribute__ ((mode (DI)));
  57. typedef int word_type __attribute__ ((mode (__word__)));
  58. struct DIstruct {SItype high, low;};
  59. typedef union
  60. {
  61. struct DIstruct s;
  62. DItype ll;
  63. } DIunion;
  64. DItype
  65. __muldi3 (DItype u, DItype v)
  66. {
  67. DIunion w;
  68. DIunion uu, vv;
  69. uu.ll = u,
  70. vv.ll = v;
  71. w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  72. w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  73. + (USItype) uu.s.high * (USItype) vv.s.low);
  74. return w.ll;
  75. }