[FFmpeg-devel] [PATCH 2/2] fate: add fixed-dsp test

James Almer jamrial at gmail.com
Sat Jan 16 02:10:43 CET 2016


Adapted from float-dsp

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavutil/Makefile       |   1 +
 libavutil/fixed_dsp.c    | 249 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/fate/libavutil.mak |   6 ++
 3 files changed, 256 insertions(+)

diff --git a/libavutil/Makefile b/libavutil/Makefile
index bf8c713..e8c0614 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -174,6 +174,7 @@ TESTPROGS = adler32                                                     \
             eval                                                        \
             file                                                        \
             fifo                                                        \
+            fixed_dsp                                                   \
             float_dsp                                                   \
             hmac                                                        \
             lfg                                                         \
diff --git a/libavutil/fixed_dsp.c b/libavutil/fixed_dsp.c
index 8c01858..e0460e1 100644
--- a/libavutil/fixed_dsp.c
+++ b/libavutil/fixed_dsp.c
@@ -165,3 +165,252 @@ AVFixedDSPContext * avpriv_alloc_fixed_dsp(int bit_exact)
 
     return fdsp;
 }
+
+#ifdef TEST
+
+#include <inttypes.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 "random_seed.h"
+
+#define LEN 240
+
+static void fill_array(AVLFG *lfg, int *a, int len)
+{
+    int i;
+
+    for (i = 0; i < len; i += 2) {
+        a[i]     = sign_extend(av_lfg_get(lfg), 24);
+        a[i + 1] = sign_extend(av_lfg_get(lfg), 24);
+    }
+}
+
+static int compare_int16(const int16_t *a, const int16_t *b, int len)
+{
+    int i;
+    for (i = 0; i < len; i++) {
+        if (a[i] != b[i]) {
+            av_log(NULL, AV_LOG_ERROR, "%d: %"PRId16" != %"PRId16"\n", i, a[i], b[i]);
+            return -1;
+        }
+    }
+    return 0;
+}
+
+static int compare_int(const int *a, const int *b, int len)
+{
+    int i;
+    for (i = 0; i < len; i++) {
+        if (a[i] != b[i]) {
+            av_log(NULL, AV_LOG_ERROR, "%d: %d != %d\n", i, a[i], b[i]);
+            return -1;
+        }
+    }
+    return 0;
+}
+
+static int test_vector_fmul(AVFixedDSPContext *fdsp, AVFixedDSPContext *cdsp,
+                            const int *v1, const int *v2)
+{
+    LOCAL_ALIGNED(32, int, cdst, [LEN]);
+    LOCAL_ALIGNED(32, int, odst, [LEN]);
+    int ret;
+
+    cdsp->vector_fmul(cdst, v1, v2, LEN);
+    fdsp->vector_fmul(odst, v1, v2, LEN);
+
+    if (ret = compare_int(cdst, odst, LEN))
+        av_log(NULL, AV_LOG_ERROR, "vector_fmul failed\n");
+
+    return ret;
+}
+
+static int test_vector_fmul_window_scaled(AVFixedDSPContext *fdsp, AVFixedDSPContext *cdsp,
+                                          const int32_t *v1, const int32_t *v2, const int32_t *v3)
+{
+    LOCAL_ALIGNED(32, int16_t, cdst, [LEN]);
+    LOCAL_ALIGNED(32, int16_t, odst, [LEN]);
+    int ret;
+
+    cdsp->vector_fmul_window_scaled(cdst, v1, v2, v3, LEN / 2, 2);
+    fdsp->vector_fmul_window_scaled(odst, v1, v2, v3, LEN / 2, 2);
+
+    if (ret = compare_int16(cdst, odst, LEN))
+        av_log(NULL, AV_LOG_ERROR, "vector_fmul_window_scaled failed\n");
+
+    return ret;
+}
+
+static int test_vector_fmul_window(AVFixedDSPContext *fdsp, AVFixedDSPContext *cdsp,
+                                   const int32_t *v1, const int32_t *v2, const int32_t *v3)
+{
+    LOCAL_ALIGNED(32, int32_t, cdst, [LEN]);
+    LOCAL_ALIGNED(32, int32_t, odst, [LEN]);
+    int ret;
+
+    cdsp->vector_fmul_window(cdst, v1, v2, v3, LEN / 2);
+    fdsp->vector_fmul_window(odst, v1, v2, v3, LEN / 2);
+
+    if (ret = compare_int(cdst, odst, LEN))
+        av_log(NULL, AV_LOG_ERROR, "vector_fmul_window failed\n");
+
+    return ret;
+}
+
+static int test_vector_fmul_add(AVFixedDSPContext *fdsp, AVFixedDSPContext *cdsp,
+                                const int *v1, const int *v2, const int *v3)
+{
+    LOCAL_ALIGNED(32, int, cdst, [LEN]);
+    LOCAL_ALIGNED(32, int, odst, [LEN]);
+    int ret;
+
+    cdsp->vector_fmul_add(cdst, v1, v2, v3, LEN);
+    fdsp->vector_fmul_add(odst, v1, v2, v3, LEN);
+
+    if (ret = compare_int(cdst, odst, LEN))
+        av_log(NULL, AV_LOG_ERROR, "vector_fmul_add failed\n");
+
+    return ret;
+}
+
+static int test_vector_fmul_reverse(AVFixedDSPContext *fdsp, AVFixedDSPContext *cdsp,
+                                    const int *v1, const int *v2)
+{
+    LOCAL_ALIGNED(32, int, cdst, [LEN]);
+    LOCAL_ALIGNED(32, int, odst, [LEN]);
+    int ret;
+
+    cdsp->vector_fmul_reverse(cdst, v1, v2, LEN);
+    fdsp->vector_fmul_reverse(odst, v1, v2, LEN);
+
+    if (ret = compare_int(cdst, odst, LEN))
+        av_log(NULL, AV_LOG_ERROR, "vector_fmul_reverse failed\n");
+
+    return ret;
+}
+
+static int test_butterflies_fixed(AVFixedDSPContext *fdsp, AVFixedDSPContext *cdsp,
+                                  const int *v1, const int *v2)
+{
+    LOCAL_ALIGNED(32, int, cv1, [LEN]);
+    LOCAL_ALIGNED(32, int, cv2, [LEN]);
+    LOCAL_ALIGNED(32, int, ov1, [LEN]);
+    LOCAL_ALIGNED(32, int, ov2, [LEN]);
+    int ret;
+
+    memcpy(cv1, v1, LEN * sizeof(*v1));
+    memcpy(cv2, v2, LEN * sizeof(*v2));
+    memcpy(ov1, v1, LEN * sizeof(*v1));
+    memcpy(ov2, v2, LEN * sizeof(*v2));
+
+    cdsp->butterflies_fixed(cv1, cv2, LEN);
+    fdsp->butterflies_fixed(ov1, ov2, LEN);
+
+    if ((ret = compare_int(cv1, ov1, LEN)) ||
+        (ret = compare_int(cv2, ov2, LEN)))
+        av_log(NULL, AV_LOG_ERROR, "butterflies_fixed failed\n");
+
+    return ret;
+}
+
+static int test_scalarproduct_fixed(AVFixedDSPContext *fdsp, AVFixedDSPContext *cdsp,
+                                    const int *v1, const int *v2)
+{
+    int cprod, oprod;
+    int ret;
+
+    cprod = cdsp->scalarproduct_fixed(v1, v2, LEN);
+    oprod = fdsp->scalarproduct_fixed(v1, v2, LEN);
+
+    if (ret = compare_int(&cprod, &oprod, 1))
+        av_log(NULL, AV_LOG_ERROR, "scalarproduct_fixed failed\n");
+
+    return ret;
+}
+
+int main(int argc, char **argv)
+{
+    int ret = 0, seeded = 0;
+    uint32_t seed;
+    AVFixedDSPContext *fdsp, *cdsp;
+    AVLFG lfg;
+
+    LOCAL_ALIGNED(32, int, src0, [LEN]);
+    LOCAL_ALIGNED(32, int, src1, [LEN]);
+    LOCAL_ALIGNED(32, int, 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, "fixed_dsp-test: %s %u\n", seeded ? "seed" : "random seed", seed);
+
+    fdsp = avpriv_alloc_fixed_dsp(1);
+    av_force_cpu_flags(0);
+    cdsp = avpriv_alloc_fixed_dsp(1);
+
+    if (!fdsp || !cdsp) {
+        ret = 1;
+        goto end;
+    }
+
+    av_lfg_init(&lfg, seed);
+
+    fill_array(&lfg, src0, LEN);
+    fill_array(&lfg, src1, LEN);
+    fill_array(&lfg, src2, LEN);
+
+    if (test_vector_fmul(fdsp, cdsp, src0, src1))
+        ret -= 1 << 0;
+    if (test_vector_fmul_window_scaled(fdsp, cdsp, src0, src1, src2))
+        ret -= 1 << 1;
+    if (test_vector_fmul_window(fdsp, cdsp, src0, src1, src2))
+        ret -= 1 << 2;
+    if (test_vector_fmul_add(fdsp, cdsp, src0, src1, src2))
+        ret -= 1 << 3;
+    if (test_vector_fmul_reverse(fdsp, cdsp, src0, src1))
+        ret -= 1 << 4;
+    if (test_butterflies_fixed(fdsp, cdsp, src0, src1))
+        ret -= 1 << 5;
+    if (test_scalarproduct_fixed(fdsp, cdsp, src0, src1))
+        ret -= 1 << 6;
+
+end:
+    av_freep(&fdsp);
+    av_freep(&cdsp);
+    return ret;
+}
+
+#endif /* TEST */
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 022ae6a..662bd16 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -65,6 +65,12 @@ FATE_LIBAVUTIL += fate-fifo
 fate-fifo: libavutil/fifo-test$(EXESUF)
 fate-fifo: CMD = run libavutil/fifo-test
 
+FATE_LIBAVUTIL += fate-fixed-dsp
+fate-fixed-dsp: libavutil/fixed_dsp-test$(EXESUF)
+fate-fixed-dsp: CMD = run libavutil/fixed_dsp-test $(CPUFLAGS:%=-c%)
+fate-fixed-dsp: CMP = null
+fate-fixed-dsp: REF = /dev/null
+
 FATE_LIBAVUTIL += fate-float-dsp
 fate-float-dsp: libavutil/float_dsp-test$(EXESUF)
 fate-float-dsp: CMD = run libavutil/float_dsp-test $(CPUFLAGS:%=-c%)
-- 
2.7.0



More information about the ffmpeg-devel mailing list