lshrdi3.c 935 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * lshrdi3.c extracted from gcc-2.7.2.3/libgcc2.c and
  4. * gcc-2.7.2.3/longlong.h
  5. *
  6. * Copyright (C) 1989-2015 Free Software Foundation, Inc.
  7. */
  8. #define BITS_PER_UNIT 8
  9. typedef int SItype __attribute__ ((mode (SI)));
  10. typedef unsigned int USItype __attribute__ ((mode (SI)));
  11. typedef int DItype __attribute__ ((mode (DI)));
  12. typedef int word_type __attribute__ ((mode (__word__)));
  13. struct DIstruct {SItype high, low;};
  14. typedef union
  15. {
  16. struct DIstruct s;
  17. DItype ll;
  18. } DIunion;
  19. DItype __lshrdi3 (DItype u, word_type b)
  20. {
  21. DIunion w;
  22. word_type bm;
  23. DIunion uu;
  24. if (b == 0)
  25. return u;
  26. uu.ll = u;
  27. bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  28. if (bm <= 0)
  29. {
  30. w.s.high = 0;
  31. w.s.low = (USItype)uu.s.high >> -bm;
  32. }
  33. else
  34. {
  35. USItype carries = (USItype)uu.s.high << bm;
  36. w.s.high = (USItype)uu.s.high >> b;
  37. w.s.low = ((USItype)uu.s.low >> b) | carries;
  38. }
  39. return w.ll;
  40. }