clzti2.c 887 B

123456789101112131415161718192021222324252627282930313233
  1. /* ===-- clzti2.c - Implement __clzti2 -------------------------------------===
  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 __clzti2 for the compiler_rt library.
  11. *
  12. * ===----------------------------------------------------------------------===
  13. */
  14. #include "int_lib.h"
  15. #ifdef CRT_HAS_128BIT
  16. /* Returns: the number of leading 0-bits */
  17. /* Precondition: a != 0 */
  18. COMPILER_RT_ABI si_int
  19. __clzti2(ti_int a)
  20. {
  21. twords x;
  22. x.all = a;
  23. const di_int f = -(x.s.high == 0);
  24. return __builtin_clzll((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 */