1 //===-- clzdi2.c - Implement __clzdi2 -------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements count leading zeros for 64bit arguments.
11 //===----------------------------------------------------------------------===//
13 #include "../assembly.h"
20 DEFINE_COMPILERRT_FUNCTION(__clzdi2)
21 #ifdef __ARM_FEATURE_CLZ
40 // r1: upper half of n, overwritten after check
41 // r1: count of leading zeros in n + 1
42 // r2: scratch register for shifted r0
54 // if ((r0 >> SHIFT) == 0)
58 // for descending powers of two as SHIFT.
59 #define BLOCK(shift) \
69 // The basic block invariants at this point are (r0 >> 2) == 0 and
70 // r0 != 0. This means 1 <= r0 <= 3 and 0 <= (r0 >> 1) <= 1.
72 // r0 | (r0 >> 1) == 0 | (r0 >> 1) == 1 | -(r0 >> 1) | 1 - (r0 >> 1)
73 // ---+----------------+----------------+------------+--------------
78 // The r1's initial value of 1 compensates for the 1 here.
79 sub r0, r1, r0, lsr #1
82 #endif // __ARM_FEATURE_CLZ
83 END_COMPILERRT_FUNCTION(__clzdi2)
85 NO_EXEC_STACK_DIRECTIVE