aboutsummaryrefslogtreecommitdiffstats
path: root/tests/checkasm/exrdsp.c
blob: 8af2f131096d2233a5dacbb604b3fd6dda9c3f1c (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
/*
 * Copyright (c) 2017 James Almer
 *
 * 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/defs.h"
#include "libavcodec/exrdsp.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"

#define BUF_SIZE 5120
#define PADDED_BUF_SIZE BUF_SIZE+AV_INPUT_BUFFER_PADDING_SIZE*2

#define randomize_buffers()                 \
    do {                                    \
        int i;                              \
        for (i = 0; i < BUF_SIZE; i += 4) { \
            uint32_t r = rnd();             \
            AV_WN32A(src + i, r);           \
        }                                   \
    } while (0)

static void check_reorder_pixels(void) {
    LOCAL_ALIGNED_32(uint8_t, src,     [PADDED_BUF_SIZE]);
    LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
    LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);

    declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t size);

    memset(src,     0, PADDED_BUF_SIZE);
    memset(dst_ref, 0, PADDED_BUF_SIZE);
    memset(dst_new, 0, PADDED_BUF_SIZE);
    randomize_buffers();
    call_ref(dst_ref, src, BUF_SIZE);
    call_new(dst_new, src, BUF_SIZE);
    if (memcmp(dst_ref, dst_new, BUF_SIZE))
        fail();
    bench_new(dst_new, src, BUF_SIZE);
}

static void check_predictor(void) {
    LOCAL_ALIGNED_32(uint8_t, src,     [PADDED_BUF_SIZE]);
    LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
    LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);

    declare_func(void, uint8_t *src, ptrdiff_t size);

    memset(src,     0, PADDED_BUF_SIZE);
    randomize_buffers();
    memcpy(dst_ref, src, PADDED_BUF_SIZE);
    memcpy(dst_new, src, PADDED_BUF_SIZE);
    call_ref(dst_ref, BUF_SIZE);
    call_new(dst_new, BUF_SIZE);
    if (memcmp(dst_ref, dst_new, BUF_SIZE))
        fail();
    bench_new(dst_new, BUF_SIZE);
}

void checkasm_check_exrdsp(void)
{
    ExrDSPContext h;

    ff_exrdsp_init(&h);

    if (check_func(h.reorder_pixels, "reorder_pixels"))
        check_reorder_pixels();

    report("reorder_pixels");

    if (check_func(h.predictor, "predictor"))
        check_predictor();

    report("predictor");
}