From patchwork Mon Nov 15 06:22:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Reid X-Patchwork-Id: 31422 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp5399277iob; Sun, 14 Nov 2021 22:22:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzJbS3ULwpAN2Q4wW5TJUDqzwG1LFt1MyzhUZNL5UTUHCa+36PFvMYOn0CRwRmw4J/8qGg X-Received: by 2002:a17:906:1290:: with SMTP id k16mr46562582ejb.566.1636957367359; Sun, 14 Nov 2021 22:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636957367; cv=none; d=google.com; s=arc-20160816; b=z8SZpuGNynlbmXNzdvtiANd4z7AFos378OaNBLM09ep/cbQ5WzOGbITsrBG/6/YZpp NJfyxyctRmImfWjebeQiALOa9Ltszi3PzhOoOo3Q2t9j43JZ99dyZxZq4tA8mDJTJiyy 1BPnk0Grypcey6hz2eDqtzRmhEFNzdrfqn/OyCxR02giRMHXB0mUYiE+Y/OR+3pZ2VAe zpMMLElgRT2uM877vDQK/bDJpxmfX2oibjUIuhmyC9wDqr9ZatQxvHqjEj1Bs3tjMizW 68ndsCm/MZjJoXLrjXOCg05ddfqXdkkrQ4uL/mQ6TRi/6i/eyNnpIkcY8NFGr4DP0t1i msZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=9zRpqnQCZ+FSA7bvmHAnlrpt5RtUiMitwS0Nc1rB8eo=; b=zuQ3cWkXgCzDMH83ZgVWr3E1700ydSoaXwz4NMju+Vjv84r+IKLaWLcwSQG+H5xSFh mxeA+JTZwQlTlQr+fcXU/ikxJ60rzDyLjY7uQw0mcBNH9n9xGOUsQnHQSV3HANHJLOCG Z9EOQALSYK0h1XbXthILmIpgRVi+N/yWuYTK9LdfupCNeyyNm1hnKApevS46Wd0wFuEu 1CucZRv8U7LcSjmdBL/92WTL2dMY05G4v9WXNgBjGENSvRwbVY4bBt4aUvu0wp0LDRwt aUvYJmrDmeQl8me3vA6eGjHj+tm5eL4a+0sW/Mq9DMR1QndP7VilMXBk9eaJccMBpGIF 3gJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=qQ4+hGyZ; 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=QUARANTINE 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 s20si21294903ejn.774.2021.11.14.22.22.46; Sun, 14 Nov 2021 22:22:47 -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=20210112 header.b=qQ4+hGyZ; 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=QUARANTINE 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 D1CF368A7ED; Mon, 15 Nov 2021 08:22:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 55E4968819D for ; Mon, 15 Nov 2021 08:22:36 +0200 (EET) Received: by mail-pj1-f44.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso13142635pjb.0 for ; Sun, 14 Nov 2021 22:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=00F5T0k7e20fbnkzBibmA/oKVCcBQtVb9X7xaRXtTdY=; b=qQ4+hGyZZWpIAkxLr0ZvViLQ3cgKmEZSaSbEtRZVPa1JgQzBPZeszCtARMpSgl3DVj +J2IawPEgIPhzhOawq1fNm8+iQB0srkViF76Mf3EOCwh4qXnQ6X4374RS+kr9hnqXv5f AoT7mSOnHVHhympQeeGjKFY1CgOYMOlqz2Ia7naEF1Y8sk7Et9P8lHTrcy9Z43zhPZ2g 1vfwGiuqK/PqYTm7Fswhuasvi0hDsR06j7sLKFDtDKrq/HKSn/gimCEwBpVM7ju1FzwX Gw9kSQ1Vk7jHuorGFV0CYbC06QmH0q433vHbxMutBzdmgdT/oe4S7gotN3kgh4EEiX4I +rJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=00F5T0k7e20fbnkzBibmA/oKVCcBQtVb9X7xaRXtTdY=; b=q3eAWu/OS3QCqR/7mahnO9rvokKvttpXqOEFxy/ezPr/umgnFrXn6EsbRSg5qMkZlq Xug8a5PPA9A6GUnlOUuXJRrJ2VraaXiL74Kv9BxN9HqNkw0G3+wNUHL67zh3mP+RIPnv 45SlG2J7f0SbFXxMO/Vyv+keJZDpz/etJmOM9bAwCs/802U4raGJzdIMRmZN2MKtXTj1 iQw1/CzhVP0RG2sddroOw0p/dPA+qDX0y36aZVsjcmyLN/H4Qer/WJ4o0i5mt8QMDKEq hFSL2Qpe/0qJsXnKr1KSLpP+9Sv61BqjKafzbvNgpIluheLph1UsJHom7FCQSROAYZpP TQQA== X-Gm-Message-State: AOAM531SXpTDE0YjoQz1ZiqW3bYRhoY76YjuJGbpgtdpl4oGE88W4OtK 3Crh3d7AfwgzZvIgcMB3KMKZRw+Fw5I= X-Received: by 2002:a17:903:22c4:b0:141:deda:a744 with SMTP id y4-20020a17090322c400b00141dedaa744mr33139586plg.25.1636957353857; Sun, 14 Nov 2021 22:22:33 -0800 (PST) Received: from localhost.localdomain (S0106bc4dfba470f3.vc.shawcable.net. [174.7.244.175]) by smtp.gmail.com with ESMTPSA id 9sm10904025pgq.57.2021.11.14.22.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 22:22:33 -0800 (PST) From: mindmark@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 14 Nov 2021 22:22:20 -0800 Message-Id: <20211115062221.1650-1-mindmark@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/2] libavutil/common: clip nan value to amin 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 Cc: Mark Reid Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: MdqMC8e7Nmee From: Mark Reid Changes av_clipf to return amin if a is nan. Before if a is nan av_clipf_c returned nan and av_clipf_sse would return amax. Now the both should behave the same. This works because nan > amin is false. The max(nan, amin) will be amin. --- libavutil/common.h | 12 ++++++------ libavutil/x86/intmath.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) -- 2.31.1.windows.1 diff --git a/libavutil/common.h b/libavutil/common.h index 3cc1f07566..9338bda7d5 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -379,6 +379,8 @@ static av_always_inline int64_t av_sat_sub64_c(int64_t a, int64_t b) { /** * Clip a float value into the amin-amax range. + * If a is nan or -inf amin will be returned. + * If a is +inf amax will be returned. * @param a value to clip * @param amin minimum value of the clip range * @param amax maximum value of the clip range @@ -389,13 +391,13 @@ static av_always_inline av_const float av_clipf_c(float a, float amin, float ama #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif - if (a < amin) return amin; - else if (a > amax) return amax; - else return a; + return FFMIN(FFMAX(a, amin), amax); } /** * Clip a double value into the amin-amax range. + * If a is nan or -inf amin will be returned. + * If a is +inf amax will be returned. * @param a value to clip * @param amin minimum value of the clip range * @param amax maximum value of the clip range @@ -406,9 +408,7 @@ static av_always_inline av_const double av_clipd_c(double a, double amin, double #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif - if (a < amin) return amin; - else if (a > amax) return amax; - else return a; + return FFMIN(FFMAX(a, amin), amax); } /** Compute ceil(log2(x)). diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h index 40743fd13e..1520c25ec9 100644 --- a/libavutil/x86/intmath.h +++ b/libavutil/x86/intmath.h @@ -110,8 +110,8 @@ static av_always_inline av_const double av_clipd_sse2(double a, double amin, dou #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif - __asm__ ("minsd %2, %0 \n\t" - "maxsd %1, %0 \n\t" + __asm__ ("maxsd %1, %0 \n\t" + "minsd %2, %0 \n\t" : "+&x"(a) : "xm"(amin), "xm"(amax)); return a; } @@ -126,8 +126,8 @@ static av_always_inline av_const float av_clipf_sse(float a, float amin, float a #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif - __asm__ ("minss %2, %0 \n\t" - "maxss %1, %0 \n\t" + __asm__ ("maxss %1, %0 \n\t" + "minss %2, %0 \n\t" : "+&x"(a) : "xm"(amin), "xm"(amax)); return a; }