|
Revision 2007, 1.8 KB
(checked in by mwhitworth, 3 years ago)
|
|
Add _BitFindFirstSet and fls functions.
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #ifndef BITMAP_H |
|---|
| 22 | #define BITMAP_H |
|---|
| 23 | |
|---|
| 24 | #include <typedefs.h> |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | void BmapSetBit(void* array,DWORD index,int value); |
|---|
| 28 | |
|---|
| 29 | int BmapGetBit(void* array,DWORD index); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | static inline int BitFindFirstZero(void* array, int size) |
|---|
| 33 | { |
|---|
| 34 | int d0, d1, d2; |
|---|
| 35 | int result; |
|---|
| 36 | |
|---|
| 37 | if (!size) |
|---|
| 38 | return 0; |
|---|
| 39 | |
|---|
| 40 | asm volatile( |
|---|
| 41 | "movl $-1,%%eax\n\t" |
|---|
| 42 | "xorl %%edx,%%edx\n\t" |
|---|
| 43 | "repe; scasl\n\t" |
|---|
| 44 | "je 1f\n\t" |
|---|
| 45 | "xorl -4(%%edi),%%eax\n\t" |
|---|
| 46 | "subl $4,%%edi\n\t" |
|---|
| 47 | "bsfl %%eax,%%edx\n" |
|---|
| 48 | "1:\tsubl %%ebx,%%edi\n\t" |
|---|
| 49 | "shll $3,%%edi\n\t" |
|---|
| 50 | "addl %%edi,%%edx" |
|---|
| 51 | :"=d" (result), "=&c" (d0), "=&D" (d1), "=&a" (d2) |
|---|
| 52 | :"1" ((size + 31) >> 5), "2" (array), "b" (array) : "memory"); |
|---|
| 53 | |
|---|
| 54 | return result; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | static inline int _BitFindFirstSet(unsigned long word) |
|---|
| 58 | { |
|---|
| 59 | asm("bsf %1, %0" : "=r"(word) : "rm"(word)); |
|---|
| 60 | return word; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | static inline int fls(unsigned long word) |
|---|
| 65 | { |
|---|
| 66 | if(word == 0) |
|---|
| 67 | return -1; |
|---|
| 68 | |
|---|
| 69 | asm("bsr %1,%0" |
|---|
| 70 | : "=r" (word) |
|---|
| 71 | : "rm" (word)); |
|---|
| 72 | return (int) word; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | #endif |
|---|