blob: 16056e007eaa89e0875b367152e7d5d3f145da0a [file] [log] [blame]
Dimitry Andric35c61d82017-04-06 18:12:02 +00001/* ===-- ffssi2.c - Implement __ffssi2 -------------------------------------===
2 *
Chandler Carruth7a739a02019-01-19 10:56:40 +00003 * 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
Dimitry Andric35c61d82017-04-06 18:12:02 +00006 *
7 * ===----------------------------------------------------------------------===
8 *
9 * This file implements __ffssi2 for the compiler_rt library.
10 *
11 * ===----------------------------------------------------------------------===
12 */
13
14#include "int_lib.h"
15
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
20COMPILER_RT_ABI si_int
21__ffssi2(si_int a)
22{
23 if (a == 0)
24 {
25 return 0;
26 }
27 return __builtin_ctz(a) + 1;
28}