From patchwork Tue Apr 11 21:11:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3368 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp25539vss; Tue, 11 Apr 2017 14:12:16 -0700 (PDT) X-Received: by 10.223.171.8 with SMTP id q8mr12710343wrc.115.1491945136719; Tue, 11 Apr 2017 14:12:16 -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 x4si27781972wrd.117.2017.04.11.14.12.16; Tue, 11 Apr 2017 14:12:16 -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 46BAB688393; Wed, 12 Apr 2017 00:12:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B58436882C2 for ; Wed, 12 Apr 2017 00:12:01 +0300 (EEST) Received: by mail-qt0-f195.google.com with SMTP id o36so1423482qtb.2 for ; Tue, 11 Apr 2017 14:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=KXIWgez9CJyxkHDxpzPXhBGpnbizpoHmc7WD9mfN8Eo=; b=r90TI4yrx+6Fu+Exy6Tw0hoHtvCjmUs1P2aGwNY24oOFDIThNVQJf5lETUAgfjAoRZ VNaRr3Os/k6I/jlkzFWh78iNZ4nYKxm828jjhPLsvXkaXSScHq+vfongdMVqwRNS/Pup wPe6QZr+cR1EVx4GIWykYNhF9RVXnrE9ishwKMGcdsughg2J9KrnFtKAzdQhVY4F0zXx n94KsYLlLfmed7Sjge+ewfHRc2zwmYwDGNJkYlrsKTzffItL0myJlpGbGXy5YR1Z33xR Zr5Ecty/YvmJPSrX1Pc0S2NfhwK4uSShZjIF4++xUlU5UyoSU4fQTCiMV9+8Xd8460aE Ou4Q== 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; bh=KXIWgez9CJyxkHDxpzPXhBGpnbizpoHmc7WD9mfN8Eo=; b=I4OBhOsXZH/8c2iTvooim3cPfymzZZQPZ+A+ujF3WfYS1qkmiyENcWIolxEpoJXhXW 2NTMdcq9SQWQ6FIBYlGWqZa4bnKKy6EDpdOpEG9skBbBNY9pSTlSeeCwbKyN6/m95dPV zRpJrPFYc09olk+ze3aRC4i8pgaJ6B8iVdPmDCywj/jQZjD1H7kn2WI24vJDCxNeXhxN hefaFEWmk9sflUaIHmV3OuAMTURQoPQZNKHT5+z3HUyetOtYpEzCq7IoRj+bU0P58htl p7iRiXCR2nKCOsA92ZLSs3BLLeqjfTlwlHaTRvnpef9Vra9ZFR/sZQUGwh3TiuXB8gmD Nvtg== X-Gm-Message-State: AN3rC/5psQ2OYiMR14xz2mmLrs04W7LDmKmkHr85+PI5sPRJCEpgnNtrxPtpZLzARyJ6Fw== X-Received: by 10.200.54.218 with SMTP id b26mr22467721qtc.8.1491945126017; Tue, 11 Apr 2017 14:12:06 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id f28sm11883330qtf.44.2017.04.11.14.12.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 14:12:05 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Apr 2017 18:11:54 -0300 Message-Id: <20170411211154.2228-1-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 Subject: [FFmpeg-devel] [PATCH] 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..89ebe56fa7 --- /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(int, 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 \