diff options
author | Chanho Min <chanho.min@lge.com> | 2013-07-08 19:01:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-09 13:33:30 -0400 |
commit | 4df87bb7b6a22dfc6fdd5abb3dd362b3af2c164d (patch) | |
tree | e7e065ee0e172184fc7dc8f96a508518836e38f2 /lib | |
parent | 1b3a5d02ee070c8f9943333b9b6370f486601e0f (diff) |
lib: add weak clz/ctz functions
Some architectures need __c[lt]z[sd]i2() for __builtin_c[lt]z[ll] and
that causes a build failure. They can be implemented using the
fls()/__ffs() and overridden by linking arch-specific versions may not
be implemented yet.
This is required by "lib: add lz4 compressor module".
Reference: https://lkml.org/lkml/2013/4/18/603
Signed-off-by: Chanho Min <chanho.min@lge.com>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: "Darrick J. Wong" <djwong@us.ibm.com>
Cc: Bob Pearson <rpearson@systemfabricworks.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Herbert Xu <herbert@gondor.hengli.com.au>
Cc: Yann Collet <yann.collet.73@gmail.com>
Cc: Kyungsik Lee <kyungsik.lee@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/clz_ctz.c | 58 |
2 files changed, 59 insertions, 1 deletions
diff --git a/lib/Makefile b/lib/Makefile index c09e38eca87a..9afb4f745e8f 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -23,7 +23,7 @@ lib-y += kobject.o klist.o | |||
23 | 23 | ||
24 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | 24 | obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ |
25 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ | 25 | bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ |
26 | gcd.o lcm.o list_sort.o uuid.o flex_array.o iovec.o \ | 26 | gcd.o lcm.o list_sort.o uuid.o flex_array.o iovec.o clz_ctz.o \ |
27 | bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o | 27 | bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o |
28 | obj-y += string_helpers.o | 28 | obj-y += string_helpers.o |
29 | obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o | 29 | obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o |
diff --git a/lib/clz_ctz.c b/lib/clz_ctz.c new file mode 100644 index 000000000000..a8f8379eb49f --- /dev/null +++ b/lib/clz_ctz.c | |||
@@ -0,0 +1,58 @@ | |||
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 | * | ||
10 | * __c[lt]z[sd]i2 can be overridden by linking arch-specific versions. | ||
11 | */ | ||
12 | |||
13 | #include <linux/export.h> | ||
14 | #include <linux/kernel.h> | ||
15 | |||
16 | int __weak __ctzsi2(int val) | ||
17 | { | ||
18 | return __ffs(val); | ||
19 | } | ||
20 | EXPORT_SYMBOL(__ctzsi2); | ||
21 | |||
22 | int __weak __clzsi2(int val) | ||
23 | { | ||
24 | return 32 - fls(val); | ||
25 | } | ||
26 | EXPORT_SYMBOL(__clzsi2); | ||
27 | |||
28 | #if BITS_PER_LONG == 32 | ||
29 | |||
30 | int __weak __clzdi2(long val) | ||
31 | { | ||
32 | return 32 - fls((int)val); | ||
33 | } | ||
34 | EXPORT_SYMBOL(__clzdi2); | ||
35 | |||
36 | int __weak __ctzdi2(long val) | ||
37 | { | ||
38 | return __ffs((u32)val); | ||
39 | } | ||
40 | EXPORT_SYMBOL(__ctzdi2); | ||
41 | |||
42 | #elif BITS_PER_LONG == 64 | ||
43 | |||
44 | int __weak __clzdi2(long val) | ||
45 | { | ||
46 | return 64 - fls64((u64)val); | ||
47 | } | ||
48 | EXPORT_SYMBOL(__clzdi2); | ||
49 | |||
50 | int __weak __ctzdi2(long val) | ||
51 | { | ||
52 | return __ffs64((u64)val); | ||
53 | } | ||
54 | EXPORT_SYMBOL(__ctzdi2); | ||
55 | |||
56 | #else | ||
57 | #error BITS_PER_LONG not 32 or 64 | ||
58 | #endif | ||