bitops.h 16 KB

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