lshrdi3.c 938 B

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