1 /* ===-- clzdi2.c - Implement __clzdi2 -------------------------------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===----------------------------------------------------------------------===
10 * This file implements count leading zeros for 64bit arguments.
12 * ===----------------------------------------------------------------------===
14 #include "../assembly.h"
18 #if __ARM_ARCH_ISA_THUMB == 2
24 #if __ARM_ARCH_ISA_THUMB == 2
25 DEFINE_COMPILERRT_THUMB_FUNCTION(__clzdi2)
27 DEFINE_COMPILERRT_FUNCTION(__clzdi2)
29 #ifdef __ARM_FEATURE_CLZ
45 /* Assumption: n != 0 */
49 * r1: upper half of n, overwritten after check
50 * r1: count of leading zeros in n + 1
51 * r2: scratch register for shifted r0
65 * if ((r0 >> SHIFT) == 0)
69 * for descending powers of two as SHIFT.
71 #define BLOCK(shift) \
82 * The basic block invariants at this point are (r0 >> 2) == 0 and
83 * r0 != 0. This means 1 <= r0 <= 3 and 0 <= (r0 >> 1) <= 1.
85 * r0 | (r0 >> 1) == 0 | (r0 >> 1) == 1 | -(r0 >> 1) | 1 - (r0 >> 1)
86 * ---+----------------+----------------+------------+--------------
91 * The r1's initial value of 1 compensates for the 1 here.
93 sub r0, r1, r0, lsr #1
96 #endif // __ARM_FEATURE_CLZ
97 END_COMPILERRT_FUNCTION(__clzdi2)