bitops.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 1994 - 1997, 99, 2000, 06, 07 Ralf Baechle (ralf@linux-mips.org)
  7. * Copyright (c) 1999, 2000 Silicon Graphics, Inc.
  8. */
  9. #ifndef _ASM_BITOPS_H
  10. #define _ASM_BITOPS_H
  11. #include <linux/compiler.h>
  12. #include <linux/irqflags.h>
  13. #include <linux/types.h>
  14. #include <asm/barrier.h>
  15. #include <asm/bug.h>
  16. #include <asm/byteorder.h> /* sigh ... */
  17. #include <asm/cpu-features.h>
  18. #include <asm/sgidefs.h>
  19. #include <asm/war.h>
  20. #if _MIPS_SZLONG == 32
  21. #define SZLONG_LOG 5
  22. #define SZLONG_MASK 31UL
  23. #define __LL "ll "
  24. #define __SC "sc "
  25. #define __INS "ins "
  26. #define __EXT "ext "
  27. #elif _MIPS_SZLONG == 64
  28. #define SZLONG_LOG 6
  29. #define SZLONG_MASK 63UL
  30. #define __LL "lld "
  31. #define __SC "scd "
  32. #define __INS "dins "
  33. #define __EXT "dext "
  34. #endif
  35. /*
  36. * clear_bit() doesn't provide any barrier for the compiler.
  37. */
  38. #define smp_mb__before_clear_bit() smp_llsc_mb()
  39. #define smp_mb__after_clear_bit() smp_llsc_mb()
  40. /*
  41. * set_bit - Atomically set a bit in memory
  42. * @nr: the bit to set
  43. * @addr: the address to start counting from
  44. *
  45. * This function is atomic and may not be reordered. See __set_bit()
  46. * if you do not require the atomic guarantees.
  47. * Note that @nr may be almost arbitrarily large; this function is not
  48. * restricted to acting on a single-word quantity.
  49. */
  50. static inline void set_bit(unsigned long nr, volatile unsigned long *addr)
  51. {
  52. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  53. unsigned short bit = nr & SZLONG_MASK;
  54. unsigned long temp;
  55. if (cpu_has_llsc && R10000_LLSC_WAR) {
  56. __asm__ __volatile__(
  57. " .set mips3 \n"
  58. "1: " __LL "%0, %1 # set_bit \n"
  59. " or %0, %2 \n"
  60. " " __SC "%0, %1 \n"
  61. " beqzl %0, 1b \n"
  62. " .set mips0 \n"
  63. : "=&r" (temp), "=m" (*m)
  64. : "ir" (1UL << bit), "m" (*m));
  65. #ifdef CONFIG_CPU_MIPSR2
  66. } else if (__builtin_constant_p(bit)) {
  67. __asm__ __volatile__(
  68. "1: " __LL "%0, %1 # set_bit \n"
  69. " " __INS "%0, %4, %2, 1 \n"
  70. " " __SC "%0, %1 \n"
  71. " beqz %0, 2f \n"
  72. " .subsection 2 \n"
  73. "2: b 1b \n"
  74. " .previous \n"
  75. : "=&r" (temp), "=m" (*m)
  76. : "ir" (bit), "m" (*m), "r" (~0));
  77. #endif /* CONFIG_CPU_MIPSR2 */
  78. } else if (cpu_has_llsc) {
  79. __asm__ __volatile__(
  80. " .set mips3 \n"
  81. "1: " __LL "%0, %1 # set_bit \n"
  82. " or %0, %2 \n"
  83. " " __SC "%0, %1 \n"
  84. " beqz %0, 2f \n"
  85. " .subsection 2 \n"
  86. "2: b 1b \n"
  87. " .previous \n"
  88. " .set mips0 \n"
  89. : "=&r" (temp), "=m" (*m)
  90. : "ir" (1UL << bit), "m" (*m));
  91. } else {
  92. volatile unsigned long *a = addr;
  93. unsigned long mask;
  94. unsigned long flags;
  95. a += nr >> SZLONG_LOG;
  96. mask = 1UL << bit;
  97. raw_local_irq_save(flags);
  98. *a |= mask;
  99. raw_local_irq_restore(flags);
  100. }
  101. }
  102. /*
  103. * clear_bit - Clears a bit in memory
  104. * @nr: Bit to clear
  105. * @addr: Address to start counting from
  106. *
  107. * clear_bit() is atomic and may not be reordered. However, it does
  108. * not contain a memory barrier, so if it is used for locking purposes,
  109. * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
  110. * in order to ensure changes are visible on other processors.
  111. */
  112. static inline void clear_bit(unsigned long nr, volatile unsigned long *addr)
  113. {
  114. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  115. unsigned short bit = nr & SZLONG_MASK;
  116. unsigned long temp;
  117. if (cpu_has_llsc && R10000_LLSC_WAR) {
  118. __asm__ __volatile__(
  119. " .set mips3 \n"
  120. "1: " __LL "%0, %1 # clear_bit \n"
  121. " and %0, %2 \n"
  122. " " __SC "%0, %1 \n"
  123. " beqzl %0, 1b \n"
  124. " .set mips0 \n"
  125. : "=&r" (temp), "=m" (*m)
  126. : "ir" (~(1UL << bit)), "m" (*m));
  127. #ifdef CONFIG_CPU_MIPSR2
  128. } else if (__builtin_constant_p(bit)) {
  129. __asm__ __volatile__(
  130. "1: " __LL "%0, %1 # clear_bit \n"
  131. " " __INS "%0, $0, %2, 1 \n"
  132. " " __SC "%0, %1 \n"
  133. " beqz %0, 2f \n"
  134. " .subsection 2 \n"
  135. "2: b 1b \n"
  136. " .previous \n"
  137. : "=&r" (temp), "=m" (*m)
  138. : "ir" (bit), "m" (*m));
  139. #endif /* CONFIG_CPU_MIPSR2 */
  140. } else if (cpu_has_llsc) {
  141. __asm__ __volatile__(
  142. " .set mips3 \n"
  143. "1: " __LL "%0, %1 # clear_bit \n"
  144. " and %0, %2 \n"
  145. " " __SC "%0, %1 \n"
  146. " beqz %0, 2f \n"
  147. " .subsection 2 \n"
  148. "2: b 1b \n"
  149. " .previous \n"
  150. " .set mips0 \n"
  151. : "=&r" (temp), "=m" (*m)
  152. : "ir" (~(1UL << bit)), "m" (*m));
  153. } else {
  154. volatile unsigned long *a = addr;
  155. unsigned long mask;
  156. unsigned long flags;
  157. a += nr >> SZLONG_LOG;
  158. mask = 1UL << bit;
  159. raw_local_irq_save(flags);
  160. *a &= ~mask;
  161. raw_local_irq_restore(flags);
  162. }
  163. }
  164. /*
  165. * clear_bit_unlock - Clears a bit in memory
  166. * @nr: Bit to clear
  167. * @addr: Address to start counting from
  168. *
  169. * clear_bit() is atomic and implies release semantics before the memory
  170. * operation. It can be used for an unlock.
  171. */
  172. static inline void clear_bit_unlock(unsigned long nr, volatile unsigned long *addr)
  173. {
  174. smp_mb__before_clear_bit();
  175. clear_bit(nr, addr);
  176. }
  177. /*
  178. * change_bit - Toggle a bit in memory
  179. * @nr: Bit to change
  180. * @addr: Address to start counting from
  181. *
  182. * change_bit() is atomic and may not be reordered.
  183. * Note that @nr may be almost arbitrarily large; this function is not
  184. * restricted to acting on a single-word quantity.
  185. */
  186. static inline void change_bit(unsigned long nr, volatile unsigned long *addr)
  187. {
  188. unsigned short bit = nr & SZLONG_MASK;
  189. if (cpu_has_llsc && R10000_LLSC_WAR) {
  190. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  191. unsigned long temp;
  192. __asm__ __volatile__(
  193. " .set mips3 \n"
  194. "1: " __LL "%0, %1 # change_bit \n"
  195. " xor %0, %2 \n"
  196. " " __SC "%0, %1 \n"
  197. " beqzl %0, 1b \n"
  198. " .set mips0 \n"
  199. : "=&r" (temp), "=m" (*m)
  200. : "ir" (1UL << bit), "m" (*m));
  201. } else if (cpu_has_llsc) {
  202. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  203. unsigned long temp;
  204. __asm__ __volatile__(
  205. " .set mips3 \n"
  206. "1: " __LL "%0, %1 # change_bit \n"
  207. " xor %0, %2 \n"
  208. " " __SC "%0, %1 \n"
  209. " beqz %0, 2f \n"
  210. " .subsection 2 \n"
  211. "2: b 1b \n"
  212. " .previous \n"
  213. " .set mips0 \n"
  214. : "=&r" (temp), "=m" (*m)
  215. : "ir" (1UL << bit), "m" (*m));
  216. } else {
  217. volatile unsigned long *a = addr;
  218. unsigned long mask;
  219. unsigned long flags;
  220. a += nr >> SZLONG_LOG;
  221. mask = 1UL << bit;
  222. raw_local_irq_save(flags);
  223. *a ^= mask;
  224. raw_local_irq_restore(flags);
  225. }
  226. }
  227. /*
  228. * test_and_set_bit - Set a bit and return its old value
  229. * @nr: Bit to set
  230. * @addr: Address to count from
  231. *
  232. * This operation is atomic and cannot be reordered.
  233. * It also implies a memory barrier.
  234. */
  235. static inline int test_and_set_bit(unsigned long nr,
  236. volatile unsigned long *addr)
  237. {
  238. unsigned short bit = nr & SZLONG_MASK;
  239. unsigned long res;
  240. smp_llsc_mb();
  241. if (cpu_has_llsc && R10000_LLSC_WAR) {
  242. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  243. unsigned long temp;
  244. __asm__ __volatile__(
  245. " .set mips3 \n"
  246. "1: " __LL "%0, %1 # test_and_set_bit \n"
  247. " or %2, %0, %3 \n"
  248. " " __SC "%2, %1 \n"
  249. " beqzl %2, 1b \n"
  250. " and %2, %0, %3 \n"
  251. " .set mips0 \n"
  252. : "=&r" (temp), "=m" (*m), "=&r" (res)
  253. : "r" (1UL << bit), "m" (*m)
  254. : "memory");
  255. } else if (cpu_has_llsc) {
  256. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  257. unsigned long temp;
  258. __asm__ __volatile__(
  259. " .set push \n"
  260. " .set noreorder \n"
  261. " .set mips3 \n"
  262. "1: " __LL "%0, %1 # test_and_set_bit \n"
  263. " or %2, %0, %3 \n"
  264. " " __SC "%2, %1 \n"
  265. " beqz %2, 2f \n"
  266. " and %2, %0, %3 \n"
  267. " .subsection 2 \n"
  268. "2: b 1b \n"
  269. " nop \n"
  270. " .previous \n"
  271. " .set pop \n"
  272. : "=&r" (temp), "=m" (*m), "=&r" (res)
  273. : "r" (1UL << bit), "m" (*m)
  274. : "memory");
  275. } else {
  276. volatile unsigned long *a = addr;
  277. unsigned long mask;
  278. unsigned long flags;
  279. a += nr >> SZLONG_LOG;
  280. mask = 1UL << bit;
  281. raw_local_irq_save(flags);
  282. res = (mask & *a);
  283. *a |= mask;
  284. raw_local_irq_restore(flags);
  285. }
  286. smp_llsc_mb();
  287. return res != 0;
  288. }
  289. /*
  290. * test_and_set_bit_lock - Set a bit and return its old value
  291. * @nr: Bit to set
  292. * @addr: Address to count from
  293. *
  294. * This operation is atomic and implies acquire ordering semantics
  295. * after the memory operation.
  296. */
  297. static inline int test_and_set_bit_lock(unsigned long nr,
  298. volatile unsigned long *addr)
  299. {
  300. unsigned short bit = nr & SZLONG_MASK;
  301. unsigned long res;
  302. if (cpu_has_llsc && R10000_LLSC_WAR) {
  303. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  304. unsigned long temp;
  305. __asm__ __volatile__(
  306. " .set mips3 \n"
  307. "1: " __LL "%0, %1 # test_and_set_bit \n"
  308. " or %2, %0, %3 \n"
  309. " " __SC "%2, %1 \n"
  310. " beqzl %2, 1b \n"
  311. " and %2, %0, %3 \n"
  312. " .set mips0 \n"
  313. : "=&r" (temp), "=m" (*m), "=&r" (res)
  314. : "r" (1UL << bit), "m" (*m)
  315. : "memory");
  316. } else if (cpu_has_llsc) {
  317. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  318. unsigned long temp;
  319. __asm__ __volatile__(
  320. " .set push \n"
  321. " .set noreorder \n"
  322. " .set mips3 \n"
  323. "1: " __LL "%0, %1 # test_and_set_bit \n"
  324. " or %2, %0, %3 \n"
  325. " " __SC "%2, %1 \n"
  326. " beqz %2, 2f \n"
  327. " and %2, %0, %3 \n"
  328. " .subsection 2 \n"
  329. "2: b 1b \n"
  330. " nop \n"
  331. " .previous \n"
  332. " .set pop \n"
  333. : "=&r" (temp), "=m" (*m), "=&r" (res)
  334. : "r" (1UL << bit), "m" (*m)
  335. : "memory");
  336. } else {
  337. volatile unsigned long *a = addr;
  338. unsigned long mask;
  339. unsigned long flags;
  340. a += nr >> SZLONG_LOG;
  341. mask = 1UL << bit;
  342. raw_local_irq_save(flags);
  343. res = (mask & *a);
  344. *a |= mask;
  345. raw_local_irq_restore(flags);
  346. }
  347. smp_llsc_mb();
  348. return res != 0;
  349. }
  350. /*
  351. * test_and_clear_bit - Clear a bit and return its old value
  352. * @nr: Bit to clear
  353. * @addr: Address to count from
  354. *
  355. * This operation is atomic and cannot be reordered.
  356. * It also implies a memory barrier.
  357. */
  358. static inline int test_and_clear_bit(unsigned long nr,
  359. volatile unsigned long *addr)
  360. {
  361. unsigned short bit = nr & SZLONG_MASK;
  362. unsigned long res;
  363. smp_llsc_mb();
  364. if (cpu_has_llsc && R10000_LLSC_WAR) {
  365. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  366. unsigned long temp;
  367. __asm__ __volatile__(
  368. " .set mips3 \n"
  369. "1: " __LL "%0, %1 # test_and_clear_bit \n"
  370. " or %2, %0, %3 \n"
  371. " xor %2, %3 \n"
  372. " " __SC "%2, %1 \n"
  373. " beqzl %2, 1b \n"
  374. " and %2, %0, %3 \n"
  375. " .set mips0 \n"
  376. : "=&r" (temp), "=m" (*m), "=&r" (res)
  377. : "r" (1UL << bit), "m" (*m)
  378. : "memory");
  379. #ifdef CONFIG_CPU_MIPSR2
  380. } else if (__builtin_constant_p(nr)) {
  381. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  382. unsigned long temp;
  383. __asm__ __volatile__(
  384. "1: " __LL "%0, %1 # test_and_clear_bit \n"
  385. " " __EXT "%2, %0, %3, 1 \n"
  386. " " __INS "%0, $0, %3, 1 \n"
  387. " " __SC "%0, %1 \n"
  388. " beqz %0, 2f \n"
  389. " .subsection 2 \n"
  390. "2: b 1b \n"
  391. " .previous \n"
  392. : "=&r" (temp), "=m" (*m), "=&r" (res)
  393. : "ri" (bit), "m" (*m)
  394. : "memory");
  395. #endif
  396. } else if (cpu_has_llsc) {
  397. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  398. unsigned long temp;
  399. __asm__ __volatile__(
  400. " .set push \n"
  401. " .set noreorder \n"
  402. " .set mips3 \n"
  403. "1: " __LL "%0, %1 # test_and_clear_bit \n"
  404. " or %2, %0, %3 \n"
  405. " xor %2, %3 \n"
  406. " " __SC "%2, %1 \n"
  407. " beqz %2, 2f \n"
  408. " and %2, %0, %3 \n"
  409. " .subsection 2 \n"
  410. "2: b 1b \n"
  411. " nop \n"
  412. " .previous \n"
  413. " .set pop \n"
  414. : "=&r" (temp), "=m" (*m), "=&r" (res)
  415. : "r" (1UL << bit), "m" (*m)
  416. : "memory");
  417. } else {
  418. volatile unsigned long *a = addr;
  419. unsigned long mask;
  420. unsigned long flags;
  421. a += nr >> SZLONG_LOG;
  422. mask = 1UL << bit;
  423. raw_local_irq_save(flags);
  424. res = (mask & *a);
  425. *a &= ~mask;
  426. raw_local_irq_restore(flags);
  427. }
  428. smp_llsc_mb();
  429. return res != 0;
  430. }
  431. /*
  432. * test_and_change_bit - Change a bit and return its old value
  433. * @nr: Bit to change
  434. * @addr: Address to count from
  435. *
  436. * This operation is atomic and cannot be reordered.
  437. * It also implies a memory barrier.
  438. */
  439. static inline int test_and_change_bit(unsigned long nr,
  440. volatile unsigned long *addr)
  441. {
  442. unsigned short bit = nr & SZLONG_MASK;
  443. unsigned long res;
  444. smp_llsc_mb();
  445. if (cpu_has_llsc && R10000_LLSC_WAR) {
  446. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  447. unsigned long temp;
  448. __asm__ __volatile__(
  449. " .set mips3 \n"
  450. "1: " __LL "%0, %1 # test_and_change_bit \n"
  451. " xor %2, %0, %3 \n"
  452. " " __SC "%2, %1 \n"
  453. " beqzl %2, 1b \n"
  454. " and %2, %0, %3 \n"
  455. " .set mips0 \n"
  456. : "=&r" (temp), "=m" (*m), "=&r" (res)
  457. : "r" (1UL << bit), "m" (*m)
  458. : "memory");
  459. } else if (cpu_has_llsc) {
  460. unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
  461. unsigned long temp;
  462. __asm__ __volatile__(
  463. " .set push \n"
  464. " .set noreorder \n"
  465. " .set mips3 \n"
  466. "1: " __LL "%0, %1 # test_and_change_bit \n"
  467. " xor %2, %0, %3 \n"
  468. " " __SC "\t%2, %1 \n"
  469. " beqz %2, 2f \n"
  470. " and %2, %0, %3 \n"
  471. " .subsection 2 \n"
  472. "2: b 1b \n"
  473. " nop \n"
  474. " .previous \n"
  475. " .set pop \n"
  476. : "=&r" (temp), "=m" (*m), "=&r" (res)
  477. : "r" (1UL << bit), "m" (*m)
  478. : "memory");
  479. } else {
  480. volatile unsigned long *a = addr;
  481. unsigned long mask;
  482. unsigned long flags;
  483. a += nr >> SZLONG_LOG;
  484. mask = 1UL << bit;
  485. raw_local_irq_save(flags);
  486. res = (mask & *a);
  487. *a ^= mask;
  488. raw_local_irq_restore(flags);
  489. }
  490. smp_llsc_mb();
  491. return res != 0;
  492. }
  493. #include <asm-generic/bitops/non-atomic.h>
  494. /*
  495. * __clear_bit_unlock - Clears a bit in memory
  496. * @nr: Bit to clear
  497. * @addr: Address to start counting from
  498. *
  499. * __clear_bit() is non-atomic and implies release semantics before the memory
  500. * operation. It can be used for an unlock if no other CPUs can concurrently
  501. * modify other bits in the word.
  502. */
  503. static inline void __clear_bit_unlock(unsigned long nr, volatile unsigned long *addr)
  504. {
  505. smp_mb();
  506. __clear_bit(nr, addr);
  507. }
  508. /*
  509. * Return the bit position (0..63) of the most significant 1 bit in a word
  510. * Returns -1 if no 1 bit exists
  511. */
  512. static inline int __ilog2(unsigned long x)
  513. {
  514. int lz;
  515. if (sizeof(x) == 4) {
  516. __asm__(
  517. " .set push \n"
  518. " .set mips32 \n"
  519. " clz %0, %1 \n"
  520. " .set pop \n"
  521. : "=r" (lz)
  522. : "r" (x));
  523. return 31 - lz;
  524. }
  525. BUG_ON(sizeof(x) != 8);
  526. __asm__(
  527. " .set push \n"
  528. " .set mips64 \n"
  529. " dclz %0, %1 \n"
  530. " .set pop \n"
  531. : "=r" (lz)
  532. : "r" (x));
  533. return 63 - lz;
  534. }
  535. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  536. /*
  537. * __ffs - find first bit in word.
  538. * @word: The word to search
  539. *
  540. * Returns 0..SZLONG-1
  541. * Undefined if no bit exists, so code should check against 0 first.
  542. */
  543. static inline unsigned long __ffs(unsigned long word)
  544. {
  545. return __ilog2(word & -word);
  546. }
  547. /*
  548. * fls - find last bit set.
  549. * @word: The word to search
  550. *
  551. * This is defined the same way as ffs.
  552. * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  553. */
  554. static inline int fls(int word)
  555. {
  556. __asm__("clz %0, %1" : "=r" (word) : "r" (word));
  557. return 32 - word;
  558. }
  559. #if defined(CONFIG_64BIT) && defined(CONFIG_CPU_MIPS64)
  560. static inline int fls64(__u64 word)
  561. {
  562. __asm__("dclz %0, %1" : "=r" (word) : "r" (word));
  563. return 64 - word;
  564. }
  565. #else
  566. #include <asm-generic/bitops/fls64.h>
  567. #endif
  568. /*
  569. * ffs - find first bit set.
  570. * @word: The word to search
  571. *
  572. * This is defined the same way as
  573. * the libc and compiler builtin ffs routines, therefore
  574. * differs in spirit from the above ffz (man ffs).
  575. */
  576. static inline int ffs(int word)
  577. {
  578. if (!word)
  579. return 0;
  580. return fls(word & -word);
  581. }
  582. #else
  583. #include <asm-generic/bitops/__ffs.h>
  584. #include <asm-generic/bitops/ffs.h>
  585. #include <asm-generic/bitops/fls.h>
  586. #include <asm-generic/bitops/fls64.h>
  587. #endif /*defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64) */
  588. #include <asm-generic/bitops/ffz.h>
  589. #include <asm-generic/bitops/find.h>
  590. #ifdef __KERNEL__
  591. #include <asm-generic/bitops/sched.h>
  592. #include <asm-generic/bitops/hweight.h>
  593. #include <asm-generic/bitops/ext2-non-atomic.h>
  594. #include <asm-generic/bitops/ext2-atomic.h>
  595. #include <asm-generic/bitops/minix.h>
  596. #endif /* __KERNEL__ */
  597. #endif /* _ASM_BITOPS_H */