lshrdi3.c 1.2 KB

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