From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 303F047002 for ; Wed, 25 Oct 2023 18:39:24 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 32B8968CAE3; Wed, 25 Oct 2023 21:39:22 +0300 (EEST) Received: from glom.nmugroup.com (unknown [193.183.80.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C939F68C987 for ; Wed, 25 Oct 2023 21:39:15 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by glom.nmugroup.com (Postfix) with ESMTP id 0E17B5429265 for ; Wed, 25 Oct 2023 20:39:15 +0200 (CEST) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) (Authenticated sender: git01) by glom.nmugroup.com (Postfix) with ESMTPSA id C55FE5429257 for ; Wed, 25 Oct 2023 20:39:14 +0200 (CEST) Message-ID: From: Tomas =?ISO-8859-1?Q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Wed, 25 Oct 2023 20:39:13 +0200 In-Reply-To: References: User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] avcodec/mlp*: improvements X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: > if (c) { > e[0] = 1 << 14; > e[1] = 0 << 14; > e[2] = v[1]; > e[3] = v[0]; > } else { > e[0] = v[0]; > e[1] = v[1]; > e[2] = 0 << 14; > e[3] = 1 << 14; > } > > if (invert2x2(e, d)) { > sum = UINT64_MAX; > goto next; > } > You can make use of the properties of e to simplify calculating the inverse. The determinant is always v[0]<<14, so you can just do if (!v[0]) continue; and skip the determinant check altogether. > if (d[i] != av_clip_intp2(d[i], 15)) { d[i] < INT16_MIN || d[i] > INT16_MAX is more clear and probably faster > + lt = ((lm * e[0]) >> 14) + ((rm * e[1]) >> 14); > + rt = ((lm * e[2]) >> 14) + ((rm * e[3]) >> 14); Result is implementation-defined. Use division by (1<<14). Also add then divide. The intermediate result is 49 bits so fits easily in 64 bits. You could also simplify this calculation by again making use of the properties of e. > if (c) > v += FFABS(rt); > else > v += FFABS(lt); > sum += v; > if (sum > best_sum) > goto next; Seems like this reduces to solving a linear program. > if ((((lt * d[0]) >> 14) + ((rt * d[1]) >> 14)) > != lm) { > sum = UINT64_MAX; > goto next; > } > > if ((((lt * d[2]) >> 14) + ((rt * d[3]) >> 14)) > != rm) { > sum = UINT64_MAX; > goto next; > } Looks like a massive hack. I'd prefer to formally verify that the arithmetic works out. Also again you can make use of the properties of e, or inv(e) as it were. /Tomas _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".