[asterisk-users] Use the NEW ulaw/alaw codecs (slower, but cleaner)

Steve Underwood steveu at coppice.org
Tue Nov 18 17:26:21 CST 2008


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




More information about the asterisk-users mailing list