muldi3.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * muldi3.c extracted from gcc-2.7.2.3/libgcc2.c and
  3. * gcc-2.7.2.3/longlong.h
  4. *
  5. * Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #define SI_TYPE_SIZE 32
  10. #define __BITS4 (SI_TYPE_SIZE / 4)
  11. #define __ll_B (1L << (SI_TYPE_SIZE / 2))
  12. #define __ll_lowpart(t) ((USItype) (t) % __ll_B)
  13. #define __ll_highpart(t) ((USItype) (t) / __ll_B)
  14. #define umul_ppmm(w1, w0, u, v) \
  15. do { \
  16. USItype __x0, __x1, __x2, __x3; \
  17. USItype __ul, __vl, __uh, __vh; \
  18. \
  19. __ul = __ll_lowpart (u); \
  20. __uh = __ll_highpart (u); \
  21. __vl = __ll_lowpart (v); \
  22. __vh = __ll_highpart (v); \
  23. \
  24. __x0 = (USItype) __ul * __vl; \
  25. __x1 = (USItype) __ul * __vh; \
  26. __x2 = (USItype) __uh * __vl; \
  27. __x3 = (USItype) __uh * __vh; \
  28. \
  29. __x1 += __ll_highpart (__x0);/* this can't give carry */ \
  30. __x1 += __x2; /* but this indeed can */ \
  31. if (__x1 < __x2) /* did we get it? */ \
  32. __x3 += __ll_B; /* yes, add it in the proper pos. */ \
  33. \
  34. (w1) = __x3 + __ll_highpart (__x1); \
  35. (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
  36. } while (0)
  37. #define __umulsidi3(u, v) \
  38. ({DIunion __w; \
  39. umul_ppmm (__w.s.high, __w.s.low, u, v); \
  40. __w.ll; })
  41. typedef int SItype __attribute__ ((mode (SI)));
  42. typedef unsigned int USItype __attribute__ ((mode (SI)));
  43. typedef int DItype __attribute__ ((mode (DI)));
  44. typedef int word_type __attribute__ ((mode (__word__)));
  45. struct DIstruct {SItype high, low;};
  46. typedef union
  47. {
  48. struct DIstruct s;
  49. DItype ll;
  50. } DIunion;
  51. DItype __muldi3 (DItype u, DItype v)
  52. {
  53. DIunion w;
  54. DIunion uu, vv;
  55. uu.ll = u,
  56. vv.ll = v;
  57. w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  58. w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  59. + (USItype) uu.s.high * (USItype) vv.s.low);
  60. return w.ll;
  61. }