From patchwork Thu Jun 1 23:10:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3785 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp1023973vsk; Thu, 1 Jun 2017 16:21:40 -0700 (PDT) X-Received: by 10.28.217.1 with SMTP id q1mr947107wmg.23.1496359300689; Thu, 01 Jun 2017 16:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496359300; cv=none; d=google.com; s=arc-20160816; b=ac8AooOGhb2uB3jH+UhLnE3VpUbO0fmNZPqxNvajOi36SVTXAe88bLm/yoEiscAPSf H7VifncuquigFrCtMe3ejfA13f3i3iJhdDJwG6+/AhKlmX+R+cv/AYL+6g2oDZluo4Ic EfiUibNH3Wscypn/qkpn674AUp3z1bKbuCUQ8fZd4/nPvFyzUiEmpmgJQL2063FL1+UU gDhPVE3ZIUFn9hGMJ6ibuf7zoLzGUIR4DjDi69XYlsmcRcjcLyJ9mFKQzy50voiPC63Y e3nbN2MUEIVt51CqzA17APkR3P0J1EIc2542+hWkmputqaWoF0+4GqPQrW+e/ilE7ehy TGsQ== 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:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=CYFRPZBgDlNasS0odZWRqB9e7/0qdTBzKKQw3stgdFU=; b=Dt0OBvPF9dzt0DYqVx6DdKjzMmdbSM1pMgFQyaC6BQV8CRl6t2Y8JFuEOf9iE2Cr90 eDTAM6Hrv1jURYISF3AfnzvIPTtHlC1JgHPhwa4nWKe6IKcsjFIobY/11s8jOWvXTaOZ mg7fVOLqafE3tWxENdfvkkInbtsNTc4/t6K55B8woaIyCN/Tl3Z2eeqe9quqKahupoVJ P5zlizsMxp/HJsqeR7/5ia37Tn1u53iwqOMfycOokxDt2ZgRmRrkvBkKtVi7uAweUfaT pyQnVS9xGs9/x3VZnicI/V9pIGdMhwYdgHM7g3fnv/6barlnHKyWqul8qMZ3KauGg3/7 XNVQ== ARC-Authentication-Results: i=1; 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 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 c3si9778168wra.29.2017.06.01.16.21.40; Thu, 01 Jun 2017 16:21:40 -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 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 C70E8689AC7; Fri, 2 Jun 2017 02:21:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 29F64689A7F for ; Fri, 2 Jun 2017 02:21:26 +0300 (EEST) Received: by mail-qk0-f193.google.com with SMTP id y201so3282537qka.3 for ; Thu, 01 Jun 2017 16:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=WCNezjPLNztVynnnkww2lHC822vJTIdN+ET1p/81yjA=; b=ga1nilvrCy7ozaTt/ZTO0kkK1A+VweSl6fBF87vr6nN85KUa3B1vdS4+VEoZAsk3uM erMCbe35fdNHXWjzD46Vn6g9OlWrOmM0b+bczRbJLhK91B95El8K9fivyK+li8UBH6aM yBIXXj37C00iY03/i0LT16OxaOC22Dyx1rP7cA6RemXEMtzugH6csgz5LioIOcPXNk64 6/+uY1MU9R+gsAH44TkPWiG0nWwcpfJY6o3dzZq8gAandbp0vOH3uTCTehPc+XzvM8+7 mICoNbocjMaHAyCAr2Z/CmlPvoMwm9eTN8q4o4VYYJmTdflpEuC2v5pmGNIS7v/amBMk ASSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=WCNezjPLNztVynnnkww2lHC822vJTIdN+ET1p/81yjA=; b=kO49DIrkdxlc+a3XWO/hqOwbZPqF92j9co7Zb7pD8WdE9ct76RPuup2nGEHQEqs669 q7Ys/8N1FvYOtryzhaF3+TxpnIb9IZJMn0AXQLPuQYYuq9Fkh99Lv4kAU1lO4AtTHxj4 UFZ2ssAPmyvcPFKgaZZ/pYgle+0zbv0iblrwUse+dUhUVrQH/VWK86EGl2m0XEsFtaal 0VwlnzX44uYdOm3B/yQravDFke4NE9jno6B9EVQVs4yvpkWNuxmGCgIhOIePY9cWR1RB CU5YLGSz2UJALFnSJGUITpD2CXGhbJ9d20FiroZ+lIwo99r0mxho9Ys4ftSCzKoS7R42 5K4Q== X-Gm-Message-State: AKS2vOxkfR5IgH7nA0TET006ViKZR7sGqXjaDDeLzwPIuBCquTw9zNLF jh+SJiqKW2dvx2ig X-Received: by 10.55.71.150 with SMTP id u144mr5024192qka.233.1496358811430; Thu, 01 Jun 2017 16:13:31 -0700 (PDT) Received: from localhost.localdomain ([181.231.116.134]) by smtp.gmail.com with ESMTPSA id d46sm14066341qte.21.2017.06.01.16.13.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Jun 2017 16:13:30 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Jun 2017 20:10:50 -0300 Message-Id: <20170601231051.6880-2-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170601231051.6880-1-jamrial@gmail.com> References: <20170601231051.6880-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/3] checkasm: add float_dsp tests 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Ported from libavutil/tests/float_dsp.c Signed-off-by: James Almer --- tests/checkasm/Makefile | 1 + tests/checkasm/checkasm.c | 20 +++ tests/checkasm/checkasm.h | 4 + tests/checkasm/float_dsp.c | 307 +++++++++++++++++++++++++++++++++++++++++++++ tests/fate/checkasm.mak | 1 + 5 files changed, 333 insertions(+) create mode 100644 tests/checkasm/float_dsp.c diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index cbe614b1fd..9cff0d538a 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -30,6 +30,7 @@ AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes) AVUTILOBJS += fixed_dsp.o +AVUTILOBJS += float_dsp.o CHECKASMOBJS-$(CONFIG_AVUTIL) += $(AVUTILOBJS) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 0cb4ed199a..0b86627cc9 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -131,6 +131,7 @@ static const struct { #endif #if CONFIG_AVUTIL { "fixed_dsp", checkasm_check_fixed_dsp }, + { "float_dsp", checkasm_check_float_dsp }, #endif { NULL } }; @@ -285,6 +286,25 @@ int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps, return 1; } +int double_near_abs_eps(double a, double b, double eps) +{ + double abs_diff = fabs(a - b); + + return abs_diff < eps; +} + +int double_near_abs_eps_array(const double *a, const double *b, double eps, + unsigned len) +{ + unsigned i; + + for (i = 0; i < len; i++) { + if (!double_near_abs_eps(a[i], b[i], eps)) + return 0; + } + return 1; +} + /* Print colored text to stderr if the terminal supports it */ static void color_printf(int color, const char *fmt, ...) { diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 03a1eda73e..4a4099dcb4 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -39,6 +39,7 @@ void checkasm_check_bswapdsp(void); void checkasm_check_colorspace(void); void checkasm_check_fixed_dsp(void); void checkasm_check_flacdsp(void); +void checkasm_check_float_dsp(void); void checkasm_check_fmtconvert(void); void checkasm_check_h264dsp(void); void checkasm_check_h264pred(void); @@ -70,6 +71,9 @@ int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len); int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps, unsigned max_ulp, unsigned len); +int double_near_abs_eps(double a, double b, double eps); +int double_near_abs_eps_array(const double *a, const double *b, double eps, + unsigned len); extern AVLFG checkasm_lfg; #define rnd() av_lfg_get(&checkasm_lfg) diff --git a/tests/checkasm/float_dsp.c b/tests/checkasm/float_dsp.c new file mode 100644 index 0000000000..3a448df44f --- /dev/null +++ b/tests/checkasm/float_dsp.c @@ -0,0 +1,307 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include +#include + +#include "libavutil/float_dsp.h" +#include "libavutil/internal.h" +#include "checkasm.h" + +#define LEN 256 + +#define randomize_buffer(buf) \ +do { \ + int i; \ + double bmg[2], stddev = 10.0, mean = 0.0; \ + \ + for (i = 0; i < LEN; i += 2) { \ + av_bmg_get(&checkasm_lfg, bmg); \ + buf[i] = bmg[0] * stddev + mean; \ + buf[i + 1] = bmg[1] * stddev + mean; \ + } \ +} while(0); + +static void test_vector_fmul(const float *src0, const float *src1) +{ + LOCAL_ALIGNED_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src0, const float *src1, + int len); + + call_ref(cdst, src0, src1, LEN); + call_new(odst, src0, src1, LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1, LEN); +} + +#define ARBITRARY_FMUL_ADD_CONST 0.005 +static void test_vector_fmul_add(const float *src0, const float *src1, const float *src2) +{ + LOCAL_ALIGNED_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src0, const float *src1, + const float *src2, int len); + + call_ref(cdst, src0, src1, src2, LEN); + call_new(odst, src0, src1, src2, LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMUL_ADD_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1, src2, LEN); +} + +static void test_vector_fmul_scalar(const float *src0, const float *src1) +{ + LOCAL_ALIGNED_16(float, cdst, [LEN]); + LOCAL_ALIGNED_16(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src, float mul, int len); + + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1[0], LEN); +} + +#define ARBITRARY_FMUL_WINDOW_CONST 0.008 +static void test_vector_fmul_window(const float *src0, const float *src1, const float *win) +{ + LOCAL_ALIGNED_16(float, cdst, [LEN]); + LOCAL_ALIGNED_16(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src0, const float *src1, + const float *win, int len); + + call_ref(cdst, src0, src1, win, LEN / 2); + call_new(odst, src0, src1, win, LEN / 2); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMUL_WINDOW_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1, win, LEN / 2); +} + +#define ARBITRARY_FMAC_SCALAR_CONST 0.005 +static void test_vector_fmac_scalar(const float *src0, const float *src1, const float *src2) +{ + LOCAL_ALIGNED_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src, float mul, int len); + + memcpy(cdst, src2, LEN * sizeof(*src2)); + memcpy(odst, src2, LEN * sizeof(*src2)); + + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMAC_SCALAR_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + memcpy(odst, src2, LEN * sizeof(*src2)); + bench_new(odst, src0, src1[0], LEN); +} + +static void test_vector_dmul_scalar(const double *src0, const double *src1) +{ + LOCAL_ALIGNED_32(double, cdst, [LEN]); + LOCAL_ALIGNED_32(double, odst, [LEN]); + int i; + + declare_func(void, double *dst, const double *src, double mul, int len); + + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!double_near_abs_eps(cdst[i], odst[i], DBL_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", i, + cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1[0], LEN); +} + +#define ARBITRARY_DMAC_SCALAR_CONST 0.005 +static void test_vector_dmac_scalar(const double *src0, const double *src1, const double *src2) +{ + LOCAL_ALIGNED_32(double, cdst, [LEN]); + LOCAL_ALIGNED_32(double, odst, [LEN]); + int i; + + declare_func(void, double *dst, const double *src, double mul, int len); + + memcpy(cdst, src2, LEN * sizeof(*src2)); + memcpy(odst, src2, LEN * sizeof(*src2)); + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!double_near_abs_eps(cdst[i], odst[i], ARBITRARY_DMAC_SCALAR_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + memcpy(odst, src2, LEN * sizeof(*src2)); + bench_new(odst, src0, src1[0], LEN); +} + +static void test_butterflies_float(const float *src0, const float *src1) +{ + LOCAL_ALIGNED_16(float, cdst, [LEN]); + LOCAL_ALIGNED_16(float, odst, [LEN]); + LOCAL_ALIGNED_16(float, cdst1, [LEN]); + LOCAL_ALIGNED_16(float, odst1, [LEN]); + int i; + + declare_func(void, float *av_restrict src0, float *av_restrict src1, + int len); + + memcpy(cdst, src0, LEN * sizeof(*src0)); + memcpy(cdst1, src1, LEN * sizeof(*src1)); + memcpy(odst, src0, LEN * sizeof(*src0)); + memcpy(odst1, src1, LEN * sizeof(*src1)); + + call_ref(cdst, cdst1, LEN); + call_new(odst, odst1, LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + memcpy(odst, src0, LEN * sizeof(*src0)); + memcpy(odst1, src1, LEN * sizeof(*src1)); + bench_new(odst, odst1, LEN); +} + +#define ARBITRARY_SCALARPRODUCT_CONST 0.2 +static void test_scalarproduct_float(const float *src0, const float *src1) +{ + float cprod, oprod; + + declare_func_float(float, const float *src0, const float *src1, int len); + + cprod = call_ref(src0, src1, LEN); + oprod = call_new(src0, src1, LEN); + if (!float_near_abs_eps(cprod, oprod, ARBITRARY_SCALARPRODUCT_CONST)) { + fprintf(stderr, "%- .12f - %- .12f = % .12g\n", + cprod, oprod, cprod - oprod); + fail(); + } + bench_new(src0, src1, LEN); +} + +void checkasm_check_float_dsp(void) +{ + LOCAL_ALIGNED_32(float, src0, [LEN]); + LOCAL_ALIGNED_32(float, src1, [LEN]); + LOCAL_ALIGNED_32(float, src2, [LEN]); + LOCAL_ALIGNED_16(float, src3, [LEN]); + LOCAL_ALIGNED_16(float, src4, [LEN]); + LOCAL_ALIGNED_16(float, src5, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src0, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src1, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src2, [LEN]); + AVFloatDSPContext *fdsp = avpriv_float_dsp_alloc(1); + + if (!fdsp) { + fprintf(stderr, "floatdsp: Out of memory error\n"); + return; + } + + randomize_buffer(src0); + randomize_buffer(src1); + randomize_buffer(src2); + randomize_buffer(src3); + randomize_buffer(src4); + randomize_buffer(src5); + randomize_buffer(dbl_src0); + randomize_buffer(dbl_src1); + randomize_buffer(dbl_src2); + + if (check_func(fdsp->vector_fmul, "vector_fmul")) + test_vector_fmul(src0, src1); + if (check_func(fdsp->vector_fmul_add, "vector_fmul_add")) + test_vector_fmul_add(src0, src1, src2); + if (check_func(fdsp->vector_fmul_scalar, "vector_fmul_scalar")) + test_vector_fmul_scalar(src3, src4); + if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse")) + test_vector_fmul(src0, src1); + if (check_func(fdsp->vector_fmul_window, "vector_fmul_window")) + test_vector_fmul_window(src3, src4, src5); + report("vector_fmul"); + if (check_func(fdsp->vector_fmac_scalar, "vector_fmac_scalar")) + test_vector_fmac_scalar(src0, src1, src2); + report("vector_fmac"); + if (check_func(fdsp->vector_dmul_scalar, "vector_dmul_scalar")) + test_vector_dmul_scalar(dbl_src0, dbl_src1); + report("vector_dmul"); + if (check_func(fdsp->vector_dmac_scalar, "vector_dmac_scalar")) + test_vector_dmac_scalar(dbl_src0, dbl_src1, dbl_src2); + report("vector_dmac"); + if (check_func(fdsp->butterflies_float, "butterflies_float")) + test_butterflies_float(src3, src4); + report("butterflies_float"); + if (check_func(fdsp->scalarproduct_float, "scalarproduct_float")) + test_scalarproduct_float(src3, src4); + report("scalarproduct_float"); + + av_freep(&fdsp); +} diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak index 70ec824f5b..cf84f477a8 100644 --- a/tests/fate/checkasm.mak +++ b/tests/fate/checkasm.mak @@ -4,6 +4,7 @@ FATE_CHECKASM = fate-checkasm-alacdsp \ fate-checkasm-bswapdsp \ fate-checkasm-fixed_dsp \ fate-checkasm-flacdsp \ + fate-checkasm-float_dsp \ fate-checkasm-fmtconvert \ fate-checkasm-h264dsp \ fate-checkasm-h264pred \