muldi3.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * File: arch/blackfin/lib/muldi3.c
  3. * Based on:
  4. * Author:
  5. *
  6. * Created:
  7. * Description:
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #ifndef SI_TYPE_SIZE
  30. #define SI_TYPE_SIZE 32
  31. #endif
  32. #define __ll_b (1L << (SI_TYPE_SIZE / 2))
  33. #define __ll_lowpart(t) ((usitype) (t) % __ll_b)
  34. #define __ll_highpart(t) ((usitype) (t) / __ll_b)
  35. #define BITS_PER_UNIT 8
  36. #if !defined(umul_ppmm)
  37. #define umul_ppmm(w1, w0, u, v) \
  38. do { \
  39. usitype __x0, __x1, __x2, __x3; \
  40. usitype __ul, __vl, __uh, __vh; \
  41. \
  42. __ul = __ll_lowpart (u); \
  43. __uh = __ll_highpart (u); \
  44. __vl = __ll_lowpart (v); \
  45. __vh = __ll_highpart (v); \
  46. \
  47. __x0 = (usitype) __ul * __vl; \
  48. __x1 = (usitype) __ul * __vh; \
  49. __x2 = (usitype) __uh * __vl; \
  50. __x3 = (usitype) __uh * __vh; \
  51. \
  52. __x1 += __ll_highpart (__x0);/* this can't give carry */ \
  53. __x1 += __x2; /* but this indeed can */ \
  54. if (__x1 < __x2) /* did we get it? */ \
  55. __x3 += __ll_b; /* yes, add it in the proper pos. */ \
  56. \
  57. (w1) = __x3 + __ll_highpart (__x1); \
  58. (w0) = __ll_lowpart (__x1) * __ll_b + __ll_lowpart (__x0); \
  59. } while (0)
  60. #endif
  61. #if !defined(__umulsidi3)
  62. #define __umulsidi3(u, v) \
  63. ({diunion __w; \
  64. umul_ppmm (__w.s.high, __w.s.low, u, v); \
  65. __w.ll; })
  66. #endif
  67. typedef unsigned int usitype __attribute__ ((mode(SI)));
  68. typedef int sitype __attribute__ ((mode(SI)));
  69. typedef int ditype __attribute__ ((mode(DI)));
  70. typedef int word_type __attribute__ ((mode(__word__)));
  71. struct distruct {
  72. sitype low, high;
  73. };
  74. typedef union {
  75. struct distruct s;
  76. ditype ll;
  77. } diunion;
  78. #ifdef CONFIG_ARITHMETIC_OPS_L1
  79. ditype __muldi3(ditype u, ditype v)__attribute__((l1_text));
  80. #endif
  81. ditype __muldi3(ditype u, ditype v)
  82. {
  83. diunion w;
  84. diunion uu, vv;
  85. uu.ll = u, vv.ll = v;
  86. w.ll = __umulsidi3(uu.s.low, vv.s.low);
  87. w.s.high += ((usitype) uu.s.low * (usitype) vv.s.high
  88. + (usitype) uu.s.high * (usitype) vv.s.low);
  89. return w.ll;
  90. }