ashrdi3.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, see the file COPYING, or write
  14. * to the Free Software Foundation, Inc.
  15. */
  16. #include <linux/export.h>
  17. #include <linux/libgcc.h>
  18. long long notrace __ashrdi3(long long u, word_type b)
  19. {
  20. DWunion uu, w;
  21. word_type bm;
  22. if (b == 0)
  23. return u;
  24. uu.ll = u;
  25. bm = 32 - b;
  26. if (bm <= 0) {
  27. /* w.s.high = 1..1 or 0..0 */
  28. w.s.high =
  29. uu.s.high >> 31;
  30. w.s.low = uu.s.high >> -bm;
  31. } else {
  32. const unsigned int carries = (unsigned int) uu.s.high << bm;
  33. w.s.high = uu.s.high >> b;
  34. w.s.low = ((unsigned int) uu.s.low >> b) | carries;
  35. }
  36. return w.ll;
  37. }
  38. EXPORT_SYMBOL(__ashrdi3);