muldi3.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. You should have received a copy of the GNU General Public License
  14. along with GNU CC; see the file COPYING. If not, write to
  15. the Free Software Foundation, 59 Temple Place - Suite 330,
  16. Boston, MA 02111-1307, USA. */
  17. #if defined(CONFIG_M68000) || defined(CONFIG_COLDFIRE)
  18. #define SI_TYPE_SIZE 32
  19. #define __BITS4 (SI_TYPE_SIZE / 4)
  20. #define __ll_B (1L << (SI_TYPE_SIZE / 2))
  21. #define __ll_lowpart(t) ((USItype) (t) % __ll_B)
  22. #define __ll_highpart(t) ((USItype) (t) / __ll_B)
  23. #define umul_ppmm(w1, w0, u, v) \
  24. do { \
  25. USItype __x0, __x1, __x2, __x3; \
  26. USItype __ul, __vl, __uh, __vh; \
  27. \
  28. __ul = __ll_lowpart (u); \
  29. __uh = __ll_highpart (u); \
  30. __vl = __ll_lowpart (v); \
  31. __vh = __ll_highpart (v); \
  32. \
  33. __x0 = (USItype) __ul * __vl; \
  34. __x1 = (USItype) __ul * __vh; \
  35. __x2 = (USItype) __uh * __vl; \
  36. __x3 = (USItype) __uh * __vh; \
  37. \
  38. __x1 += __ll_highpart (__x0);/* this can't give carry */ \
  39. __x1 += __x2; /* but this indeed can */ \
  40. if (__x1 < __x2) /* did we get it? */ \
  41. __x3 += __ll_B; /* yes, add it in the proper pos. */ \
  42. \
  43. (w1) = __x3 + __ll_highpart (__x1); \
  44. (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
  45. } while (0)
  46. #else
  47. #define umul_ppmm(w1, w0, u, v) \
  48. __asm__ ("mulu%.l %3,%1:%0" \
  49. : "=d" ((USItype)(w0)), \
  50. "=d" ((USItype)(w1)) \
  51. : "%0" ((USItype)(u)), \
  52. "dmi" ((USItype)(v)))
  53. #endif
  54. #define __umulsidi3(u, v) \
  55. ({DIunion __w; \
  56. umul_ppmm (__w.s.high, __w.s.low, u, v); \
  57. __w.ll; })
  58. typedef int SItype __attribute__ ((mode (SI)));
  59. typedef unsigned int USItype __attribute__ ((mode (SI)));
  60. typedef int DItype __attribute__ ((mode (DI)));
  61. typedef int word_type __attribute__ ((mode (__word__)));
  62. struct DIstruct {SItype high, low;};
  63. typedef union
  64. {
  65. struct DIstruct s;
  66. DItype ll;
  67. } DIunion;
  68. DItype
  69. __muldi3 (DItype u, DItype v)
  70. {
  71. DIunion w;
  72. DIunion uu, vv;
  73. uu.ll = u,
  74. vv.ll = v;
  75. w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  76. w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  77. + (USItype) uu.s.high * (USItype) vv.s.low);
  78. return w.ll;
  79. }