GNU Linux-libre 4.14.330-gnu1
[releases.git] / lib / clz_ctz.c
1 /*
2  * lib/clz_ctz.c
3  *
4  * Copyright (C) 2013 Chanho Min <chanho.min@lge.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  * The functions in this file aren't called directly, but are required by
10  * GCC builtins such as __builtin_ctz, and therefore they can't be removed
11  * despite appearing unreferenced in kernel source.
12  *
13  * __c[lt]z[sd]i2 can be overridden by linking arch-specific versions.
14  */
15
16 #include <linux/export.h>
17 #include <linux/kernel.h>
18
19 int __weak __ctzsi2(int val);
20 int __weak __ctzsi2(int val)
21 {
22         return __ffs(val);
23 }
24 EXPORT_SYMBOL(__ctzsi2);
25
26 int __weak __clzsi2(int val);
27 int __weak __clzsi2(int val)
28 {
29         return 32 - fls(val);
30 }
31 EXPORT_SYMBOL(__clzsi2);
32
33 int __weak __clzdi2(u64 val);
34 int __weak __clzdi2(u64 val)
35 {
36         return 64 - fls64(val);
37 }
38 EXPORT_SYMBOL(__clzdi2);
39
40 int __weak __ctzdi2(u64 val);
41 int __weak __ctzdi2(u64 val)
42 {
43         return __ffs64(val);
44 }
45 EXPORT_SYMBOL(__ctzdi2);