1 /* ===-- clzsi2.c - Implement __clzsi2 -------------------------------------===
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 32bit arguments.
12 * ===----------------------------------------------------------------------===
14 #include "../assembly.h"
21 DEFINE_COMPILERRT_FUNCTION(__clzsi2)
22 #ifdef __ARM_FEATURE_CLZ
26 /* Assumption: n != 0 */
30 * r1: count of leading zeros in n + 1
31 * r2: scratch register for shifted r0
37 * if ((r0 >> SHIFT) == 0)
41 * for descending powers of two as SHIFT.
44 #define BLOCK(shift) \
55 * The basic block invariants at this point are (r0 >> 2) == 0 and
56 * r0 != 0. This means 1 <= r0 <= 3 and 0 <= (r0 >> 1) <= 1.
58 * r0 | (r0 >> 1) == 0 | (r0 >> 1) == 1 | -(r0 >> 1) | 1 - (r0 >> 1)
59 * ---+----------------+----------------+------------+--------------
64 * The r1's initial value of 1 compensates for the 1 here.
66 sub r0, r1, r0, lsr #1
69 #endif // __ARM_FEATURE_CLZ
70 END_COMPILERRT_FUNCTION(__clzsi2)
72 NO_EXEC_STACK_DIRECTIVE