Interestingly the Linux kernel has this for find-last-set:

static inline unsigned long __fls(unsigned long word)
{
       asm("bsr %1,%0"
           :"=r" (word)
           :"rm" (word));
       return word;
}

spandsp has this (Everything non-x86 has been removed):

static __inline__ int top_bit(unsigned int bits)
{
    int res;

    __asm__ (" xorl %[res],%[res];\n"
             " decl %[res];\n"
             " bsrl %[bits],%[res]\n"
             : [res] "=&r" (res)
             : [bits] "rm" (bits));
    return res;
}

I haven't measured which one is best.


/Benny


_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to