From bf26db91294a1de2f9199341ee41f068f168bec2 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Fri, 4 Oct 2002 05:24:10 +0000 Subject: [PATCH] add wide version of silog2 --- src/libFLAC/bitmath.c | 24 ++++++++++++++++++++++++ src/libFLAC/include/private/bitmath.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/libFLAC/bitmath.c b/src/libFLAC/bitmath.c index 4543ccb..77cde39 100644 --- a/src/libFLAC/bitmath.c +++ b/src/libFLAC/bitmath.c @@ -98,3 +98,27 @@ unsigned FLAC__bitmath_silog2(int v) } } } + +unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v) +{ + while(1) { + if(v == 0) { + return 0; + } + else if(v > 0) { + unsigned l = 0; + while(v) { + l++; + v >>= 1; + } + return l+1; + } + else if(v == -1) { + return 2; + } + else { + v++; + v = -v; + } + } +} diff --git a/src/libFLAC/include/private/bitmath.h b/src/libFLAC/include/private/bitmath.h index ccc78bd..2f1e606 100644 --- a/src/libFLAC/include/private/bitmath.h +++ b/src/libFLAC/include/private/bitmath.h @@ -24,5 +24,6 @@ unsigned FLAC__bitmath_ilog2(unsigned v); unsigned FLAC__bitmath_silog2(int v); +unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v); #endif -- 2.7.4