Dimitry Andric | 35c61d8 | 2017-04-06 18:12:02 +0000 | [diff] [blame] | 1 | /* ===-- ffssi2.c - Implement __ffssi2 -------------------------------------=== |
| 2 | * |
Chandler Carruth | 7a739a0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Dimitry Andric | 35c61d8 | 2017-04-06 18:12:02 +0000 | [diff] [blame] | 6 | * |
| 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 | |
| 20 | COMPILER_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 | } |