clz_ctz.c 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include <linux/export.h>
  13. #include <linux/kernel.h>
  14. int __weak __ctzsi2(int val)
  15. {
  16. return __ffs(val);
  17. }
  18. EXPORT_SYMBOL(__ctzsi2);
  19. int __weak __clzsi2(int val)
  20. {
  21. return 32 - fls(val);
  22. }
  23. EXPORT_SYMBOL(__clzsi2);
  24. #if BITS_PER_LONG == 32
  25. int __weak __clzdi2(long val)
  26. {
  27. return 32 - fls((int)val);
  28. }
  29. EXPORT_SYMBOL(__clzdi2);
  30. int __weak __ctzdi2(long val)
  31. {
  32. return __ffs((u32)val);
  33. }
  34. EXPORT_SYMBOL(__ctzdi2);
  35. #elif BITS_PER_LONG == 64
  36. int __weak __clzdi2(long val)
  37. {
  38. return 64 - fls64((u64)val);
  39. }
  40. EXPORT_SYMBOL(__clzdi2);
  41. int __weak __ctzdi2(long val)
  42. {
  43. return __ffs64((u64)val);
  44. }
  45. EXPORT_SYMBOL(__ctzdi2);
  46. #else
  47. #error BITS_PER_LONG not 32 or 64
  48. #endif