Skip to content
Snippets Groups Projects
Commit a16cef62 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry
Browse files

Replace silk_CLZ functions with EC_ILOG().

In most cases these will use __builtin_clz().
In a follow-up, we should audit usage of silk_CLZ32() and convert
 the places where its argument must be non-zero to use EC_ILOG()
 directly to avoid the test for zero (which is necessary on x86).
parent 80ad3837
No related branches found
No related tags found
No related merge requests found
...@@ -76,50 +76,16 @@ POSSIBILITY OF SUCH DAMAGE. ...@@ -76,50 +76,16 @@ POSSIBILITY OF SUCH DAMAGE.
(( (a) & ((b)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a)-(b)) : \ (( (a) & ((b)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a)-(b)) : \
((((a)^0x80000000) & (b) & 0x80000000) ? silk_int32_MAX : (a)-(b)) ) ((((a)^0x80000000) & (b) & 0x80000000) ? silk_int32_MAX : (a)-(b)) )
#include "ecintrin.h"
static inline opus_int32 silk_CLZ16(opus_int16 in16) static inline opus_int32 silk_CLZ16(opus_int16 in16)
{ {
opus_int32 out32 = 0; return 32 - EC_ILOG(in16<<16|0x8000);
if( in16 == 0 ) {
return 16;
}
/* test nibbles */
if( in16 & 0xFF00 ) {
if( in16 & 0xF000 ) {
in16 >>= 12;
} else {
out32 += 4;
in16 >>= 8;
}
} else {
if( in16 & 0xFFF0 ) {
out32 += 8;
in16 >>= 4;
} else {
out32 += 12;
}
}
/* test bits and return */
if( in16 & 0xC ) {
if( in16 & 0x8 )
return out32 + 0;
else
return out32 + 1;
} else {
if( in16 & 0xE )
return out32 + 2;
else
return out32 + 3;
}
} }
static inline opus_int32 silk_CLZ32(opus_int32 in32) static inline opus_int32 silk_CLZ32(opus_int32 in32)
{ {
/* test highest 16 bits and convert to opus_int16 */ return in32 ? 32 - EC_ILOG(in32) : 0;
if( in32 & 0xFFFF0000 ) {
return silk_CLZ16((opus_int16)(in32 >> 16));
} else {
return silk_CLZ16((opus_int16)in32) + 16;
}
} }
/* Row based */ /* Row based */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment