ashldi3.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* ====-- ashldi3.c - Implement __ashldi3 -----------------------------------===
  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 __ashldi3 for the compiler_rt library.
  11. *
  12. * ===----------------------------------------------------------------------===
  13. */
  14. #include "int_lib.h"
  15. /* Returns: a << b */
  16. /* Precondition: 0 <= b < bits_in_dword */
  17. ARM_EABI_FNALIAS(llsl, ashldi3)
  18. COMPILER_RT_ABI di_int
  19. __ashldi3(di_int a, si_int b)
  20. {
  21. const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
  22. dwords input;
  23. dwords result;
  24. input.all = a;
  25. if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
  26. {
  27. result.s.low = 0;
  28. result.s.high = input.s.low << (b - bits_in_word);
  29. }
  30. else /* 0 <= b < bits_in_word */
  31. {
  32. if (b == 0)
  33. return a;
  34. result.s.low = input.s.low << b;
  35. result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_word - b));
  36. }
  37. return result.all;
  38. }