bitops.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef __ASM_SH64_BITOPS_H
  2. #define __ASM_SH64_BITOPS_H
  3. /*
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * include/asm-sh64/bitops.h
  9. *
  10. * Copyright (C) 2000, 2001 Paolo Alberelli
  11. * Copyright (C) 2003 Paul Mundt
  12. */
  13. #ifdef __KERNEL__
  14. #ifndef _LINUX_BITOPS_H
  15. #error only <linux/bitops.h> can be included directly
  16. #endif
  17. #include <linux/compiler.h>
  18. #include <asm/system.h>
  19. /* For __swab32 */
  20. #include <asm/byteorder.h>
  21. static __inline__ void set_bit(int nr, volatile void * addr)
  22. {
  23. int mask;
  24. volatile unsigned int *a = addr;
  25. unsigned long flags;
  26. a += nr >> 5;
  27. mask = 1 << (nr & 0x1f);
  28. local_irq_save(flags);
  29. *a |= mask;
  30. local_irq_restore(flags);
  31. }
  32. /*
  33. * clear_bit() doesn't provide any barrier for the compiler.
  34. */
  35. #define smp_mb__before_clear_bit() barrier()
  36. #define smp_mb__after_clear_bit() barrier()
  37. static inline void clear_bit(int nr, volatile unsigned long *a)
  38. {
  39. int mask;
  40. unsigned long flags;
  41. a += nr >> 5;
  42. mask = 1 << (nr & 0x1f);
  43. local_irq_save(flags);
  44. *a &= ~mask;
  45. local_irq_restore(flags);
  46. }
  47. static __inline__ void change_bit(int nr, volatile void * addr)
  48. {
  49. int mask;
  50. volatile unsigned int *a = addr;
  51. unsigned long flags;
  52. a += nr >> 5;
  53. mask = 1 << (nr & 0x1f);
  54. local_irq_save(flags);
  55. *a ^= mask;
  56. local_irq_restore(flags);
  57. }
  58. static __inline__ int test_and_set_bit(int nr, volatile void * addr)
  59. {
  60. int mask, retval;
  61. volatile unsigned int *a = addr;
  62. unsigned long flags;
  63. a += nr >> 5;
  64. mask = 1 << (nr & 0x1f);
  65. local_irq_save(flags);
  66. retval = (mask & *a) != 0;
  67. *a |= mask;
  68. local_irq_restore(flags);
  69. return retval;
  70. }
  71. static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
  72. {
  73. int mask, retval;
  74. volatile unsigned int *a = addr;
  75. unsigned long flags;
  76. a += nr >> 5;
  77. mask = 1 << (nr & 0x1f);
  78. local_irq_save(flags);
  79. retval = (mask & *a) != 0;
  80. *a &= ~mask;
  81. local_irq_restore(flags);
  82. return retval;
  83. }
  84. static __inline__ int test_and_change_bit(int nr, volatile void * addr)
  85. {
  86. int mask, retval;
  87. volatile unsigned int *a = addr;
  88. unsigned long flags;
  89. a += nr >> 5;
  90. mask = 1 << (nr & 0x1f);
  91. local_irq_save(flags);
  92. retval = (mask & *a) != 0;
  93. *a ^= mask;
  94. local_irq_restore(flags);
  95. return retval;
  96. }
  97. #include <asm-generic/bitops/non-atomic.h>
  98. static __inline__ unsigned long ffz(unsigned long word)
  99. {
  100. unsigned long result, __d2, __d3;
  101. __asm__("gettr tr0, %2\n\t"
  102. "pta $+32, tr0\n\t"
  103. "andi %1, 1, %3\n\t"
  104. "beq %3, r63, tr0\n\t"
  105. "pta $+4, tr0\n"
  106. "0:\n\t"
  107. "shlri.l %1, 1, %1\n\t"
  108. "addi %0, 1, %0\n\t"
  109. "andi %1, 1, %3\n\t"
  110. "beqi %3, 1, tr0\n"
  111. "1:\n\t"
  112. "ptabs %2, tr0\n\t"
  113. : "=r" (result), "=r" (word), "=r" (__d2), "=r" (__d3)
  114. : "0" (0L), "1" (word));
  115. return result;
  116. }
  117. #include <asm-generic/bitops/__ffs.h>
  118. #include <asm-generic/bitops/find.h>
  119. #include <asm-generic/bitops/hweight.h>
  120. #include <asm-generic/bitops/lock.h>
  121. #include <asm-generic/bitops/sched.h>
  122. #include <asm-generic/bitops/ffs.h>
  123. #include <asm-generic/bitops/ext2-non-atomic.h>
  124. #include <asm-generic/bitops/ext2-atomic.h>
  125. #include <asm-generic/bitops/minix.h>
  126. #include <asm-generic/bitops/fls.h>
  127. #include <asm-generic/bitops/fls64.h>
  128. #endif /* __KERNEL__ */
  129. #endif /* __ASM_SH64_BITOPS_H */