ARM: tct_hammer_defconfig: Save defconfig
[linux-2.6/btrfs-unstable.git] / lib / clz_ctz.c
blob2e11e48446abf1bf078163575e10a33a8028febc
1 /*
2 * lib/clz_ctz.c
4 * Copyright (C) 2013 Chanho Min <chanho.min@lge.com>
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.
13 * __c[lt]z[sd]i2 can be overridden by linking arch-specific versions.
16 #include <linux/export.h>
17 #include <linux/kernel.h>
19 int __weak __ctzsi2(int val);
20 int __weak __ctzsi2(int val)
22 return __ffs(val);
24 EXPORT_SYMBOL(__ctzsi2);
26 int __weak __clzsi2(int val);
27 int __weak __clzsi2(int val)
29 return 32 - fls(val);
31 EXPORT_SYMBOL(__clzsi2);
33 int __weak __clzdi2(long val);
34 int __weak __ctzdi2(long val);
35 #if BITS_PER_LONG == 32
37 int __weak __clzdi2(long val)
39 return 32 - fls((int)val);
41 EXPORT_SYMBOL(__clzdi2);
43 int __weak __ctzdi2(long val)
45 return __ffs((u32)val);
47 EXPORT_SYMBOL(__ctzdi2);
49 #elif BITS_PER_LONG == 64
51 int __weak __clzdi2(long val)
53 return 64 - fls64((u64)val);
55 EXPORT_SYMBOL(__clzdi2);
57 int __weak __ctzdi2(long val)
59 return __ffs64((u64)val);
61 EXPORT_SYMBOL(__ctzdi2);
63 #else
64 #error BITS_PER_LONG not 32 or 64
65 #endif