Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Chanho Min | 4df87bb | 2013-07-08 16:01:43 -0700 | [diff] [blame] | 2 | /* |
| 3 | * lib/clz_ctz.c |
| 4 | * |
| 5 | * Copyright (C) 2013 Chanho Min <chanho.min@lge.com> |
| 6 | * |
Rashika Kheria | 3c516cd | 2014-04-03 14:49:09 -0700 | [diff] [blame] | 7 | * The functions in this file aren't called directly, but are required by |
| 8 | * GCC builtins such as __builtin_ctz, and therefore they can't be removed |
| 9 | * despite appearing unreferenced in kernel source. |
Chanho Min | 4df87bb | 2013-07-08 16:01:43 -0700 | [diff] [blame] | 10 | * |
| 11 | * __c[lt]z[sd]i2 can be overridden by linking arch-specific versions. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/export.h> |
| 15 | #include <linux/kernel.h> |
| 16 | |
Rashika Kheria | 3c516cd | 2014-04-03 14:49:09 -0700 | [diff] [blame] | 17 | int __weak __ctzsi2(int val); |
Chanho Min | 4df87bb | 2013-07-08 16:01:43 -0700 | [diff] [blame] | 18 | int __weak __ctzsi2(int val) |
| 19 | { |
| 20 | return __ffs(val); |
| 21 | } |
| 22 | EXPORT_SYMBOL(__ctzsi2); |
| 23 | |
Rashika Kheria | 3c516cd | 2014-04-03 14:49:09 -0700 | [diff] [blame] | 24 | int __weak __clzsi2(int val); |
Chanho Min | 4df87bb | 2013-07-08 16:01:43 -0700 | [diff] [blame] | 25 | int __weak __clzsi2(int val) |
| 26 | { |
| 27 | return 32 - fls(val); |
| 28 | } |
| 29 | EXPORT_SYMBOL(__clzsi2); |
| 30 | |
Rashika Kheria | 3c516cd | 2014-04-03 14:49:09 -0700 | [diff] [blame] | 31 | int __weak __clzdi2(long val); |
| 32 | int __weak __ctzdi2(long val); |
Chanho Min | 4df87bb | 2013-07-08 16:01:43 -0700 | [diff] [blame] | 33 | #if BITS_PER_LONG == 32 |
| 34 | |
| 35 | int __weak __clzdi2(long val) |
| 36 | { |
| 37 | return 32 - fls((int)val); |
| 38 | } |
| 39 | EXPORT_SYMBOL(__clzdi2); |
| 40 | |
| 41 | int __weak __ctzdi2(long val) |
| 42 | { |
| 43 | return __ffs((u32)val); |
| 44 | } |
| 45 | EXPORT_SYMBOL(__ctzdi2); |
| 46 | |
| 47 | #elif BITS_PER_LONG == 64 |
| 48 | |
| 49 | int __weak __clzdi2(long val) |
| 50 | { |
| 51 | return 64 - fls64((u64)val); |
| 52 | } |
| 53 | EXPORT_SYMBOL(__clzdi2); |
| 54 | |
| 55 | int __weak __ctzdi2(long val) |
| 56 | { |
| 57 | return __ffs64((u64)val); |
| 58 | } |
| 59 | EXPORT_SYMBOL(__ctzdi2); |
| 60 | |
| 61 | #else |
| 62 | #error BITS_PER_LONG not 32 or 64 |
| 63 | #endif |