1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2015 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 "checkasm.h"
22cabdff1aSopenharmony_ci#include "libavutil/common.h"
23cabdff1aSopenharmony_ci#include "libavutil/fixed_dsp.h"
24cabdff1aSopenharmony_ci#include "libavutil/internal.h"
25cabdff1aSopenharmony_ci#include "libavutil/mem.h"
26cabdff1aSopenharmony_ci#include "libavutil/mem_internal.h"
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_ci#define BUF_SIZE 256
29cabdff1aSopenharmony_ci
30cabdff1aSopenharmony_ci#define randomize_buffers()                   \
31cabdff1aSopenharmony_ci    do {                                      \
32cabdff1aSopenharmony_ci        int i;                                \
33cabdff1aSopenharmony_ci        for (i = 0; i < BUF_SIZE; i++) {      \
34cabdff1aSopenharmony_ci            src0[i] = sign_extend(rnd(), 24); \
35cabdff1aSopenharmony_ci            src1[i] = sign_extend(rnd(), 24); \
36cabdff1aSopenharmony_ci            src2[i] = sign_extend(rnd(), 24); \
37cabdff1aSopenharmony_ci        }                                     \
38cabdff1aSopenharmony_ci    } while (0)
39cabdff1aSopenharmony_ci
40cabdff1aSopenharmony_cistatic void check_vector_fmul(const int *src0, const int *src1)
41cabdff1aSopenharmony_ci{
42cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
43cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
44cabdff1aSopenharmony_ci
45cabdff1aSopenharmony_ci    declare_func(void, int *dst, const int *src0, const int *src1, int len);
46cabdff1aSopenharmony_ci
47cabdff1aSopenharmony_ci    call_ref(ref, src0, src1, BUF_SIZE);
48cabdff1aSopenharmony_ci    call_new(new, src0, src1, BUF_SIZE);
49cabdff1aSopenharmony_ci    if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
50cabdff1aSopenharmony_ci        fail();
51cabdff1aSopenharmony_ci    bench_new(new, src0, src1, BUF_SIZE);
52cabdff1aSopenharmony_ci}
53cabdff1aSopenharmony_ci
54cabdff1aSopenharmony_cistatic void check_vector_fmul_add(const int *src0, const int *src1, const int *src2)
55cabdff1aSopenharmony_ci{
56cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]);
57cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int, new, [BUF_SIZE]);
58cabdff1aSopenharmony_ci
59cabdff1aSopenharmony_ci    declare_func(void, int *dst, const int *src0, const int *src1, const int *src2, int len);
60cabdff1aSopenharmony_ci
61cabdff1aSopenharmony_ci    call_ref(ref, src0, src1, src2, BUF_SIZE);
62cabdff1aSopenharmony_ci    call_new(new, src0, src1, src2, BUF_SIZE);
63cabdff1aSopenharmony_ci    if (memcmp(ref, new, BUF_SIZE * sizeof(int)))
64cabdff1aSopenharmony_ci        fail();
65cabdff1aSopenharmony_ci    bench_new(new, src0, src1, src2, BUF_SIZE);
66cabdff1aSopenharmony_ci}
67cabdff1aSopenharmony_ci
68cabdff1aSopenharmony_cistatic void check_vector_fmul_window(const int32_t *src0, const int32_t *src1, const int32_t *win)
69cabdff1aSopenharmony_ci{
70cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE]);
71cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE]);
72cabdff1aSopenharmony_ci
73cabdff1aSopenharmony_ci    declare_func(void, int32_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len);
74cabdff1aSopenharmony_ci
75cabdff1aSopenharmony_ci    call_ref(ref, src0, src1, win, BUF_SIZE / 2);
76cabdff1aSopenharmony_ci    call_new(new, src0, src1, win, BUF_SIZE / 2);
77cabdff1aSopenharmony_ci    if (memcmp(ref, new, BUF_SIZE * sizeof(int32_t)))
78cabdff1aSopenharmony_ci        fail();
79cabdff1aSopenharmony_ci    bench_new(new, src0, src1, win, BUF_SIZE / 2);
80cabdff1aSopenharmony_ci}
81cabdff1aSopenharmony_ci
82cabdff1aSopenharmony_cistatic void check_vector_fmul_window_scaled(const int32_t *src0, const int32_t *src1, const int32_t *win)
83cabdff1aSopenharmony_ci{
84cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(int16_t, ref, [BUF_SIZE]);
85cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(int16_t, new, [BUF_SIZE]);
86cabdff1aSopenharmony_ci
87cabdff1aSopenharmony_ci    declare_func(void, int16_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len, uint8_t bits);
88cabdff1aSopenharmony_ci
89cabdff1aSopenharmony_ci    call_ref(ref, src0, src1, win, BUF_SIZE / 2, 2);
90cabdff1aSopenharmony_ci    call_new(new, src0, src1, win, BUF_SIZE / 2, 2);
91cabdff1aSopenharmony_ci    if (memcmp(ref, new, BUF_SIZE * sizeof(int16_t)))
92cabdff1aSopenharmony_ci        fail();
93cabdff1aSopenharmony_ci    bench_new(new, src0, src1, win, BUF_SIZE / 2, 2);
94cabdff1aSopenharmony_ci}
95cabdff1aSopenharmony_ci
96cabdff1aSopenharmony_cistatic void check_butterflies(const int *src0, const int *src1)
97cabdff1aSopenharmony_ci{
98cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(int, ref0, [BUF_SIZE]);
99cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(int, ref1, [BUF_SIZE]);
100cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(int, new0, [BUF_SIZE]);
101cabdff1aSopenharmony_ci    LOCAL_ALIGNED_16(int, new1, [BUF_SIZE]);
102cabdff1aSopenharmony_ci
103cabdff1aSopenharmony_ci    declare_func(void, int *av_restrict src0, int *av_restrict src1, int len);
104cabdff1aSopenharmony_ci
105cabdff1aSopenharmony_ci    memcpy(ref0, src0, BUF_SIZE * sizeof(*src0));
106cabdff1aSopenharmony_ci    memcpy(ref1, src1, BUF_SIZE * sizeof(*src1));
107cabdff1aSopenharmony_ci    memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
108cabdff1aSopenharmony_ci    memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
109cabdff1aSopenharmony_ci
110cabdff1aSopenharmony_ci    call_ref(ref0, ref1, BUF_SIZE);
111cabdff1aSopenharmony_ci    call_new(new0, new1, BUF_SIZE);
112cabdff1aSopenharmony_ci    if (memcmp(ref0, new0, BUF_SIZE * sizeof(*ref0)) ||
113cabdff1aSopenharmony_ci        memcmp(ref1, new1, BUF_SIZE * sizeof(*ref1)))
114cabdff1aSopenharmony_ci        fail();
115cabdff1aSopenharmony_ci    memcpy(new0, src0, BUF_SIZE * sizeof(*src0));
116cabdff1aSopenharmony_ci    memcpy(new1, src1, BUF_SIZE * sizeof(*src1));
117cabdff1aSopenharmony_ci    bench_new(new0, new1, BUF_SIZE);
118cabdff1aSopenharmony_ci}
119cabdff1aSopenharmony_ci
120cabdff1aSopenharmony_cistatic void check_scalarproduct_fixed(const int *src0, const int *src1)
121cabdff1aSopenharmony_ci{
122cabdff1aSopenharmony_ci    int ref, new;
123cabdff1aSopenharmony_ci
124cabdff1aSopenharmony_ci    declare_func(int, const int *src0, const int *src1, int len);
125cabdff1aSopenharmony_ci
126cabdff1aSopenharmony_ci    ref = call_ref(src0, src1, BUF_SIZE);
127cabdff1aSopenharmony_ci    new = call_new(src0, src1, BUF_SIZE);
128cabdff1aSopenharmony_ci    if (ref != new)
129cabdff1aSopenharmony_ci        fail();
130cabdff1aSopenharmony_ci    bench_new(src0, src1, BUF_SIZE);
131cabdff1aSopenharmony_ci}
132cabdff1aSopenharmony_ci
133cabdff1aSopenharmony_civoid checkasm_check_fixed_dsp(void)
134cabdff1aSopenharmony_ci{
135cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int32_t, src0, [BUF_SIZE]);
136cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int32_t, src1, [BUF_SIZE]);
137cabdff1aSopenharmony_ci    LOCAL_ALIGNED_32(int32_t, src2, [BUF_SIZE]);
138cabdff1aSopenharmony_ci    AVFixedDSPContext *fdsp = avpriv_alloc_fixed_dsp(1);
139cabdff1aSopenharmony_ci
140cabdff1aSopenharmony_ci    randomize_buffers();
141cabdff1aSopenharmony_ci    if (check_func(fdsp->vector_fmul, "vector_fmul_fixed"))
142cabdff1aSopenharmony_ci        check_vector_fmul(src0, src1);
143cabdff1aSopenharmony_ci    if (check_func(fdsp->vector_fmul_add, "vector_fmul_add_fixed"))
144cabdff1aSopenharmony_ci        check_vector_fmul_add(src0, src1, src2);
145cabdff1aSopenharmony_ci    if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse_fixed"))
146cabdff1aSopenharmony_ci        check_vector_fmul(src0, src1);
147cabdff1aSopenharmony_ci    if (check_func(fdsp->vector_fmul_window, "vector_fmul_window_fixed"))
148cabdff1aSopenharmony_ci        check_vector_fmul_window(src0, src1, src2);
149cabdff1aSopenharmony_ci    if (check_func(fdsp->vector_fmul_window_scaled, "vector_fmul_window_scaled_fixed"))
150cabdff1aSopenharmony_ci        check_vector_fmul_window_scaled(src0, src1, src2);
151cabdff1aSopenharmony_ci    report("vector_fmul");
152cabdff1aSopenharmony_ci    if (check_func(fdsp->butterflies_fixed, "butterflies_fixed"))
153cabdff1aSopenharmony_ci        check_butterflies(src0, src1);
154cabdff1aSopenharmony_ci    report("butterflies_fixed");
155cabdff1aSopenharmony_ci    if (check_func(fdsp->scalarproduct_fixed, "scalarproduct_fixed"))
156cabdff1aSopenharmony_ci        check_scalarproduct_fixed(src0, src1);
157cabdff1aSopenharmony_ci    report("scalarproduct_fixed");
158cabdff1aSopenharmony_ci
159cabdff1aSopenharmony_ci    av_freep(&fdsp);
160cabdff1aSopenharmony_ci}
161