[FFmpeg-cvslog] vorbisdec: ensure FASTDIV denominator is never 1

Luca Barbato git at videolan.org
Sat Sep 15 10:48:40 CEST 2012


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Thu Sep 13 19:45:21 2012 +0200| [714508bcb91057868a96588b9fba4d29c6c4fc77] | committer: Luca Barbato

vorbisdec: ensure FASTDIV denominator is never 1

In both usages of FASTDIV the denominator might be 1.

Using a branch could make the function slower than using a normal
division.

Both denominator and numerator can be multiplied by 2 safely and
using shifts is faster than using a branch.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=714508bcb91057868a96588b9fba4d29c6c4fc77
---

 libavcodec/vorbisdec.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index f11e2f5..f5a541a 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1354,8 +1354,7 @@ static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
                         if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) {
                             unsigned coffs;
                             unsigned dim  = vc->codebooks[vqbook].dimensions;
-                            unsigned step = dim == 1 ? vr->partition_size
-                                                     : FASTDIV(vr->partition_size, dim);
+                            unsigned step = FASTDIV(vr->partition_size << 1, dim << 1);
                             vorbis_codebook codebook = vc->codebooks[vqbook];
 
                             if (vr_type == 0) {
@@ -1409,7 +1408,7 @@ static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
                                 }
 
                             } else if (vr_type == 2) {
-                                unsigned voffs_div = FASTDIV(voffset, ch);
+                                unsigned voffs_div = FASTDIV(voffset << 1, ch <<1);
                                 unsigned voffs_mod = voffset - voffs_div * ch;
 
                                 for (k = 0; k < step; ++k) {



More information about the ffmpeg-cvslog mailing list