muldi3.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "libgcc.h"
  2. #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
  3. #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
  4. #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
  5. #define umul_ppmm(w1, w0, u, v) \
  6. do { \
  7. UWtype __x0, __x1, __x2, __x3; \
  8. UHWtype __ul, __vl, __uh, __vh; \
  9. __ul = __ll_lowpart(u); \
  10. __uh = __ll_highpart(u); \
  11. __vl = __ll_lowpart(v); \
  12. __vh = __ll_highpart(v); \
  13. __x0 = (UWtype) __ul * __vl; \
  14. __x1 = (UWtype) __ul * __vh; \
  15. __x2 = (UWtype) __uh * __vl; \
  16. __x3 = (UWtype) __uh * __vh; \
  17. __x1 += __ll_highpart(__x0); \
  18. __x1 += __x2; \
  19. if (__x1 < __x2) \
  20. __x3 += __ll_B; \
  21. (w1) = __x3 + __ll_highpart(__x1); \
  22. (w0) = __ll_lowpart(__x1) * __ll_B + __ll_lowpart(__x0); \
  23. } while (0)
  24. #define __umulsidi3(u, v) ( \
  25. { \
  26. DWunion __w; \
  27. umul_ppmm(__w.s.high, __w.s.low, u, v); \
  28. __w.ll; } \
  29. )
  30. DWtype __muldi3(DWtype u, DWtype v)
  31. {
  32. const DWunion uu = {.ll = u};
  33. const DWunion vv = {.ll = v};
  34. DWunion w = {.ll = __umulsidi3(uu.s.low, vv.s.low)};
  35. w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
  36. + (UWtype) uu.s.high * (UWtype) vv.s.low);
  37. return w.ll;
  38. }