muldi3.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include <linux/compiler.h>
  14. #include <linux/export.h>
  15. #ifdef CONFIG_CPU_HAS_NO_MULDIV64
  16. #define SI_TYPE_SIZE 32
  17. #define __BITS4 (SI_TYPE_SIZE / 4)
  18. #define __ll_B (1L << (SI_TYPE_SIZE / 2))
  19. #define __ll_lowpart(t) ((USItype) (t) % __ll_B)
  20. #define __ll_highpart(t) ((USItype) (t) / __ll_B)
  21. #define umul_ppmm(w1, w0, u, v) \
  22. do { \
  23. USItype __x0, __x1, __x2, __x3; \
  24. USItype __ul, __vl, __uh, __vh; \
  25. \
  26. __ul = __ll_lowpart (u); \
  27. __uh = __ll_highpart (u); \
  28. __vl = __ll_lowpart (v); \
  29. __vh = __ll_highpart (v); \
  30. \
  31. __x0 = (USItype) __ul * __vl; \
  32. __x1 = (USItype) __ul * __vh; \
  33. __x2 = (USItype) __uh * __vl; \
  34. __x3 = (USItype) __uh * __vh; \
  35. \
  36. __x1 += __ll_highpart (__x0);/* this can't give carry */ \
  37. __x1 += __x2; /* but this indeed can */ \
  38. if (__x1 < __x2) /* did we get it? */ \
  39. __x3 += __ll_B; /* yes, add it in the proper pos. */ \
  40. \
  41. (w1) = __x3 + __ll_highpart (__x1); \
  42. (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
  43. } while (0)
  44. #else
  45. #define umul_ppmm(w1, w0, u, v) \
  46. __asm__ ("mulu%.l %3,%1:%0" \
  47. : "=d" ((USItype)(w0)), \
  48. "=d" ((USItype)(w1)) \
  49. : "%0" ((USItype)(u)), \
  50. "dmi" ((USItype)(v)))
  51. #endif
  52. #define __umulsidi3(u, v) \
  53. ({DIunion __w; \
  54. umul_ppmm (__w.s.high, __w.s.low, u, v); \
  55. __w.ll; })
  56. typedef int SItype __attribute__ ((mode (SI)));
  57. typedef unsigned int USItype __attribute__ ((mode (SI)));
  58. typedef int DItype __attribute__ ((mode (DI)));
  59. typedef int word_type __attribute__ ((mode (__word__)));
  60. struct DIstruct {SItype high, low;};
  61. typedef union
  62. {
  63. struct DIstruct s;
  64. DItype ll;
  65. } DIunion;
  66. DItype
  67. __muldi3 (DItype u, DItype v)
  68. {
  69. DIunion w;
  70. DIunion uu, vv;
  71. uu.ll = u,
  72. vv.ll = v;
  73. w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  74. w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  75. + (USItype) uu.s.high * (USItype) vv.s.low);
  76. return w.ll;
  77. }
  78. EXPORT_SYMBOL(__muldi3);