aboutsummaryrefslogtreecommitdiffstats
path: root/tests/checkasm/blockdsp.c
blob: 5f4d46b8fac3312fffa80fd908dc1801d03b4d13 (plain) (blame)
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
/*
 * Copyright (c) 2015 Henrik Gramner
 *
 * 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 "checkasm.h"

#include "libavcodec/blockdsp.h"

#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"

#define randomize_buffers(size)             \
    do {                                    \
        int i;                              \
        for (i = 0; i < size; i++) {        \
            uint16_t r = rnd();             \
            AV_WN16A(buf0 + i, r);          \
            AV_WN16A(buf1 + i, r);          \
        }                                   \
    } while (0)

#define check_clear(func, size)                                     \
do {                                                                \
    if (check_func(h.func, "blockdsp." #func)) {                    \
        declare_func(void, int16_t *block);                         \
        randomize_buffers(size);                                    \
        call_ref(buf0);                                             \
        call_new(buf1);                                             \
        if (memcmp(buf0, buf1, sizeof(*buf0) * size))               \
            fail();                                                 \
        bench_new(buf0);                                            \
    }                                                               \
} while (0)

static void check_fill(BlockDSPContext *h){
    LOCAL_ALIGNED_16(uint8_t, buf0_16, [16 * 16]);
    LOCAL_ALIGNED_16(uint8_t, buf1_16, [16 * 16]);

    for (int t = 0; t < 2; ++t) {
        uint8_t *buf0 = buf0_16 + t * /* force 8 byte alignment */ 8;
        uint8_t *buf1 = buf1_16 + t * /* force 8 byte alignment */ 8;
        int n = 16 - 8 * t;
        declare_func(void, uint8_t *block, uint8_t value,
                     ptrdiff_t line_size, int h);
        if (check_func(h->fill_block_tab[t], "blockdsp.fill_block_tab[%d]", t)) {
            uint8_t value = rnd();
            memset(buf0, 0, sizeof(*buf0) * n * n);
            memset(buf1, 0, sizeof(*buf1) * n * n);
            call_ref(buf0, value, n, n);
            call_new(buf1, value, n, n);
            if (memcmp(buf0, buf1, sizeof(*buf0) * n * n))
                fail();
            bench_new(buf0, value, n, n);
        }
    }
}

void checkasm_check_blockdsp(void)
{
    LOCAL_ALIGNED_32(uint16_t, buf0, [6 * 8 * 8]);
    LOCAL_ALIGNED_32(uint16_t, buf1, [6 * 8 * 8]);

    BlockDSPContext h;

    ff_blockdsp_init(&h);

    check_clear(clear_block,  8 * 8);
    check_clear(clear_blocks, 8 * 8 * 6);

    check_fill(&h);

    report("blockdsp");
}