当前位置: 技术问答>linux和unix
位映射??????????
来源: 互联网 发布时间:2016-04-09
本文导语: // Bitmap manipulation routines #include "bitops.h" int find_first_zero_bit(void *bitmap, int len) { int result; if (!len) return 0; __asm { mov ebx, bitmap mov edi, ebx mov ecx, len add ecx, 31 shr ecx,...
// Bitmap manipulation routines
#include "bitops.h"
int find_first_zero_bit(void *bitmap, int len)
{
int result;
if (!len) return 0;
__asm
{
mov ebx, bitmap
mov edi, ebx
mov ecx, len
add ecx, 31
shr ecx, 5
xor edx, edx
mov eax, -1
repe scasd
je ffzb1
sub edi, 4
xor eax, [edi]
bsf edx, eax
ffzb1:
sub edi, ebx
shl edi, 3
add edx, edi
mov result, edx
}
return result;
}
不知道这代码是什么意思,用途何在。随便GOOGLE下,说查找什么最高位为0的,看了半天还是不明白。
#include "bitops.h"
int find_first_zero_bit(void *bitmap, int len)
{
int result;
if (!len) return 0;
__asm
{
mov ebx, bitmap
mov edi, ebx
mov ecx, len
add ecx, 31
shr ecx, 5
xor edx, edx
mov eax, -1
repe scasd
je ffzb1
sub edi, 4
xor eax, [edi]
bsf edx, eax
ffzb1:
sub edi, ebx
shl edi, 3
add edx, edi
mov result, edx
}
return result;
}
不知道这代码是什么意思,用途何在。随便GOOGLE下,说查找什么最高位为0的,看了半天还是不明白。
|
The kernel also provides routines to find the first set (or unset) bit starting at a given address:
int find_first_bit(unsigned long *addr, unsigned int size)
int find_first_zero_bit(unsigned long *addr, unsigned int size)
Both functions take a pointer as their first argument and the number of bits in total to search as their second. They return the bit number of the first set or first unset bit, respectively. If your code is searching only a word, the routines __ffs() and ffz(), which take a single parameter of the word in which to search, are optimal.
在Linux Kernel Development 的第九章有提到。 不过具体的实现你要自己去看了。
还有,可以看看其他平台的非汇编实现。
int find_first_bit(unsigned long *addr, unsigned int size)
int find_first_zero_bit(unsigned long *addr, unsigned int size)
Both functions take a pointer as their first argument and the number of bits in total to search as their second. They return the bit number of the first set or first unset bit, respectively. If your code is searching only a word, the routines __ffs() and ffz(), which take a single parameter of the word in which to search, are optimal.
在Linux Kernel Development 的第九章有提到。 不过具体的实现你要自己去看了。
还有,可以看看其他平台的非汇编实现。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。