bitops.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2009, 2010 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef _ASM_C6X_BITOPS_H
  12. #define _ASM_C6X_BITOPS_H
  13. #ifdef __KERNEL__
  14. #include <linux/bitops.h>
  15. #include <asm/system.h>
  16. #include <asm/byteorder.h>
  17. /*
  18. * clear_bit() doesn't provide any barrier for the compiler.
  19. */
  20. #define smp_mb__before_clear_bit() barrier()
  21. #define smp_mb__after_clear_bit() barrier()
  22. /*
  23. * We are lucky, DSP is perfect for bitops: do it in 3 cycles
  24. */
  25. /**
  26. * __ffs - find first bit in word.
  27. * @word: The word to search
  28. *
  29. * Undefined if no bit exists, so code should check against 0 first.
  30. * Note __ffs(0) = undef, __ffs(1) = 0, __ffs(0x80000000) = 31.
  31. *
  32. */
  33. static inline unsigned long __ffs(unsigned long x)
  34. {
  35. asm (" bitr .M1 %0,%0\n"
  36. " nop\n"
  37. " lmbd .L1 1,%0,%0\n"
  38. : "+a"(x));
  39. return x;
  40. }
  41. /*
  42. * ffz - find first zero in word.
  43. * @word: The word to search
  44. *
  45. * Undefined if no zero exists, so code should check against ~0UL first.
  46. */
  47. #define ffz(x) __ffs(~(x))
  48. /**
  49. * fls - find last (most-significant) bit set
  50. * @x: the word to search
  51. *
  52. * This is defined the same way as ffs.
  53. * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  54. */
  55. static inline int fls(int x)
  56. {
  57. if (!x)
  58. return 0;
  59. asm (" lmbd .L1 1,%0,%0\n" : "+a"(x));
  60. return 32 - x;
  61. }
  62. /**
  63. * ffs - find first bit set
  64. * @x: the word to search
  65. *
  66. * This is defined the same way as
  67. * the libc and compiler builtin ffs routines, therefore
  68. * differs in spirit from the above ffz (man ffs).
  69. * Note ffs(0) = 0, ffs(1) = 1, ffs(0x80000000) = 32.
  70. */
  71. static inline int ffs(int x)
  72. {
  73. if (!x)
  74. return 0;
  75. return __ffs(x) + 1;
  76. }
  77. #include <asm-generic/bitops/__fls.h>
  78. #include <asm-generic/bitops/fls64.h>
  79. #include <asm-generic/bitops/find.h>
  80. #include <asm-generic/bitops/sched.h>
  81. #include <asm-generic/bitops/hweight.h>
  82. #include <asm-generic/bitops/lock.h>
  83. #include <asm-generic/bitops/atomic.h>
  84. #include <asm-generic/bitops/non-atomic.h>
  85. #include <asm-generic/bitops/le.h>
  86. #include <asm-generic/bitops/ext2-atomic.h>
  87. #endif /* __KERNEL__ */
  88. #endif /* _ASM_C6X_BITOPS_H */