Back to home page

LXR

 
 

    


0001 /*
0002  * lib/clz_ctz.c
0003  *
0004  * Copyright (C) 2013 Chanho Min <chanho.min@lge.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License version 2 as
0008  * published by the Free Software Foundation.
0009  * The functions in this file aren't called directly, but are required by
0010  * GCC builtins such as __builtin_ctz, and therefore they can't be removed
0011  * despite appearing unreferenced in kernel source.
0012  *
0013  * __c[lt]z[sd]i2 can be overridden by linking arch-specific versions.
0014  */
0015 
0016 #include <linux/export.h>
0017 #include <linux/kernel.h>
0018 
0019 int __weak __ctzsi2(int val);
0020 int __weak __ctzsi2(int val)
0021 {
0022     return __ffs(val);
0023 }
0024 EXPORT_SYMBOL(__ctzsi2);
0025 
0026 int __weak __clzsi2(int val);
0027 int __weak __clzsi2(int val)
0028 {
0029     return 32 - fls(val);
0030 }
0031 EXPORT_SYMBOL(__clzsi2);
0032 
0033 int __weak __clzdi2(long val);
0034 int __weak __ctzdi2(long val);
0035 #if BITS_PER_LONG == 32
0036 
0037 int __weak __clzdi2(long val)
0038 {
0039     return 32 - fls((int)val);
0040 }
0041 EXPORT_SYMBOL(__clzdi2);
0042 
0043 int __weak __ctzdi2(long val)
0044 {
0045     return __ffs((u32)val);
0046 }
0047 EXPORT_SYMBOL(__ctzdi2);
0048 
0049 #elif BITS_PER_LONG == 64
0050 
0051 int __weak __clzdi2(long val)
0052 {
0053     return 64 - fls64((u64)val);
0054 }
0055 EXPORT_SYMBOL(__clzdi2);
0056 
0057 int __weak __ctzdi2(long val)
0058 {
0059     return __ffs64((u64)val);
0060 }
0061 EXPORT_SYMBOL(__ctzdi2);
0062 
0063 #else
0064 #error BITS_PER_LONG not 32 or 64
0065 #endif