ashldi3.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* ashrdi3.c extracted from gcc-2.95.2/libgcc2.c which is: */
  2. /* Copyright (C) 1989, 92-98, 1999 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. #define BITS_PER_UNIT 8
  13. typedef int SItype __attribute__ ((mode (SI)));
  14. typedef unsigned int USItype __attribute__ ((mode (SI)));
  15. typedef int DItype __attribute__ ((mode (DI)));
  16. typedef int word_type __attribute__ ((mode (__word__)));
  17. struct DIstruct {SItype high, low;};
  18. typedef union
  19. {
  20. struct DIstruct s;
  21. DItype ll;
  22. } DIunion;
  23. DItype
  24. __ashldi3 (DItype u, word_type b)
  25. {
  26. DIunion w;
  27. word_type bm;
  28. DIunion uu;
  29. if (b == 0)
  30. return u;
  31. uu.ll = u;
  32. bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  33. if (bm <= 0)
  34. {
  35. w.s.low = 0;
  36. w.s.high = (USItype)uu.s.low << -bm;
  37. }
  38. else
  39. {
  40. USItype carries = (USItype)uu.s.low >> bm;
  41. w.s.low = (USItype)uu.s.low << b;
  42. w.s.high = ((USItype)uu.s.high << b) | carries;
  43. }
  44. return w.ll;
  45. }