ashrdi3.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* ashrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
  2. /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU CC; see the file COPYING. If not, write to
  14. the Free Software Foundation, 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #define BITS_PER_UNIT 8
  17. typedef int SItype __attribute__ ((mode (SI)));
  18. typedef unsigned int USItype __attribute__ ((mode (SI)));
  19. typedef int DItype __attribute__ ((mode (DI)));
  20. typedef int word_type __attribute__ ((mode (__word__)));
  21. struct DIstruct {SItype high, low;};
  22. typedef union
  23. {
  24. struct DIstruct s;
  25. DItype ll;
  26. } DIunion;
  27. DItype
  28. __ashrdi3 (DItype u, word_type b)
  29. {
  30. DIunion w;
  31. word_type bm;
  32. DIunion uu;
  33. if (b == 0)
  34. return u;
  35. uu.ll = u;
  36. bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  37. if (bm <= 0)
  38. {
  39. /* w.s.high = 1..1 or 0..0 */
  40. w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
  41. w.s.low = uu.s.high >> -bm;
  42. }
  43. else
  44. {
  45. USItype carries = (USItype)uu.s.high << bm;
  46. w.s.high = uu.s.high >> b;
  47. w.s.low = ((USItype)uu.s.low >> b) | carries;
  48. }
  49. return w.ll;
  50. }