find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax

1.3.100

find_first_zero_bit在使用gcc 4.2.4 编译时,需要保护%eax

find_first_zero_bit 修订后:

/*
 * Find-bit routines..
 */
extern __inline__ int find_first_zero_bit(void * addr, unsigned size)
{
    int res;

    if (!size)
        return 0;
    __asm__ ("cld\n\t"
        "pushl %%eax\n\t" //fixed:
        "movl $-1,%%eax\n\t"
        "xorl %%edx,%%edx\n\t"
        "repe; scasl\n\t"
        "je 1f\n\t"
        "xorl -4(%%edi),%%eax\n\t"
        "subl $4,%%edi\n\t"
        "bsfl %%eax,%%edx\n"
        "1:\tsubl %%ebx,%%edi\n\t"
        "shll $3,%%edi\n\t"
        "addl %%edi,%%edx\n\t"
        "popl %%eax"
        :"=d" (res)
        :"c" ((size + 31) >> 5), "D" (addr), "b" (addr)
        /*:"ax", "cx", "di"*/);
    return res;
}

posted @ 2017-12-14 11:14  mull  阅读(565)  评论(0编辑  收藏  举报