test_bit

来源:互联网 发布:mac os 10.11 iso 编辑:程序博客网 时间:2024/05/05 12:41
include/asm-arm/bitopt.h

test_bit   测试相应地址的nr位是否为 1.

_test_bit_be( int nr, const void *addr)
{
       /* nr ^ 0x18  >> 3 是将高低字节反转 如:  0 <=> 3  , 1 <=>2 */
      /* 1 << (nr &7 )  是取出相应字节的相应位  如  1 对应第三字节的第一位  */
                                                                         
       return ((unsinged char *) addr )[ (nr ^ 0x18) >>3 ]  &  (1U <<(nr &7 ));

}
    
_test_and_set_bit_be   使用汇编来写保证原子操作 
__test_and_set_bit_be  用c语言没有原子操作

逻辑左移  <<   是跟体系结构无关的,就是高位,
    little endian 每个字节中的高位在高内存,
    bigendian 每个字节中的高位还是在低内存
    举例:
 struct  {
                 unsigned char   a1:4;
                 unsigned char   a2:4;
   }  a;
  unsigned char *b=&a;
  a.a1=0;
  a.a2=0xff;
  *b  在little endian  中是 0xf0;
            big   endian  中是 0xf;
 
            









              
原创粉丝点击