ashrdi3.c 565 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. */
  4. #include <linux/export.h>
  5. #include <linux/libgcc.h>
  6. long long notrace __ashrdi3(long long u, word_type b)
  7. {
  8. DWunion uu, w;
  9. word_type bm;
  10. if (b == 0)
  11. return u;
  12. uu.ll = u;
  13. bm = 32 - b;
  14. if (bm <= 0) {
  15. /* w.s.high = 1..1 or 0..0 */
  16. w.s.high =
  17. uu.s.high >> 31;
  18. w.s.low = uu.s.high >> -bm;
  19. } else {
  20. const unsigned int carries = (unsigned int) uu.s.high << bm;
  21. w.s.high = uu.s.high >> b;
  22. w.s.low = ((unsigned int) uu.s.low >> b) | carries;
  23. }
  24. return w.ll;
  25. }
  26. EXPORT_SYMBOL(__ashrdi3);