bitops.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2005 - Alejandro Liu Ly <alejandro_liu@hotmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifdef __i386__
  19. #define bitop(name,op) \
  20. static inline int name(char * addr,unsigned int nr) \
  21. { \
  22. int __res; \
  23. __asm__ __volatile__("bt" op " %1,%2; adcl $0,%0" \
  24. :"=g" (__res) \
  25. :"r" (nr),"m" (*(addr)),"0" (0)); \
  26. return __res; \
  27. }
  28. bitop(bit,"")
  29. bitop(setbit,"s")
  30. bitop(clrbit,"r")
  31. #elif defined(__mc68000__)
  32. #define bitop(name,op) \
  33. static inline int name (char *addr, unsigned int nr) \
  34. { \
  35. char __res; \
  36. __asm__ __volatile__("bf" op " %2@{%1:#1}; sne %0" \
  37. : "=d" (__res) \
  38. : "d" (nr ^ 15), "a" (addr)); \
  39. return __res != 0; \
  40. }
  41. bitop (bit, "tst")
  42. bitop (setbit, "set")
  43. bitop (clrbit, "clr")
  44. #else
  45. static inline int bit(char * addr,unsigned int nr)
  46. {
  47. return (addr[nr >> 3] & (1<<(nr & 7))) != 0;
  48. }
  49. static inline int setbit(char * addr,unsigned int nr)
  50. {
  51. int __res = bit(addr, nr);
  52. addr[nr >> 3] |= (1<<(nr & 7));
  53. return __res != 0; \
  54. }
  55. static inline int clrbit(char * addr,unsigned int nr)
  56. {
  57. int __res = bit(addr, nr);
  58. addr[nr >> 3] &= ~(1<<(nr & 7));
  59. return __res != 0;
  60. }
  61. #endif