ashrdi3.c 530 B

1234567891011121314151617181920212223242526
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "libgcc.h"
  3. DWtype __ashrdi3(DWtype u, word_type b)
  4. {
  5. const DWunion uu = {.ll = u};
  6. const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
  7. DWunion w;
  8. if (b == 0)
  9. return u;
  10. if (bm <= 0) {
  11. /* w.s.high = 1..1 or 0..0 */
  12. w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
  13. w.s.low = uu.s.high >> -bm;
  14. } else {
  15. const UWtype carries = (UWtype) uu.s.high << bm;
  16. w.s.high = uu.s.high >> b;
  17. w.s.low = ((UWtype) uu.s.low >> b) | carries;
  18. }
  19. return w.ll;
  20. }