muldi3.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #define BITS_PER_UNIT 8
  18. #define umul_ppmm(w1, w0, u, v) \
  19. __asm__ ("mulu%.l %3,%1:%0" \
  20. : "=d" ((USItype)(w0)), \
  21. "=d" ((USItype)(w1)) \
  22. : "%0" ((USItype)(u)), \
  23. "dmi" ((USItype)(v)))
  24. #define __umulsidi3(u, v) \
  25. ({DIunion __w; \
  26. umul_ppmm (__w.s.high, __w.s.low, u, v); \
  27. __w.ll; })
  28. typedef int SItype __attribute__ ((mode (SI)));
  29. typedef unsigned int USItype __attribute__ ((mode (SI)));
  30. typedef int DItype __attribute__ ((mode (DI)));
  31. typedef int word_type __attribute__ ((mode (__word__)));
  32. struct DIstruct {SItype high, low;};
  33. typedef union
  34. {
  35. struct DIstruct s;
  36. DItype ll;
  37. } DIunion;
  38. DItype
  39. __muldi3 (DItype u, DItype v)
  40. {
  41. DIunion w;
  42. DIunion uu, vv;
  43. uu.ll = u,
  44. vv.ll = v;
  45. w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  46. w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  47. + (USItype) uu.s.high * (USItype) vv.s.low);
  48. return w.ll;
  49. }