ctzti2.c 897 B

123456789101112131415161718192021222324252627282930313233
  1. /* ===-- ctzti2.c - Implement __ctzti2 -------------------------------------===
  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 __ctzti2 for the compiler_rt library.
  11. *
  12. * ===----------------------------------------------------------------------===
  13. */
  14. #include "int_lib.h"
  15. #ifdef CRT_HAS_128BIT
  16. /* Returns: the number of trailing 0-bits */
  17. /* Precondition: a != 0 */
  18. COMPILER_RT_ABI si_int
  19. __ctzti2(ti_int a)
  20. {
  21. twords x;
  22. x.all = a;
  23. const di_int f = -(x.s.low == 0);
  24. return __builtin_ctzll((x.s.high & f) | (x.s.low & ~f)) +
  25. ((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT)));
  26. }
  27. #endif /* CRT_HAS_128BIT */