ashrdi3.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===//
  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 __ashrdi3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. // Returns: arithmetic a >> b
  14. // Precondition: 0 <= b < bits_in_dword
  15. COMPILER_RT_ABI di_int __ashrdi3(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.high = input.s.high < 0 ? -1 : 0
  22. result.s.high = input.s.high >> (bits_in_word - 1);
  23. result.s.low = input.s.high >> (b - bits_in_word);
  24. } else /* 0 <= b < bits_in_word */ {
  25. if (b == 0)
  26. return a;
  27. result.s.high = input.s.high >> b;
  28. result.s.low =
  29. ((su_int)input.s.high << (bits_in_word - b)) | (input.s.low >> b);
  30. }
  31. return result.all;
  32. }
  33. #if defined(__ARM_EABI__)
  34. COMPILER_RT_ALIAS(__ashrdi3, __aeabi_lasr)
  35. #endif