From patchwork Sat Dec 2 17:36:24 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: 6507 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2564519jah; Sat, 2 Dec 2017 09:42:30 -0800 (PST) X-Google-Smtp-Source: AGs4zMYWmkHDsJy15I6fDbQRH71xxexiv+pphzAS/oPbp5SMlDfTVp13aNtjrGHtbu4mXFr3Svm3 X-Received: by 10.28.105.14 with SMTP id e14mr3515946wmc.74.1512236550546; Sat, 02 Dec 2017 09:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512236550; cv=none; d=google.com; s=arc-20160816; b=DqQjGfmsiuAjl+40rba/AoyZKafHZ5Lxy8qCPfKQFpiDbgIxKwDEA2Cl6rV57hkW9c cusAFg8SY+IDesUsvUr8/lOzT59k4OyVgQ0R2ngKFnCa1DF4YKDur2OeGF0M13Dys9Zu pyxxAxpQ9SMbL+HqxRMTDCKHGRPWh7/5mY8THdprsjH1rqUKxHzmZO2+BUNm8kDtWfqa T0pwBrvtx8qk0Gf/dilTvhaCfsCyZtIT9dBiXDnMYm4XhL32LRe1ApeMg5nuUx4OYB7G 4BYe/+uj7jgZlrlq1ueKxN6Yu55p87eB/PSvx9L887efPIIlFiqXIGXVYBsqF9phleGY OGqg== 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=a50hcU26MOj9R1Uzuvjb3oTiZYmX9oDqKXdN4lyt39riAB48dI5qDaw5A+sOLopZuu g19yRC9dX+vP9T4tp/1Cbh7opNWE+PO2VNOuG54Zx/3Ybtdj5SaIHV51K7kreElqvJpv IyCluh6xcDrmxY/Ovd6M63o5K2RDNGesKVmw4LGJvK7fI61FxTvGrlJzuZlZ+XLGGNAS 6xNHxdtYYZimacAFSFUwmQdtAh8U36IYErm12Q3RqEuilYGtFDqQQdJjP1Yb6D86I7fW wgVsLhpkF/TmUX2WbQ/fv1XLBZK6bxp1fWrAXDsT7MbYYqnMhJwNRbyxiDHVOggLHPuP Ix5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=SaWUY/05; 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 n96si5603919wrb.391.2017.12.02.09.42.30; Sat, 02 Dec 2017 09:42:30 -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=SaWUY/05; 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 EF88468A53F; Sat, 2 Dec 2017 19:42:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot0-f196.google.com (mail-ot0-f196.google.com [74.125.82.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 30D72680296 for ; Sat, 2 Dec 2017 19:42:18 +0200 (EET) Received: by mail-ot0-f196.google.com with SMTP id y10so11573051otg.10 for ; Sat, 02 Dec 2017 09:42:22 -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=SaWUY/056g3PtrWuoyHd5J9J95yw/EP6PjCsTyDscScNwzngkj8gpYOHcZ8Yu5kSx8 jJrzA2/JQy7UaaUNz+s+/IN9WtfyYZP8JWB1cjJ0DVRJY99LVtvWq9bWUbaWfIc8hoi2 pBcjpa1TFXGrzRy9nsZoDN3r+KgZCVVWBmqhnISmuDCORraXk3QtagnSuO6ajNNQBlhz rJJ7N6HnwYrMyZi60Dm1vKh05gkkkzMzYIqal6+MAkc6lrBXO6lm9KcGGhc3rbA00BX1 smqk15GMTsWxIZMeCg9sHfWAz3x+RIuBS8Bn3d7266B6vyP0TsdFmyDraOoaxXLiTeoI yYKw== 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=gdIzHLZgSS/RU+hTflVw93qZkROxEw3Nq+hHQGAZAqeavvv2ecu2LAAP2J09g7PNYe KF02u09x7yE9c+K/ldkKhqE1FvzTdPtI6n0P4a81EsJ+7yQ7oalTMLt13Q2U3gHdCeUE U0Gd7TRirxIPcGRoxgSs/cPaeunsdIHK/CNw7YUHoz78L5Ar6IGDY7cLtkhf6A8fTnlV oIG2hdvTnRGhGngYiDa/RCJK9u0rZyRnem6xuFsEf5sEHwpvcJSFKYDPBtcz5hs2dj96 QdOfrXZTmcEXPP1uIlCq4ZgQYBFGOZOY+AUxXnvgwJUrsXUCsvI29kljoCP/oOEccyWP HnGQ== X-Gm-Message-State: AJaThX5tOZEBuZeE5VyydpbkRQh43d+OffP621Jsog5iIM9lz9nLm5Iy Ny4xkdNMKHdCx2L7fRAQ6F5ZHg== X-Received: by 10.157.73.142 with SMTP id g14mr12707052otf.56.1512236214551; Sat, 02 Dec 2017 09:36:54 -0800 (PST) Received: from localhost.localdomain ([2605:6000:1019:4a8:80a0:1945:efcc:4de5]) by smtp.gmail.com with ESMTPSA id s101sm4180379ota.17.2017.12.02.09.36.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Dec 2017 09:36:54 -0800 (PST) From: Andrew D'Addesio To: ffmpeg-devel@ffmpeg.org Date: Sat, 2 Dec 2017 11:36:24 -0600 Message-Id: <20171202173627.5292-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