summaryrefslogtreecommitdiffstats
path: root/tests/checkasm/llviddspenc.c
blob: 31eafd5526d1a31f0505340408090f2073ad4293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Copyright (c) 2016 Alexandra Hájková
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU 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 <string.h>

#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"

#include "libavcodec/lossless_videoencdsp.h"

#include "checkasm.h"

#define randomize_buffers(buf, size)      \
    do {                                  \
        int j;                            \
        for (j = 0; j < size; j+=4)       \
            AV_WN32(buf + j, rnd());      \
    } while (0)

static const struct {uint8_t w, h, s;} planes[] = {
    {16,16,16}, {21,23,25}, {32,17,48}, {15,128,16}, {128,127,128}
};

#define MAX_STRIDE 128
#define MAX_HEIGHT 127

static void check_diff_bytes(LLVidEncDSPContext *c)
{
    int i;
    LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE]);
    LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE]);
    LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE]);
    LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE]);
    LOCAL_ALIGNED_32(uint8_t, src2, [MAX_STRIDE]);
    LOCAL_ALIGNED_32(uint8_t, src3, [MAX_STRIDE]);

    declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const uint8_t *src1,
                      const uint8_t *src2, intptr_t w);

    memset(dst0, 0, MAX_STRIDE);
    memset(dst1, 0, MAX_STRIDE);
    randomize_buffers(src0, MAX_STRIDE);
    memcpy(src1, src0, MAX_STRIDE);
    randomize_buffers(src2, MAX_STRIDE);
    memcpy(src3, src2, MAX_STRIDE);

    if (check_func(c->diff_bytes, "diff_bytes")) {
        for (i = 0; i < 5; i ++) {
            call_ref(dst0, src0, src2, planes[i].w);
            call_new(dst1, src1, src3, planes[i].w);
            if (memcmp(dst0, dst1, planes[i].w))
                fail();
        }
        bench_new(dst1, src0, src2, planes[4].w);
    }
}

static void check_sub_left_pred(LLVidEncDSPContext *c)
{
    int i;
    LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE * MAX_HEIGHT]);
    LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE * MAX_HEIGHT]);
    LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE * MAX_HEIGHT]);
    LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE * MAX_HEIGHT]);

    declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, const uint8_t *src,
                      ptrdiff_t stride, ptrdiff_t width, int height);

    memset(dst0, 0, MAX_STRIDE * MAX_HEIGHT);
    memset(dst1, 0, MAX_STRIDE * MAX_HEIGHT);
    randomize_buffers(src0, MAX_STRIDE * MAX_HEIGHT);
    memcpy(src1, src0, MAX_STRIDE * MAX_HEIGHT);

    if (check_func(c->sub_left_predict, "sub_left_predict")) {
        for (i = 0; i < 5; i ++) {
            call_ref(dst0, src0, planes[i].s, planes[i].w, planes[i].h);
            call_new(dst1, src1, planes[i].s, planes[i].w, planes[i].h);
            if (memcmp(dst0, dst1, planes[i].w * planes[i].h))
                fail();
            break;
        }
        bench_new(dst1, src0, planes[4].s, planes[4].w, planes[4].h);
    }
}

void checkasm_check_llviddspenc(void)
{
    LLVidEncDSPContext c;
    ff_llvidencdsp_init(&c);

    check_diff_bytes(&c);
    report("diff_bytes");

    check_sub_left_pred(&c);
    report("sub_left_predict");
}
OpenPOWER on IntegriCloud