bitops.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #include <linux/compiler.h>
  15. #include <asm/system.h>
  16. /* For __swab32 */
  17. #include <asm/byteorder.h>
  18. static __inline__ void set_bit(int nr, volatile void * addr)
  19. {
  20. int mask;
  21. volatile unsigned int *a = addr;
  22. unsigned long flags;
  23. a += nr >> 5;
  24. mask = 1 << (nr & 0x1f);
  25. local_irq_save(flags);
  26. *a |= mask;
  27. local_irq_restore(flags);
  28. }
  29. /*
  30. * clear_bit() doesn't provide any barrier for the compiler.
  31. */
  32. #define smp_mb__before_clear_bit() barrier()
  33. #define smp_mb__after_clear_bit() barrier()
  34. static inline void clear_bit(int nr, volatile unsigned long *a)
  35. {
  36. int mask;
  37. unsigned long flags;
  38. a += nr >> 5;
  39. mask = 1 << (nr & 0x1f);
  40. local_irq_save(flags);
  41. *a &= ~mask;
  42. local_irq_restore(flags);
  43. }
  44. static __inline__ void change_bit(int nr, volatile void * addr)
  45. {
  46. int mask;
  47. volatile unsigned int *a = addr;
  48. unsigned long flags;
  49. a += nr >> 5;
  50. mask = 1 << (nr & 0x1f);
  51. local_irq_save(flags);
  52. *a ^= mask;
  53. local_irq_restore(flags);
  54. }
  55. static __inline__ int test_and_set_bit(int nr, volatile void * addr)
  56. {
  57. int mask, retval;
  58. volatile unsigned int *a = addr;
  59. unsigned long flags;
  60. a += nr >> 5;
  61. mask = 1 << (nr & 0x1f);
  62. local_irq_save(flags);
  63. retval = (mask & *a) != 0;
  64. *a |= mask;
  65. local_irq_restore(flags);
  66. return retval;
  67. }
  68. static __inline__ int test_and_clear_bit(int nr, volatile void * addr)
  69. {
  70. int mask, retval;
  71. volatile unsigned int *a = addr;
  72. unsigned long flags;
  73. a += nr >> 5;
  74. mask = 1 << (nr & 0x1f);
  75. local_irq_save(flags);
  76. retval = (mask & *a) != 0;
  77. *a &= ~mask;
  78. local_irq_restore(flags);
  79. return retval;
  80. }
  81. static __inline__ int test_and_change_bit(int nr, volatile void * addr)
  82. {
  83. int mask, retval;
  84. volatile unsigned int *a = addr;
  85. unsigned long flags;
  86. a += nr >> 5;
  87. mask = 1 << (nr & 0x1f);
  88. local_irq_save(flags);
  89. retval = (mask & *a) != 0;
  90. *a ^= mask;
  91. local_irq_restore(flags);
  92. return retval;
  93. }
  94. #include <asm-generic/bitops/non-atomic.h>
  95. static __inline__ unsigned long ffz(unsigned long word)
  96. {
  97. unsigned long result, __d2, __d3;
  98. __asm__("gettr tr0, %2\n\t"
  99. "pta $+32, tr0\n\t"
  100. "andi %1, 1, %3\n\t"
  101. "beq %3, r63, tr0\n\t"
  102. "pta $+4, tr0\n"
  103. "0:\n\t"
  104. "shlri.l %1, 1, %1\n\t"
  105. "addi %0, 1, %0\n\t"
  106. "andi %1, 1, %3\n\t"
  107. "beqi %3, 1, tr0\n"
  108. "1:\n\t"
  109. "ptabs %2, tr0\n\t"
  110. : "=r" (result), "=r" (word), "=r" (__d2), "=r" (__d3)
  111. : "0" (0L), "1" (word));
  112. return result;
  113. }
  114. #include <asm-generic/bitops/__ffs.h>
  115. #include <asm-generic/bitops/find.h>
  116. #include <asm-generic/bitops/hweight.h>
  117. #include <asm-generic/bitops/sched.h>
  118. #include <asm-generic/bitops/ffs.h>
  119. #include <asm-generic/bitops/ext2-non-atomic.h>
  120. #include <asm-generic/bitops/ext2-atomic.h>
  121. #include <asm-generic/bitops/minix.h>
  122. #include <asm-generic/bitops/fls.h>
  123. #include <asm-generic/bitops/fls64.h>
  124. #endif /* __KERNEL__ */
  125. #endif /* __ASM_SH64_BITOPS_H */