aboutsummaryrefslogtreecommitdiffstats
path: root/tests/checkasm/bswapdsp.c
blob: 6aa7a81c2c0f293804584799df6cd67f9bd44f2d (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
/*
 * 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/bswapdsp.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"

#define BUF_SIZE 512

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

#define check_bswap(type)                                                                  \
    do {                                                                                   \
        int w;                                                                             \
        for (w = 0; w < BUF_SIZE / sizeof(type); w++) {                                    \
            int offset = (BUF_SIZE / sizeof(type) - w) & 15; /* Test various alignments */ \
            randomize_buffers();                                                           \
            call_ref((type *)dst0 + offset, (type *)src0 + offset, w);                     \
            call_new((type *)dst1 + offset, (type *)src1 + offset, w);                     \
            if (memcmp(src0, src1, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE))              \
                fail();                                                                    \
            bench_new((type *)dst1 + offset, (type *)src1 + offset, w);                    \
        }                                                                                  \
    } while (0)

void checkasm_check_bswapdsp(void)
{
    DECLARE_ALIGNED(16, uint8_t, src0)[BUF_SIZE];
    DECLARE_ALIGNED(16, uint8_t, src1)[BUF_SIZE];
    DECLARE_ALIGNED(16, uint8_t, dst0)[BUF_SIZE];
    DECLARE_ALIGNED(16, uint8_t, dst1)[BUF_SIZE];
    BswapDSPContext h;

    ff_bswapdsp_init(&h);

    if (check_func(h.bswap_buf, "bswap_buf"))
        check_bswap(uint32_t);

    if (check_func(h.bswap16_buf, "bswap16_buf"))
        check_bswap(uint16_t);

    report("bswap");
}