aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorRonald S. Bultje <rsbultje@gmail.com>2016-10-14 13:01:27 -0400
committerMichael Niedermayer <michael@niedermayer.cc>2016-12-04 20:25:15 +0100
commit642cd5de4de6c94877601078fad5474a45d36630 (patch)
tree88466593c2199b739ab0e2ca8925c21d09a3e1b6 /libavcodec
parentd54aa2de176119f49d3491be8b8fe7ad7848577f (diff)
downloadffmpeg-642cd5de4de6c94877601078fad5474a45d36630.tar.gz
vp9: change order of operations in adapt_prob().
This is intended to workaround bug "665 Integer Divide Instruction May Cause Unpredictable Behavior" on some early AMD CPUs, which causes a div-by-zero in this codepath, such as reported in Mozilla bug #1293996. Note that this isn't guaranteed to fix the bug, since a compiler is free to reorder instructions that don't depend on each other. However, it appears to fix the bug in Firefox, and a similar patch was applied to libvpx also (see Chrome bug #599899). (cherry picked from commit be885da3427c5d9a6fa68229d16318afffe67193) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/vp9.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 5d8ad12b21..c9d76907a1 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -3703,11 +3703,10 @@ static av_always_inline void adapt_prob(uint8_t *p, unsigned ct0, unsigned ct1,
if (!ct)
return;
+ update_factor = FASTDIV(update_factor * FFMIN(ct, max_count), max_count);
p1 = *p;
- p2 = ((ct0 << 8) + (ct >> 1)) / ct;
+ p2 = ((((int64_t) ct0) << 8) + (ct >> 1)) / ct;
p2 = av_clip(p2, 1, 255);
- ct = FFMIN(ct, max_count);
- update_factor = FASTDIV(update_factor * ct, max_count);
// (p1 * (256 - update_factor) + p2 * update_factor + 128) >> 8
*p = p1 + (((p2 - p1) * update_factor + 128) >> 8);