ashrdi3.c 990 B

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