lshrdi3.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* ===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===
  2. *
  3. * The LLVM Compiler Infrastructure
  4. *
  5. * This file is dual licensed under the MIT and the University of Illinois Open
  6. * Source Licenses. See LICENSE.TXT for details.
  7. *
  8. * ===----------------------------------------------------------------------===
  9. *
  10. * This file implements __lshrdi3 for the compiler_rt library.
  11. *
  12. * ===----------------------------------------------------------------------===
  13. */
  14. #include "int_lib.h"
  15. /* Returns: logical a >> b */
  16. /* Precondition: 0 <= b < bits_in_dword */
  17. ARM_EABI_FNALIAS(llsr, lshrdi3)
  18. COMPILER_RT_ABI di_int
  19. __lshrdi3(di_int a, si_int b)
  20. {
  21. const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
  22. udwords input;
  23. udwords result;
  24. input.all = a;
  25. if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
  26. {
  27. result.s.high = 0;
  28. result.s.low = input.s.high >> (b - bits_in_word);
  29. }
  30. else /* 0 <= b < bits_in_word */
  31. {
  32. if (b == 0)
  33. return a;
  34. result.s.high = input.s.high >> b;
  35. result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
  36. }
  37. return result.all;
  38. }