From patchwork Fri Oct 14 17:01:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ronald S. Bultje" X-Patchwork-Id: 1004 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp15298vsd; Fri, 14 Oct 2016 10:01:50 -0700 (PDT) X-Received: by 10.194.94.39 with SMTP id cz7mr2844161wjb.141.1476464510391; Fri, 14 Oct 2016 10:01:50 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id pl9si25991367wjb.212.2016.10.14.10.01.48; Fri, 14 Oct 2016 10:01:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2BA0A6891F4; Fri, 14 Oct 2016 20:01:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C29BF680C5C for ; Fri, 14 Oct 2016 20:01:39 +0300 (EEST) Received: by mail-pf0-f195.google.com with SMTP id s8so7581685pfj.2 for ; Fri, 14 Oct 2016 10:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=1hvJlvnE+WGecMc38J9tR7RSuBjaaK8rulsNAOpAxvI=; b=po2OlkUZ2+fo9tyivnayMo33cCWVFefQ3UZE6S29hP9Nt0SkcH82EtQWIJn/SBggvU rBLI8bP01H60SzITxAx7hSQEAB+0cikSWHAG862myyHNyIakB7Sky++dGL3RASkZheSR UsN8Ej0F7av5t9LqlGVbKgM7ki7+jSY29kTx6HbuymKvX9wk8vig/EHtVYbld8unmd/P ANScETsSALa7GeWAQOQ/OeX1mxN0f3u3MnqBE+uGhyNwTXqmUtUbtSUJCsxj+U96IUpK Cp1zCV6UUb4Wyj1jFEU/l0rc5DzkT3DocneXzSO6/R/fMz2IRooHwHc+uq9u92gmIuah ZDnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1hvJlvnE+WGecMc38J9tR7RSuBjaaK8rulsNAOpAxvI=; b=KniBhv5uMdLjO6Ja8tY0gi38yB3YXb+Rj594GvOTTVdRFxVJ+DMzCyND8J80qVcB1y P3qu2toNEHgfAetl/YJrRzxhbdpV/77aQ6cJzaWo9r8GrhnpbID3N84s9PT+Rcte9wtX nlVS0WCI+1Bj7ZwPOq633k6ii13gTRHd+gpQkOpH+u6W1tke+9T3Ln8UN95Yat0RdrXE XtGB8UTRow8wjaT/ZCQXx8TGuCOWcCcHX0yfF8n+qm7be7+0e0dGNbaHc4jZur2pICqF SI4Xj2MyE8T5XN/NhFb1ojPoHqVXd4Pm40grSjCw1Rb/D71OaUFLtoiDCbEY5sbk2UaW S7Ew== X-Gm-Message-State: AA6/9RlnN6DybtL2gWU/xFRp6OIlhEcvXJxH4Sz5TBfL6sZBvwxAMjtg1sLjc1HPLdmLyw== X-Received: by 10.98.223.145 with SMTP id d17mr19529628pfl.82.1476464499298; Fri, 14 Oct 2016 10:01:39 -0700 (PDT) Received: from Macintosh-7.local.com ([157.130.212.6]) by smtp.gmail.com with ESMTPSA id t29sm28796759pfj.95.2016.10.14.10.01.38 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 14 Oct 2016 10:01:38 -0700 (PDT) From: "Ronald S. Bultje" To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Oct 2016 13:01:37 -0400 Message-Id: <1476464497-82840-1-git-send-email-rsbultje@gmail.com> X-Mailer: git-send-email 2.8.1 Subject: [FFmpeg-devel] [PATCH] vp9: change order of operations in adapt_prob(). X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "Ronald S. Bultje" MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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). --- libavcodec/vp9.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index cb2a4a2..3b72149 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -3705,11 +3705,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);