bitops.h 16 KB

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