From patchwork Wed Apr 26 17:32:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3497 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp457052vsd; Wed, 26 Apr 2017 10:32:32 -0700 (PDT) X-Received: by 10.223.134.97 with SMTP id 30mr637603wrw.161.1493227952614; Wed, 26 Apr 2017 10:32:32 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r27si781956wrr.334.2017.04.26.10.32.31; Wed, 26 Apr 2017 10:32:32 -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 B84F468799F; Wed, 26 Apr 2017 20:32:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f193.google.com (mail-qt0-f193.google.com [209.85.216.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 156E16800C6 for ; Wed, 26 Apr 2017 20:32:20 +0300 (EEST) Received: by mail-qt0-f193.google.com with SMTP id o36so1132930qtb.2 for ; Wed, 26 Apr 2017 10:32:21 -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=L2A9k8fy/3p1JXVvpnoqW1H3abNWyMRbSvWEfv48Cfs=; b=L08KLf5bI0trjxGD+/JvjO73ZhLeP75fl3GvXk7Du45Lo26LxDcGGIUJQXmh4J4qPe tg+XjXZYFeA/XLe+QiX9VVTEGkxgr131BFlncS7+RVsFxdxtiMf6LH36KlmpuuM/CeoB 4WMSaZu03hHCtkR4UGNnpP/6B/d8n1JvWFSAy3D+qrWtNO14yabzlGNj2nvZXXLmWJUX 3j2ofHc9imYebDhh0eMfT05yeC9OPmskb7H27rk9Qg7Tr0qc3rcSYFwLyJLVHreagJPs 0qWC1lRkAS3AOHy8h3qN3TLEXGW+FVPeqnSywxJVX7m6xPKYiv4tZ45cb1iDcEjAjo5m 2p9A== 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=L2A9k8fy/3p1JXVvpnoqW1H3abNWyMRbSvWEfv48Cfs=; b=LC3dwJvAmxMc4kLlBW87J56e7+g1yWq2VTVrbzeEd0ISom4rPBIRLkfb137rBk7sw/ r2EfRheYgtdFTaYE9+gRBiqMglJCJRAt+1QL/DLU//09zUcmUJVzmzEeJ7Kvd2xmbOEc q2/ZzTlWhCsi7VZUZ9OtdeajsvTtGoUl9t8Xdo9NF9boETsfp8O+/bYN0an/7l8ggWSQ gmZfn6+DJ227M2Kdk/42ipgr8xxq7FclpzyjiAF/oUcvPecIkjhbhtCrOxN75/dbbbGE 93otgOcRG4TejvB//7i0ZBbkG0MmjmXq6AwriM9fmSe8nCeIrsF9bbWtdL0rFpd+khnQ mo5g== X-Gm-Message-State: AN3rC/5V5hCBknOFxSLkDibTYNdX0xFCB8FidR8B4klJ9iBiZ+QAjoZj yL5bYm2SyNTI1qV2 X-Received: by 10.200.33.245 with SMTP id 50mr951143qtz.64.1493227940135; Wed, 26 Apr 2017 10:32:20 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id c64sm605793qka.63.2017.04.26.10.32.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Apr 2017 10:32:19 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Apr 2017 14:32:00 -0300 Message-Id: <20170426173200.2948-1-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170426132043.GO4714@nb4> References: <20170426132043.GO4714@nb4> Subject: [FFmpeg-devel] [PATCH v2] 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" This is a port of 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 | 302 +++++++++++++++++++++++++++++++++++++++++++++ tests/fate/checkasm.mak | 1 + 5 files changed, 328 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 695d871220..6cb10f606b 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..d0cdbe60d1 --- /dev/null +++ b/tests/checkasm/float_dsp.c @@ -0,0 +1,302 @@ +/* + * 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_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(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 *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 *win, int len); + + call_ref(cdst, src0, src1, src2, LEN / 2); + call_new(odst, src0, src1, src2, 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, src2, 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_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(float, odst, [LEN]); + LOCAL_ALIGNED_32(float, cdst1, [LEN]); + LOCAL_ALIGNED_32(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, 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_32(double, dbl_src0, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src1, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src2, [LEN]); + + AVFloatDSPContext *fdsp; + + if (!(fdsp = avpriv_float_dsp_alloc(1))) { + fprintf(stderr, "floatdsp: Out of memory error\n"); + return; + } + + randomize_buffer(src0); + randomize_buffer(src1); + randomize_buffer(src2); + 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(src0, src1); + 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(src0, src1, src2); + 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(src0, src1); + report("butterflies_float"); + if (check_func(fdsp->scalarproduct_float, "scalarproduct_float")) + test_scalarproduct_float(src0, src1); + report("scalarproduct_float"); + + av_freep(&fdsp); + + report("floatdsp"); +} diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak index c7b6b36ebb..a45436c8c8 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 \