lshrdi3.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * File: arch/blackfin/lib/lshrdi3.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. #define BITS_PER_UNIT 8
  30. typedef int SItype __attribute__ ((mode(SI)));
  31. typedef unsigned int USItype __attribute__ ((mode(SI)));
  32. typedef int DItype __attribute__ ((mode(DI)));
  33. typedef int word_type __attribute__ ((mode(__word__)));
  34. struct DIstruct {
  35. SItype high, low;
  36. };
  37. typedef union {
  38. struct DIstruct s;
  39. DItype ll;
  40. } DIunion;
  41. #ifdef CONFIG_ARITHMETIC_OPS_L1
  42. DItype __lshrdi3(DItype u, word_type b)__attribute__((l1_text));
  43. #endif
  44. DItype __lshrdi3(DItype u, word_type b)
  45. {
  46. DIunion w;
  47. word_type bm;
  48. DIunion uu;
  49. if (b == 0)
  50. return u;
  51. uu.ll = u;
  52. bm = (sizeof(SItype) * BITS_PER_UNIT) - b;
  53. if (bm <= 0) {
  54. w.s.high = 0;
  55. w.s.low = (USItype) uu.s.high >> -bm;
  56. } else {
  57. USItype carries = (USItype) uu.s.high << bm;
  58. w.s.high = (USItype) uu.s.high >> b;
  59. w.s.low = ((USItype) uu.s.low >> b) | carries;
  60. }
  61. return w.ll;
  62. }