Benny Amorsen wrote:
> 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.
>
>   
Measurement is the wrong issue to look at. The Digium one is just wrong. 
The bsr or bsrl does not set the result register if the source is zero. 
It indicated the zero condition through a flag. Its faster to avoid 
testing that flag, and just preload the result register with a well 
known value.

Steve


_______________________________________________
-- 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