ashldi3.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // ====-- ashldi3.c - Implement __ashldi3 ---------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements __ashldi3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. // Returns: a << b
  14. // Precondition: 0 <= b < bits_in_dword
  15. COMPILER_RT_ABI di_int __ashldi3(di_int a, int b) {
  16. const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
  17. dwords input;
  18. dwords result;
  19. input.all = a;
  20. if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ {
  21. result.s.low = 0;
  22. result.s.high = input.s.low << (b - bits_in_word);
  23. } else /* 0 <= b < bits_in_word */ {
  24. if (b == 0)
  25. return a;
  26. result.s.low = input.s.low << b;
  27. result.s.high =
  28. ((su_int)input.s.high << b) | (input.s.low >> (bits_in_word - b));
  29. }
  30. return result.all;
  31. }
  32. #if defined(__ARM_EABI__)
  33. COMPILER_RT_ALIAS(__ashldi3, __aeabi_llsl)
  34. #endif