bitops.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef _ASM_GENERIC_BITOPS_H_
  2. #define _ASM_GENERIC_BITOPS_H_
  3. /*
  4. * For the benefit of those who are trying to port Linux to another
  5. * architecture, here are some C-language equivalents. You should
  6. * recode these in the native assembly language, if at all possible.
  7. * To guarantee atomicity, these routines call cli() and sti() to
  8. * disable interrupts while they operate. (You have to provide inline
  9. * routines to cli() and sti().)
  10. *
  11. * Also note, these routines assume that you have 32 bit longs.
  12. * You will have to change this if you are trying to port Linux to the
  13. * Alpha architecture or to a Cray. :-)
  14. *
  15. * C language equivalents written by Theodore Ts'o, 9/26/92
  16. */
  17. extern __inline__ int set_bit(int nr,long * addr)
  18. {
  19. int mask, retval;
  20. addr += nr >> 5;
  21. mask = 1 << (nr & 0x1f);
  22. cli();
  23. retval = (mask & *addr) != 0;
  24. *addr |= mask;
  25. sti();
  26. return retval;
  27. }
  28. extern __inline__ int clear_bit(int nr, long * addr)
  29. {
  30. int mask, retval;
  31. addr += nr >> 5;
  32. mask = 1 << (nr & 0x1f);
  33. cli();
  34. retval = (mask & *addr) != 0;
  35. *addr &= ~mask;
  36. sti();
  37. return retval;
  38. }
  39. extern __inline__ int test_bit(int nr, const unsigned long * addr)
  40. {
  41. int mask;
  42. addr += nr >> 5;
  43. mask = 1 << (nr & 0x1f);
  44. return ((mask & *addr) != 0);
  45. }
  46. /*
  47. * fls: find last bit set.
  48. */
  49. #define fls(x) generic_fls(x)
  50. #define fls64(x) generic_fls64(x)
  51. #ifdef __KERNEL__
  52. /*
  53. * ffs: find first bit set. This is defined the same way as
  54. * the libc and compiler builtin ffs routines, therefore
  55. * differs in spirit from the above ffz (man ffs).
  56. */
  57. #define ffs(x) generic_ffs(x)
  58. /*
  59. * hweightN: returns the hamming weight (i.e. the number
  60. * of bits set) of a N-bit word
  61. */
  62. #define hweight32(x) generic_hweight32(x)
  63. #define hweight16(x) generic_hweight16(x)
  64. #define hweight8(x) generic_hweight8(x)
  65. #endif /* __KERNEL__ */
  66. #endif /* _ASM_GENERIC_BITOPS_H */