mss12: avoid unnecessary division in arith*_get_bit()
authorAlberto Delmás <adelmas@gmail.com>
Mon, 3 Sep 2012 15:32:01 +0000 (17:32 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 6 Sep 2012 18:44:04 +0000 (20:44 +0200)
That division can be replaced with a comparison:
((c->value - c->low) << 1) + 1 >= range

By expanding 'range' definition and simplifying this inequation we obtain
the final expression.

Suggested by Michael Niedermayer <michaelni@gmx.at>

Signed-off-by: Kostya Shishkov <kostya.shishkov@gmail.com>
libavcodec/mss12.h

index 678a0c0..f5d0366 100644 (file)
@@ -103,7 +103,7 @@ av_cold int ff_mss12_decode_end(MSS12Context *ctx);
 static int arith ## VERSION ## _get_bit(ArithCoder *c)                  \
 {                                                                       \
     int range = c->high - c->low + 1;                                   \
-    int bit   = (((c->value - c->low) << 1) + 1) / range;               \
+    int bit   = 2 * c->value - c->low >= c->high;                       \
                                                                         \
     if (bit)                                                            \
         c->low += range >> 1;                                           \