summaryrefslogtreecommitdiff
path: root/libavutil/tests/float_dsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/tests/float_dsp.c')
-rw-r--r--libavutil/tests/float_dsp.c111
1 files changed, 86 insertions, 25 deletions
diff --git a/libavutil/tests/float_dsp.c b/libavutil/tests/float_dsp.c
index ab6bf6a569..7dc98c548e 100644
--- a/libavutil/tests/float_dsp.c
+++ b/libavutil/tests/float_dsp.c
@@ -1,26 +1,36 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * 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.
*
- * Libav is distributed in the hope that it will be useful,
+ * 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 Libav; if not, write to the Free Software
+ * 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 <float.h>
+#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-
+#if HAVE_UNISTD_H
+#include <unistd.h> /* for getopt */
+#endif
+#if !HAVE_GETOPT
+#include "compat/getopt.c"
+#endif
+
+#include "libavutil/common.h"
#include "libavutil/cpu.h"
#include "libavutil/internal.h"
#include "libavutil/lfg.h"
@@ -134,6 +144,26 @@ static int test_vector_fmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *c
return ret;
}
+#define ARBITRARY_DMAC_SCALAR_CONST 0.005
+static int test_vector_dmac_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
+ const double *v1, const double *src0, double scale)
+{
+ LOCAL_ALIGNED(32, double, cdst, [LEN]);
+ LOCAL_ALIGNED(32, double, odst, [LEN]);
+ int ret;
+
+ memcpy(cdst, v1, LEN * sizeof(*v1));
+ memcpy(odst, v1, LEN * sizeof(*v1));
+
+ cdsp->vector_dmac_scalar(cdst, src0, scale, LEN);
+ fdsp->vector_dmac_scalar(odst, src0, scale, LEN);
+
+ if (ret = compare_doubles(cdst, odst, LEN, ARBITRARY_DMAC_SCALAR_CONST))
+ av_log(NULL, AV_LOG_ERROR, "vector_dmac_scalar failed\n");
+
+ return ret;
+}
+
static int test_vector_dmul_scalar(AVFloatDSPContext *fdsp, AVFloatDSPContext *cdsp,
const double *v1, double scale)
{
@@ -242,9 +272,9 @@ static int test_scalarproduct_float(AVFloatDSPContext *fdsp, AVFloatDSPContext *
int main(int argc, char **argv)
{
- int ret = 0;
+ int ret = 0, seeded = 0;
uint32_t seed;
- AVFloatDSPContext fdsp, cdsp;
+ AVFloatDSPContext *fdsp, *cdsp;
AVLFG lfg;
LOCAL_ALIGNED(32, float, src0, [LEN]);
@@ -252,13 +282,42 @@ int main(int argc, char **argv)
LOCAL_ALIGNED(32, float, src2, [LEN]);
LOCAL_ALIGNED(32, double, dbl_src0, [LEN]);
LOCAL_ALIGNED(32, double, dbl_src1, [LEN]);
-
- if (argc > 2 && !strcmp(argv[1], "-s"))
- seed = strtoul(argv[2], NULL, 10);
- else
+ LOCAL_ALIGNED(32, double, dbl_src2, [LEN]);
+
+ for (;;) {
+ int arg = getopt(argc, argv, "s:c:");
+ if (arg == -1)
+ break;
+ switch (arg) {
+ case 's':
+ seed = strtoul(optarg, NULL, 10);
+ seeded = 1;
+ break;
+ case 'c':
+ {
+ int cpuflags = av_get_cpu_flags();
+
+ if (av_parse_cpu_caps(&cpuflags, optarg) < 0)
+ return 1;
+
+ av_force_cpu_flags(cpuflags);
+ break;
+ }
+ }
+ }
+ if (!seeded)
seed = av_get_random_seed();
- av_log(NULL, AV_LOG_INFO, "float_dsp-test: random seed %u\n", seed);
+ av_log(NULL, AV_LOG_INFO, "float_dsp-test: %s %u\n", seeded ? "seed" : "random seed", seed);
+
+ fdsp = avpriv_float_dsp_alloc(1);
+ av_force_cpu_flags(0);
+ cdsp = avpriv_float_dsp_alloc(1);
+
+ if (!fdsp || !cdsp) {
+ ret = 1;
+ goto end;
+ }
av_lfg_init(&lfg, seed);
@@ -268,29 +327,31 @@ int main(int argc, char **argv)
fill_double_array(&lfg, dbl_src0, LEN);
fill_double_array(&lfg, dbl_src1, LEN);
+ fill_double_array(&lfg, dbl_src2, LEN);
- avpriv_float_dsp_init(&fdsp, 1);
- av_set_cpu_flags_mask(0);
- avpriv_float_dsp_init(&cdsp, 1);
-
- if (test_vector_fmul(&fdsp, &cdsp, src0, src1))
+ if (test_vector_fmul(fdsp, cdsp, src0, src1))
ret -= 1 << 0;
- if (test_vector_fmac_scalar(&fdsp, &cdsp, src2, src0, src1[0]))
+ if (test_vector_fmac_scalar(fdsp, cdsp, src2, src0, src1[0]))
ret -= 1 << 1;
- if (test_vector_fmul_scalar(&fdsp, &cdsp, src0, src1[0]))
+ if (test_vector_fmul_scalar(fdsp, cdsp, src0, src1[0]))
ret -= 1 << 2;
- if (test_vector_fmul_window(&fdsp, &cdsp, src0, src1, src2))
+ if (test_vector_fmul_window(fdsp, cdsp, src0, src1, src2))
ret -= 1 << 3;
- if (test_vector_fmul_add(&fdsp, &cdsp, src0, src1, src2))
+ if (test_vector_fmul_add(fdsp, cdsp, src0, src1, src2))
ret -= 1 << 4;
- if (test_vector_fmul_reverse(&fdsp, &cdsp, src0, src1))
+ if (test_vector_fmul_reverse(fdsp, cdsp, src0, src1))
ret -= 1 << 5;
- if (test_butterflies_float(&fdsp, &cdsp, src0, src1))
+ if (test_butterflies_float(fdsp, cdsp, src0, src1))
ret -= 1 << 6;
- if (test_scalarproduct_float(&fdsp, &cdsp, src0, src1))
+ if (test_scalarproduct_float(fdsp, cdsp, src0, src1))
ret -= 1 << 7;
- if (test_vector_dmul_scalar(&fdsp, &cdsp, dbl_src0, dbl_src1[0]))
+ if (test_vector_dmul_scalar(fdsp, cdsp, dbl_src0, dbl_src1[0]))
ret -= 1 << 8;
+ if (test_vector_dmac_scalar(fdsp, cdsp, dbl_src2, dbl_src0, dbl_src1[0]))
+ ret -= 1 << 9;
+end:
+ av_freep(&fdsp);
+ av_freep(&cdsp);
return ret;
}