From patchwork Sat Dec 2 17:46:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew D'Addesio X-Patchwork-Id: 6512 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2572144jah; Sat, 2 Dec 2017 09:52:48 -0800 (PST) X-Google-Smtp-Source: AGs4zMbfHFGw0gyXCSvdEaYeHU9TtmgjTpNgGtGaC9f7gnvzRRUoPyqiBiy5S/lFIihvc3c1JgEG X-Received: by 10.223.196.247 with SMTP id o52mr8290705wrf.119.1512237168351; Sat, 02 Dec 2017 09:52:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512237168; cv=none; d=google.com; s=arc-20160816; b=LFo6sIaoo1LSE6ehSPevYpuFKmGxPs4OvXisb9qiggI7gS9DdxRSLneLazd2wiUZT6 lNEwbxHUxoVVAULKkBBSXxwpi2seVoZn6DfsyOwPqH9nOgT3hBxbcMfg7iD3Lx7DuwQ2 sgAkTSjLVU4pdI5qSQy1p+nyyBaoRaF2ZbFh4vPxSucDd8GpxVgY3ljStf3JySI+It+Q Fcg0dT9oIu6QJsacKtTwkQA4lOdg+oKBRR5rLCiZpcvdRLxZA1NmXYbHMNS39ssm0bbW nB7F8imFWVg+1lLe9dnj4ClX3ecbcgylH66L3GDc2tGMvbzbQcN8IpNFnmPMhcwt9ttc X0Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=cjWDy7/jMY3uvtxLn8bufXoTxeWby+Hc78b8PFnM6Uk=; b=iETpRgTpIeXsYVrw3nMRO9c9lw7thCfMn2lyGS7gpJFiGpGD90O75rMPX61RWj7kwg 46JQmgq7x4yWwC+7WoOLkLXlB8EoU90ynT8JbuoT5rYoHzQ+IZMi41zQRLQzcXf26Og6 XFFJ+LgPRPwqjEKOsoXP1pyuWU3Qkwo9hfgLAWEbJUJI8tq6C2qxOFrUbVxCaAaxA3bj 4RTINZyNIqBJSyVll9cpcfIGBzFunHZOrx/ByjCoeWyhjP22WpG1WCTRsXLGZVGWxhJd IpbqoerNjI9uizvSur4GRwNQTZRSSpF3yhJUnHJ7aq3GGSk1qgsgAEM7FoaDy7yKKH9I 4Aig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=Uqv16cN9; 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 sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 21si2496614wmk.140.2017.12.02.09.52.47; Sat, 02 Dec 2017 09:52:48 -0800 (PST) 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 header.s=20161025 header.b=Uqv16cN9; 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 sp=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 204D168A576; Sat, 2 Dec 2017 19:52:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f67.google.com (mail-oi0-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 27F1468A545 for ; Sat, 2 Dec 2017 19:52:37 +0200 (EET) Received: by mail-oi0-f67.google.com with SMTP id s9so9195386oie.5 for ; Sat, 02 Dec 2017 09:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=dt4jVgxHKAAb0KWv/91DlLIQfsmZzaqkAnjKk00j2rA=; b=Uqv16cN9VnTckj2nn7qj2wtcWbnGI8Cw4ojgkn4F+rflxsF+7TgY1+5Pq0b6vcKzWr c8YcjzkN1AnF+qJt7+mop5dk1pivuGwXp/5y7uE0fdwPeQbD3G0xf/mn7tzxTGUi1ZgN MVslldC3Vrn/aGoPqrB67d+nbqo96onB+anMeuxvJDaiCJTFFWrBAYcuAuk4ub/aFFNC V2g92bIqUCTWjOC8Rpstq6atICcW2qLetdMHCPQPAr2SVBPFxorpOu7OqFHki2JzuuXY v9grU7lbdTkqZe9tjsdq3p8xGeG4Aq7fMeaRJ2TbMcz+WxoHW2Pb8u9xZzRJMdbuei1M PrIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dt4jVgxHKAAb0KWv/91DlLIQfsmZzaqkAnjKk00j2rA=; b=R0x0+YTM4Sg5Bwh6raOqUsEqzJV/Y+VrytiLBRnquUQnpL84eRZtF0W8Sh3gsAIp0x /EbGIYArMKyRlEB1m1RQA7wpzODqNUnnHSIGH2noRzpnu0vIvMi3kAw7rVkLNoWaMP6Q DrmCBv+K/L4zWHmrozHsyqQKwDR0qYwykJBrb6Ccurd6OU8MDQ2ltE5P50ONrVdf6Er9 2fzw4lJX4X95HBWa6x5U92yxKSdJbRAZoZtlzUaAKDhlNhrvV39L4GzfNHdTce6Z1tkE KN+leF4KLPCoI9d6NkXf3wvOtyRxTPR2cdwFBeFZtXFSRE53aBo+ozElrOxuLzRU/Gna o9tQ== X-Gm-Message-State: AJaThX7KMcky/QKmwpL8uKlakKn2T3IKCJpHGw2zIflr0CazobGgC94E PQLq0ahPmFiQaIsPNnw8tSY6hg== X-Received: by 10.202.72.74 with SMTP id v71mr10664130oia.34.1512236846506; Sat, 02 Dec 2017 09:47:26 -0800 (PST) Received: from localhost.localdomain ([2605:6000:1019:4a8:80a0:1945:efcc:4de5]) by smtp.gmail.com with ESMTPSA id n40sm4185398otb.54.2017.12.02.09.47.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Dec 2017 09:47:26 -0800 (PST) From: Andrew D'Addesio To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 Dec 2017 11:46:56 -0600 Message-Id: <20171202174659.1064-1-modchipv12@gmail.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [FFmpeg-devel] [PATCH 1/4] libavutil: Add saturating subtraction functions 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: Andrew D'Addesio MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add av_sat_sub32 and av_sat_dsub32 as the subtraction analogues to av_sat_add32/av_sat_dadd32. Also clarify the formulas for dadd32/dsub32. Signed-off-by: Andrew D'Addesio --- libavutil/arm/intmath.h | 16 ++++++++++++++++ libavutil/common.h | 32 +++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libavutil/arm/intmath.h b/libavutil/arm/intmath.h index 65e42c5..5311a7d 100644 --- a/libavutil/arm/intmath.h +++ b/libavutil/arm/intmath.h @@ -94,6 +94,22 @@ static av_always_inline int av_sat_dadd32_arm(int a, int b) return r; } +#define av_sat_sub32 av_sat_sub32_arm +static av_always_inline int av_sat_sub32_arm(int a, int b) +{ + int r; + __asm__ ("qsub %0, %1, %2" : "=r"(r) : "r"(a), "r"(b)); + return r; +} + +#define av_sat_dsub32 av_sat_dsub32_arm +static av_always_inline int av_sat_dsub32_arm(int a, int b) +{ + int r; + __asm__ ("qdsub %0, %1, %2" : "=r"(r) : "r"(a), "r"(b)); + return r; +} + #endif /* HAVE_ARMV6_INLINE */ #if HAVE_ASM_MOD_Q diff --git a/libavutil/common.h b/libavutil/common.h index 8142b31..5e03828 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -260,13 +260,37 @@ static av_always_inline int av_sat_add32_c(int a, int b) * * @param a first value * @param b value doubled and added to a - * @return sum with signed saturation + * @return sum sat(a + sat(2*b)) with signed saturation */ static av_always_inline int av_sat_dadd32_c(int a, int b) { return av_sat_add32(a, av_sat_add32(b, b)); } +/** + * Subtract two signed 32-bit values with saturation. + * + * @param a one value + * @param b another value + * @return difference with signed saturation + */ +static av_always_inline int av_sat_sub32_c(int a, int b) +{ + return av_clipl_int32((int64_t)a - b); +} + +/** + * Subtract a doubled value from another value with saturation at both stages. + * + * @param a first value + * @param b value doubled and subtracted from a + * @return difference sat(a - sat(2*b)) with signed saturation + */ +static av_always_inline int av_sat_dsub32_c(int a, int b) +{ + return av_sat_sub32(a, av_sat_add32(b, b)); +} + /** * Clip a float value into the amin-amax range. * @param a value to clip @@ -513,6 +537,12 @@ static av_always_inline av_const int av_parity_c(uint32_t v) #ifndef av_sat_dadd32 # define av_sat_dadd32 av_sat_dadd32_c #endif +#ifndef av_sat_sub32 +# define av_sat_sub32 av_sat_sub32_c +#endif +#ifndef av_sat_dsub32 +# define av_sat_dsub32 av_sat_dsub32_c +#endif #ifndef av_clipf # define av_clipf av_clipf_c #endif