ffsti2.c 995 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* ===-- ffsti2.c - Implement __ffsti2 -------------------------------------===
  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 __ffsti2 for the compiler_rt library.
  11. *
  12. * ===----------------------------------------------------------------------===
  13. */
  14. #include "int_lib.h"
  15. #ifdef CRT_HAS_128BIT
  16. /* Returns: the index of the least significant 1-bit in a, or
  17. * the value zero if a is zero. The least significant bit is index one.
  18. */
  19. COMPILER_RT_ABI si_int
  20. __ffsti2(ti_int a)
  21. {
  22. twords x;
  23. x.all = a;
  24. if (x.s.low == 0)
  25. {
  26. if (x.s.high == 0)
  27. return 0;
  28. return __builtin_ctzll(x.s.high) + (1 + sizeof(di_int) * CHAR_BIT);
  29. }
  30. return __builtin_ctzll(x.s.low) + 1;
  31. }
  32. #endif /* CRT_HAS_128BIT */