xref: /third_party/ffmpeg/tests/checkasm/exrdsp.c (revision cabdff1a)
1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2017 James Almer
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or modify
7cabdff1aSopenharmony_ci * it under the terms of the GNU General Public License as published by
8cabdff1aSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
9cabdff1aSopenharmony_ci * (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14cabdff1aSopenharmony_ci * GNU General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU General Public License along
17cabdff1aSopenharmony_ci * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18cabdff1aSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci#include <string.h>
22cabdff1aSopenharmony_ci
23cabdff1aSopenharmony_ci#include "checkasm.h"
24cabdff1aSopenharmony_ci#include "libavcodec/avcodec.h"
25cabdff1aSopenharmony_ci#include "libavcodec/exrdsp.h"
26cabdff1aSopenharmony_ci#include "libavutil/intreadwrite.h"
27cabdff1aSopenharmony_ci#include "libavutil/mem_internal.h"
28cabdff1aSopenharmony_ci
29cabdff1aSopenharmony_ci#define BUF_SIZE 5120
30cabdff1aSopenharmony_ci#define PADDED_BUF_SIZE BUF_SIZE+AV_INPUT_BUFFER_PADDING_SIZE*2
31cabdff1aSopenharmony_ci
32cabdff1aSopenharmony_ci#define randomize_buffers()                 \
33cabdff1aSopenharmony_ci    do {                                    \
34cabdff1aSopenharmony_ci        int i;                              \
35cabdff1aSopenharmony_ci        for (i = 0; i < BUF_SIZE; i += 4) { \
36cabdff1aSopenharmony_ci            uint32_t r = rnd();             \
37cabdff1aSopenharmony_ci            AV_WN32A(src + i, r);           \
38cabdff1aSopenharmony_ci        }                                   \
39cabdff1aSopenharmony_ci    } while (0)
40cabdff1aSopenharmony_ci
41cabdff1aSopenharmony_cistatic void check_reorder_pixels(void) {
42cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(uint8_t, src,     [PADDED_BUF_SIZE]);
43cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
44cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);
45cabdff1aSopenharmony_ci
46cabdff1aSopenharmony_ci    declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t size);
47cabdff1aSopenharmony_ci
48cabdff1aSopenharmony_ci    memset(src,     0, PADDED_BUF_SIZE);
49cabdff1aSopenharmony_ci    memset(dst_ref, 0, PADDED_BUF_SIZE);
50cabdff1aSopenharmony_ci    memset(dst_new, 0, PADDED_BUF_SIZE);
51cabdff1aSopenharmony_ci    randomize_buffers();
52cabdff1aSopenharmony_ci    call_ref(dst_ref, src, BUF_SIZE);
53cabdff1aSopenharmony_ci    call_new(dst_new, src, BUF_SIZE);
54cabdff1aSopenharmony_ci    if (memcmp(dst_ref, dst_new, BUF_SIZE))
55cabdff1aSopenharmony_ci        fail();
56cabdff1aSopenharmony_ci    bench_new(dst_new, src, BUF_SIZE);
57cabdff1aSopenharmony_ci}
58cabdff1aSopenharmony_ci
59cabdff1aSopenharmony_cistatic void check_predictor(void) {
60cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(uint8_t, src,     [PADDED_BUF_SIZE]);
61cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
62cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);
63cabdff1aSopenharmony_ci
64cabdff1aSopenharmony_ci    declare_func(void, uint8_t *src, ptrdiff_t size);
65cabdff1aSopenharmony_ci
66cabdff1aSopenharmony_ci    memset(src,     0, PADDED_BUF_SIZE);
67cabdff1aSopenharmony_ci    randomize_buffers();
68cabdff1aSopenharmony_ci    memcpy(dst_ref, src, PADDED_BUF_SIZE);
69cabdff1aSopenharmony_ci    memcpy(dst_new, src, PADDED_BUF_SIZE);
70cabdff1aSopenharmony_ci    call_ref(dst_ref, BUF_SIZE);
71cabdff1aSopenharmony_ci    call_new(dst_new, BUF_SIZE);
72cabdff1aSopenharmony_ci    if (memcmp(dst_ref, dst_new, BUF_SIZE))
73cabdff1aSopenharmony_ci        fail();
74cabdff1aSopenharmony_ci    bench_new(dst_new, BUF_SIZE);
75cabdff1aSopenharmony_ci}
76cabdff1aSopenharmony_ci
77cabdff1aSopenharmony_civoid checkasm_check_exrdsp(void)
78cabdff1aSopenharmony_ci{
79cabdff1aSopenharmony_ci    ExrDSPContext h;
80cabdff1aSopenharmony_ci
81cabdff1aSopenharmony_ci    ff_exrdsp_init(&h);
82cabdff1aSopenharmony_ci
83cabdff1aSopenharmony_ci    if (check_func(h.reorder_pixels, "reorder_pixels"))
84cabdff1aSopenharmony_ci        check_reorder_pixels();
85cabdff1aSopenharmony_ci
86cabdff1aSopenharmony_ci    report("reorder_pixels");
87cabdff1aSopenharmony_ci
88cabdff1aSopenharmony_ci    if (check_func(h.predictor, "predictor"))
89cabdff1aSopenharmony_ci        check_predictor();
90cabdff1aSopenharmony_ci
91cabdff1aSopenharmony_ci    report("predictor");
92cabdff1aSopenharmony_ci}
93