lshrdi3.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===//
  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 __lshrdi3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. // Returns: logical a >> b
  14. // Precondition: 0 <= b < bits_in_dword
  15. COMPILER_RT_ABI di_int __lshrdi3(di_int a, int b) {
  16. const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
  17. udwords input;
  18. udwords result;
  19. input.all = a;
  20. if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ {
  21. result.s.high = 0;
  22. result.s.low = input.s.high >> (b - bits_in_word);
  23. } else /* 0 <= b < bits_in_word */ {
  24. if (b == 0)
  25. return a;
  26. result.s.high = input.s.high >> b;
  27. result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
  28. }
  29. return result.all;
  30. }
  31. #if defined(__ARM_EABI__)
  32. COMPILER_RT_ALIAS(__lshrdi3, __aeabi_llsr)
  33. #endif