root/include/asm/bitops.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. set_bit
  2. clear_bit
  3. test_bit
  4. set_bit
  5. clear_bit
  6. test_bit

   1 #ifndef _ASM_BITOPS_H
   2 /*
   3  * Copyright 1992, Linus Torvalds.
   4  */
   5 
   6 #ifdef i386
   7 /*
   8  * These have to be done with inline assembly: that way the bit-setting
   9  * is guaranteed to be atomic. Both set_bit and clear_bit return 0
  10  * if the bit-setting went ok, != 0 if the bit already was set/cleared.
  11  *
  12  * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
  13  */
  14 
  15 /*
  16  * Some hacks to defeat gcc over-optimizations..
  17  */
  18 struct __dummy { unsigned long a[100]; };
  19 #define ADDR (*(struct __dummy *) addr)
  20 
  21 extern inline int set_bit(int nr, void * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  22 {
  23         unsigned char ok;
  24 
  25         __asm__ __volatile__("btsl %2,%1\n\tsetb %0"
  26                 :"=q" (ok),"=m" (ADDR)
  27                 :"r" (nr));
  28         return ok;
  29 }
  30 
  31 extern inline int clear_bit(int nr, void * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  32 {
  33         unsigned char ok;
  34 
  35         __asm__ __volatile__("btrl %2,%1\n\tsetnb %0"
  36                 :"=q" (ok),"=m" (ADDR)
  37                 :"r" (nr));
  38         return ok;
  39 }
  40 
  41 /*
  42  * This routine doesn't need to be atomic, but it's faster to code it
  43  * this way.
  44  */
  45 extern inline int test_bit(int nr, void * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47         unsigned char ok;
  48 
  49         __asm__ __volatile__("btl %2,%1\n\tsetb %0"
  50                 :"=q" (ok)
  51                 :"m" (ADDR),"r" (nr));
  52         return ok;
  53 }
  54 
  55 #else
  56 /*
  57  * For the benefit of those who are trying to port Linux to another
  58  * architecture, here are some C-language equivalents.  You should
  59  * recode these in the native assmebly language, if at all possible.
  60  * To guarantee atomicity, these routines call cli() and sti() to
  61  * disable interrupts while they operate.  (You have to provide inline
  62  * routines to cli() and sti().)
  63  *
  64  * Also note, these routines assume that you have 32 bit integers.
  65  * You will have to change this if you are trying to port Linux to the
  66  * Alpha architecture or to a Cray.  :-)
  67  * 
  68  * C language equivalents written by Theodore Ts'o, 9/26/92
  69  */
  70 
  71 extern inline int set_bit(int nr,int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73         int     mask, retval;
  74 
  75         addr += nr >> 5;
  76         mask = 1 << (nr & 0x1f);
  77         cli();
  78         retval = (mask & *addr) != 0;
  79         *addr |= mask;
  80         sti();
  81         return retval;
  82 }
  83 
  84 extern inline int clear_bit(int nr, int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         int     mask, retval;
  87 
  88         addr += nr >> 5;
  89         mask = 1 << (nr & 0x1f);
  90         cli();
  91         retval = (mask & *addr) == 0;
  92         *addr &= ~mask;
  93         sti();
  94         return retval;
  95 }
  96 
  97 extern inline int test_bit(int nr, int * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
  98 {
  99         int     mask;
 100 
 101         addr += nr >> 5;
 102         mask = 1 << (nr & 0x1f);
 103         return ((mask & *addr) != 0);
 104 }
 105 #endif  /* i386 */
 106 #endif /* _ASM_BITOPS_H */

/* [previous][next][first][last][top][bottom][index][help] */