summaryrefslogtreecommitdiff
path: root/libavutil/float_dsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/float_dsp.c')
-rw-r--r--libavutil/float_dsp.c96
1 files changed, 70 insertions, 26 deletions
diff --git a/libavutil/float_dsp.c b/libavutil/float_dsp.c
index aabc800db6..49e0ae7f03 100644
--- a/libavutil/float_dsp.c
+++ b/libavutil/float_dsp.c
@@ -1,24 +1,28 @@
/*
- * This file is part of Libav.
+ * Copyright 2005 Balatoni Denes
+ * Copyright 2006 Loren Merritt
*
- * Libav is free software; you can redistribute it and/or
+ * 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.
*
- * 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 "attributes.h"
#include "float_dsp.h"
+#include "mem.h"
static void vector_fmul_c(float *dst, const float *src0, const float *src1,
int len)
@@ -89,7 +93,7 @@ static void vector_fmul_reverse_c(float *dst, const float *src0,
dst[i] = src0[i] * src1[-i];
}
-static void butterflies_float_c(float *restrict v1, float *restrict v2,
+static void butterflies_float_c(float *av_restrict v1, float *av_restrict v2,
int len)
{
int i;
@@ -112,8 +116,12 @@ float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
return p;
}
-av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
+av_cold AVFloatDSPContext *avpriv_float_dsp_alloc(int bit_exact)
{
+ AVFloatDSPContext *fdsp = av_mallocz(sizeof(AVFloatDSPContext));
+ if (!fdsp)
+ return NULL;
+
fdsp->vector_fmul = vector_fmul_c;
fdsp->vector_fmac_scalar = vector_fmac_scalar_c;
fdsp->vector_fmul_scalar = vector_fmul_scalar_c;
@@ -132,8 +140,12 @@ av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
ff_float_dsp_init_ppc(fdsp, bit_exact);
if (ARCH_X86)
ff_float_dsp_init_x86(fdsp);
+ if (ARCH_MIPS)
+ ff_float_dsp_init_mips(fdsp);
+ return fdsp;
}
+
#ifdef TEST
#include <float.h>
@@ -141,13 +153,18 @@ av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
#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 "common.h"
#include "cpu.h"
#include "internal.h"
#include "lfg.h"
#include "log.h"
-#include "mem.h"
#include "random_seed.h"
#define LEN 240
@@ -364,9 +381,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]);
@@ -375,12 +392,40 @@ int main(int argc, char **argv)
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
+ 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);
@@ -391,29 +436,28 @@ int main(int argc, char **argv)
fill_double_array(&lfg, dbl_src0, LEN);
fill_double_array(&lfg, dbl_src1, 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;
+end:
+ av_freep(&fdsp);
+ av_freep(&cdsp);
return ret;
}