diff options
Diffstat (limited to 'tests/checkasm')
35 files changed, 2711 insertions, 769 deletions
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index d5febec74c..74f07f11cd 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -3,21 +3,40 @@ AVCODECOBJS-$(CONFIG_AUDIODSP) += audiodsp.o AVCODECOBJS-$(CONFIG_BLOCKDSP) += blockdsp.o AVCODECOBJS-$(CONFIG_BSWAPDSP) += bswapdsp.o +AVCODECOBJS-$(CONFIG_FLACDSP) += flacdsp.o AVCODECOBJS-$(CONFIG_FMTCONVERT) += fmtconvert.o -AVCODECOBJS-$(CONFIG_HUFFYUVDSP) += huffyuvdsp.o +AVCODECOBJS-$(CONFIG_G722DSP) += g722dsp.o AVCODECOBJS-$(CONFIG_H264DSP) += h264dsp.o AVCODECOBJS-$(CONFIG_H264PRED) += h264pred.o AVCODECOBJS-$(CONFIG_H264QPEL) += h264qpel.o +AVCODECOBJS-$(CONFIG_LLVIDDSP) += llviddsp.o AVCODECOBJS-$(CONFIG_VP8DSP) += vp8dsp.o +AVCODECOBJS-$(CONFIG_VIDEODSP) += videodsp.o # decoders/encoders -AVCODECOBJS-$(CONFIG_DCA_DECODER) += dcadsp.o synth_filter.o -AVCODECOBJS-$(CONFIG_HEVC_DECODER) += hevc_add_res.o hevc_idct.o hevc_mc.o +AVCODECOBJS-$(CONFIG_AAC_DECODER) += aacpsdsp.o \ + sbrdsp.o +AVCODECOBJS-$(CONFIG_ALAC_DECODER) += alacdsp.o +AVCODECOBJS-$(CONFIG_DCA_DECODER) += synth_filter.o +AVCODECOBJS-$(CONFIG_EXR_DECODER) += exrdsp.o +AVCODECOBJS-$(CONFIG_JPEG2000_DECODER) += jpeg2000dsp.o +AVCODECOBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o +AVCODECOBJS-$(CONFIG_HEVC_DECODER) += hevc_add_res.o hevc_idct.o AVCODECOBJS-$(CONFIG_V210_ENCODER) += v210enc.o AVCODECOBJS-$(CONFIG_VP9_DECODER) += vp9dsp.o CHECKASMOBJS-$(CONFIG_AVCODEC) += $(AVCODECOBJS-yes) +# libavfilter tests +AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o +AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o + +CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes) + +AVUTILOBJS += fixed_dsp.o +AVUTILOBJS += float_dsp.o + +CHECKASMOBJS-$(CONFIG_AVUTIL) += $(AVUTILOBJS) CHECKASMOBJS-$(ARCH_AARCH64) += aarch64/checkasm.o CHECKASMOBJS-$(HAVE_ARMV5TE_EXTERNAL) += arm/checkasm.o @@ -32,14 +51,16 @@ CHECKASMDIRS := $(sort $(dir $(CHECKASMOBJS))) $(CHECKASMOBJS): | $(CHECKASMDIRS) OBJDIRS += $(CHECKASMDIRS) +tests/checkasm/checkasm.o: CFLAGS += -Umain + CHECKASM := tests/checkasm/checkasm$(EXESUF) $(CHECKASM): $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) - $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avutil) $(EXTRALIBS) + $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avfilter) $(EXTRALIBS-avutil) $(EXTRALIBS) checkasm: $(CHECKASM) -clean:: checkasmclean +testclean:: checkasmclean checkasmclean: $(RM) $(CHECKASM) $(CLEANSUFFIXES:%=tests/checkasm/%) $(CLEANSUFFIXES:%=tests/checkasm/$(ARCH)/%) diff --git a/tests/checkasm/aacpsdsp.c b/tests/checkasm/aacpsdsp.c new file mode 100644 index 0000000000..ea68b39fa9 --- /dev/null +++ b/tests/checkasm/aacpsdsp.c @@ -0,0 +1,243 @@ +/* + * 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 "libavcodec/aacpsdsp.h" + +#include "checkasm.h" + +#define N 32 +#define STRIDE 128 +#define BUF_SIZE (N * STRIDE) + +#define randomize(buf, len) do { \ + int i; \ + for (i = 0; i < len; i++) { \ + const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \ + (buf)[i] = f; \ + } \ +} while (0) + +#define EPS 0.005 + +static void test_add_squares(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE]); + LOCAL_ALIGNED_16(INTFLOAT, src, [BUF_SIZE], [2]); + + declare_func(void, INTFLOAT *dst, + const INTFLOAT (*src)[2], int n); + + randomize((INTFLOAT *)src, BUF_SIZE * 2); + randomize(dst0, BUF_SIZE); + memcpy(dst1, dst0, BUF_SIZE * sizeof(INTFLOAT)); + call_ref(dst0, src, BUF_SIZE); + call_new(dst1, src, BUF_SIZE); + if (!float_near_abs_eps_array(dst0, dst1, EPS, BUF_SIZE)) + fail(); + bench_new(dst1, src, BUF_SIZE); +} + +static void test_mul_pair_single(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, src0, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, src1, [BUF_SIZE]); + + declare_func(void, INTFLOAT (*dst)[2], + INTFLOAT (*src0)[2], INTFLOAT *src1, int n); + + randomize((INTFLOAT *)src0, BUF_SIZE * 2); + randomize(src1, BUF_SIZE); + call_ref(dst0, src0, src1, BUF_SIZE); + call_new(dst1, src0, src1, BUF_SIZE); + if (!float_near_abs_eps_array((float *)dst0, (float *)dst1, EPS, BUF_SIZE * 2)) + fail(); + bench_new(dst1, src0, src1, BUF_SIZE); +} + +static void test_hybrid_analysis(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, dst0, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, in, [13], [2]); + LOCAL_ALIGNED_16(INTFLOAT, filter, [N], [8][2]); + + declare_func(void, INTFLOAT (*out)[2], INTFLOAT (*in)[2], + const INTFLOAT (*filter)[8][2], + ptrdiff_t stride, int n); + + randomize((INTFLOAT *)in, 13 * 2); + randomize((INTFLOAT *)filter, N * 8 * 2); + + randomize((INTFLOAT *)dst0, BUF_SIZE * 2); + memcpy(dst1, dst0, BUF_SIZE * 2 * sizeof(INTFLOAT)); + + call_ref(dst0, in, filter, STRIDE, N); + call_new(dst1, in, filter, STRIDE, N); + + if (!float_near_abs_eps_array((float *)dst0, (float *)dst1, EPS, BUF_SIZE * 2)) + fail(); + bench_new(dst1, in, filter, STRIDE, N); +} + +static void test_hybrid_analysis_ileave(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, in, [2], [38][64]); + LOCAL_ALIGNED_16(INTFLOAT, out0, [91], [32][2]); + LOCAL_ALIGNED_16(INTFLOAT, out1, [91], [32][2]); + + declare_func(void, INTFLOAT (*out)[32][2], INTFLOAT L[2][38][64], + int i, int len); + + randomize((INTFLOAT *)out0, 91 * 32 * 2); + randomize((INTFLOAT *)in, 2 * 38 * 64); + memcpy(out1, out0, 91 * 32 * 2 * sizeof(INTFLOAT)); + + /* len is hardcoded to 32 as that's the only value used in + libavcodec. asm functions are likely to be optimized + hardcoding this value in their loops and could fail with + anything else. + i is hardcoded to the two values currently used by the + aac decoder because the arm neon implementation is + micro-optimized for them and will fail for almost every + other value. */ + call_ref(out0, in, 3, 32); + call_new(out1, in, 3, 32); + + /* the function just moves data around, so memcmp is enough */ + if (memcmp(out0, out1, 91 * 32 * 2 * sizeof(INTFLOAT))) + fail(); + + call_ref(out0, in, 5, 32); + call_new(out1, in, 5, 32); + + if (memcmp(out0, out1, 91 * 32 * 2 * sizeof(INTFLOAT))) + fail(); + + bench_new(out1, in, 3, 32); +} + +static void test_hybrid_synthesis_deint(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, out0, [2], [38][64]); + LOCAL_ALIGNED_16(INTFLOAT, out1, [2], [38][64]); + LOCAL_ALIGNED_16(INTFLOAT, in, [91], [32][2]); + + declare_func(void, INTFLOAT out[2][38][64], INTFLOAT (*in)[32][2], + int i, int len); + + randomize((INTFLOAT *)in, 91 * 32 * 2); + randomize((INTFLOAT *)out0, 2 * 38 * 64); + memcpy(out1, out0, 2 * 38 * 64 * sizeof(INTFLOAT)); + + /* len is hardcoded to 32 as that's the only value used in + libavcodec. asm functions are likely to be optimized + hardcoding this value in their loops and could fail with + anything else. + i is hardcoded to the two values currently used by the + aac decoder because the arm neon implementation is + micro-optimized for them and will fail for almost every + other value. */ + call_ref(out0, in, 3, 32); + call_new(out1, in, 3, 32); + + /* the function just moves data around, so memcmp is enough */ + if (memcmp(out0, out1, 2 * 38 * 64 * sizeof(INTFLOAT))) + fail(); + + call_ref(out0, in, 5, 32); + call_new(out1, in, 5, 32); + + if (memcmp(out0, out1, 2 * 38 * 64 * sizeof(INTFLOAT))) + fail(); + + bench_new(out1, in, 3, 32); +} + +static void test_stereo_interpolate(PSDSPContext *psdsp) +{ + int i; + LOCAL_ALIGNED_16(INTFLOAT, l, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, r, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, l0, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, r0, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, l1, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, r1, [BUF_SIZE], [2]); + LOCAL_ALIGNED_16(INTFLOAT, h, [2], [4]); + LOCAL_ALIGNED_16(INTFLOAT, h_step, [2], [4]); + + declare_func(void, INTFLOAT (*l)[2], INTFLOAT (*r)[2], + INTFLOAT h[2][4], INTFLOAT h_step[2][4], int len); + + randomize((INTFLOAT *)l, BUF_SIZE * 2); + randomize((INTFLOAT *)r, BUF_SIZE * 2); + + for (i = 0; i < 2; i++) { + if (check_func(psdsp->stereo_interpolate[i], "ps_stereo_interpolate%s", i ? "_ipdopd" : "")) { + memcpy(l0, l, BUF_SIZE * 2 * sizeof(INTFLOAT)); + memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT)); + memcpy(r0, r, BUF_SIZE * 2 * sizeof(INTFLOAT)); + memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT)); + + randomize((INTFLOAT *)h, 2 * 4); + randomize((INTFLOAT *)h_step, 2 * 4); + + call_ref(l0, r0, h, h_step, BUF_SIZE); + call_new(l1, r1, h, h_step, BUF_SIZE); + if (!float_near_abs_eps_array((float *)l0, (float *)l1, EPS, BUF_SIZE * 2) || + !float_near_abs_eps_array((float *)r0, (float *)r1, EPS, BUF_SIZE * 2)) + fail(); + + memcpy(l1, l, BUF_SIZE * 2 * sizeof(INTFLOAT)); + memcpy(r1, r, BUF_SIZE * 2 * sizeof(INTFLOAT)); + bench_new(l1, r1, h, h_step, BUF_SIZE); + } + } +} + +void checkasm_check_aacpsdsp(void) +{ + PSDSPContext psdsp; + + ff_psdsp_init(&psdsp); + + if (check_func(psdsp.add_squares, "ps_add_squares")) + test_add_squares(); + report("add_squares"); + + if (check_func(psdsp.mul_pair_single, "ps_mul_pair_single")) + test_mul_pair_single(); + report("mul_pair_single"); + + if (check_func(psdsp.hybrid_analysis, "ps_hybrid_analysis")) + test_hybrid_analysis(); + report("hybrid_analysis"); + + if (check_func(psdsp.hybrid_analysis_ileave, "ps_hybrid_analysis_ileave")) + test_hybrid_analysis_ileave(); + report("hybrid_analysis_ileave"); + + if (check_func(psdsp.hybrid_synthesis_deint, "ps_hybrid_synthesis_deint")) + test_hybrid_synthesis_deint(); + report("hybrid_synthesis_deint"); + + test_stereo_interpolate(&psdsp); + report("stereo_interpolate"); +} diff --git a/tests/checkasm/aarch64/checkasm.S b/tests/checkasm/aarch64/checkasm.S index bc5ed9ea09..75a9a56143 100644 --- a/tests/checkasm/aarch64/checkasm.S +++ b/tests/checkasm/aarch64/checkasm.S @@ -3,14 +3,14 @@ * Copyright (c) 2015 Martin Storsjo * Copyright (c) 2015 Janne Grunau * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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. @@ -112,10 +112,10 @@ function checkasm_checked_call, export=1 movi v3.8h, #0 .macro check_reg_neon reg1, reg2 - ldr q0, [x9], #16 - uzp1 v1.2d, v\reg1\().2d, v\reg2\().2d - eor v0.16b, v0.16b, v1.16b - orr v3.16b, v3.16b, v0.16b + ldr q1, [x9], #16 + uzp1 v2.2d, v\reg1\().2d, v\reg2\().2d + eor v1.16b, v1.16b, v2.16b + orr v3.16b, v3.16b, v1.16b .endm check_reg_neon 8, 9 check_reg_neon 10, 11 diff --git a/tests/checkasm/alacdsp.c b/tests/checkasm/alacdsp.c new file mode 100644 index 0000000000..cbf03f82e8 --- /dev/null +++ b/tests/checkasm/alacdsp.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015 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/alacdsp.h" +#include "libavcodec/mathops.h" +#include "libavutil/common.h" +#include "libavutil/internal.h" + +#define BUF_SIZE 256 +#define MAX_CHANNELS 2 + +#define randomize_buffers() \ + do { \ + int i; \ + for (i = 0; i < BUF_SIZE*MAX_CHANNELS; i++) { \ + int32_t r = sign_extend(rnd(), 24); \ + ref_buf[i] = r; \ + new_buf[i] = r; \ + } \ + } while (0) + +static void check_decorrelate_stereo(void) +{ + LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]); + LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS]); + int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] }; + int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] }; + ALACDSPContext c; + + ff_alacdsp_init(&c); + if (check_func(c.decorrelate_stereo, "alac_decorrelate_stereo")) { + int len = (rnd() & 0xFF) + 1; + int shift = rnd() & 0x1F; + int weight = rnd() & 0xFF; + declare_func(void, int32_t *buf[2], int len, int shift, int weight); + + randomize_buffers(); + call_ref(ref, len, shift, weight); + call_new(new, len, shift, weight); + if (memcmp(ref[0], new[0], len * sizeof(int32_t)) || + memcmp(ref[1], new[1], len * sizeof(int32_t))) + fail(); + bench_new(new, BUF_SIZE, shift, weight); + } + + report("decorrelate_stereo"); +} + +#undef randomize_buffers +#define randomize_buffers() \ + do { \ + int i, j; \ + for (i = 0; i < BUF_SIZE; i++) { \ + for (j = 0; j < ch; j++) { \ + int32_t r = sign_extend(rnd(), 24); \ + ref[j][i] = r; \ + new[j][i] = r; \ + r = rnd() & 0xFF; \ + ref_ebb[j][i] = r; \ + new_ebb[j][i] = r; \ + } \ + } \ + } while (0) + +static void check_append_extra_bits(void) +{ + LOCAL_ALIGNED_16(int32_t, ref_buf, [BUF_SIZE*MAX_CHANNELS*2]); + LOCAL_ALIGNED_16(int32_t, new_buf, [BUF_SIZE*MAX_CHANNELS*2]); + int32_t *ref[2] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1] }; + int32_t *new[2] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1] }; + int32_t *ref_ebb[2] = { &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3] }; + int32_t *new_ebb[2] = { &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3] }; + ALACDSPContext c; + static const char * const channels[2] = { "mono", "stereo" }; + int ch; + + ff_alacdsp_init(&c); + for (ch = 1; ch <= 2; ch++) { + if (check_func(c.append_extra_bits[ch-1], "alac_append_extra_bits_%s", channels[ch-1])) { + int len = (rnd() & 0xFF) + 1; + declare_func(void, int32_t *buf[2], int32_t *ebb[2], int ebits, int ch, int len); + + randomize_buffers(); + call_ref(ref, ref_ebb, 8, ch, len); + call_new(new, new_ebb, 8, ch, len); + if ( memcmp(ref[0], new[0], len * sizeof(int32_t)) || + (ch == 2 && memcmp(ref[1], new[1], len * sizeof(int32_t)))) + fail(); + bench_new(new, new_ebb, 8, ch, BUF_SIZE); + } + } + + report("append_extra_bits"); +} + +void checkasm_check_alacdsp(void) +{ + check_decorrelate_stereo(); + check_append_extra_bits(); +} diff --git a/tests/checkasm/arm/checkasm.S b/tests/checkasm/arm/checkasm.S index 237252f978..2051b290f6 100644 --- a/tests/checkasm/arm/checkasm.S +++ b/tests/checkasm/arm/checkasm.S @@ -3,14 +3,14 @@ * Copyright (c) 2015 Martin Storsjo * Copyright (c) 2015 Janne Grunau * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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. diff --git a/tests/checkasm/audiodsp.c b/tests/checkasm/audiodsp.c index 40fa3844e8..7c4e16e40d 100644 --- a/tests/checkasm/audiodsp.c +++ b/tests/checkasm/audiodsp.c @@ -1,18 +1,18 @@ /* - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/blockdsp.c b/tests/checkasm/blockdsp.c index f10e2ff578..c753506b3c 100644 --- a/tests/checkasm/blockdsp.c +++ b/tests/checkasm/blockdsp.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2015 Henrik Gramner * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ @@ -53,11 +53,13 @@ do { \ void checkasm_check_blockdsp(void) { - LOCAL_ALIGNED_16(uint16_t, buf0, [6 * 8 * 8]); - LOCAL_ALIGNED_16(uint16_t, buf1, [6 * 8 * 8]); + LOCAL_ALIGNED_32(uint16_t, buf0, [6 * 8 * 8]); + LOCAL_ALIGNED_32(uint16_t, buf1, [6 * 8 * 8]); + + AVCodecContext avctx = { 0 }; BlockDSPContext h; - ff_blockdsp_init(&h); + ff_blockdsp_init(&h, &avctx); check_clear(clear_block, 8 * 8); check_clear(clear_blocks, 8 * 8 * 6); diff --git a/tests/checkasm/bswapdsp.c b/tests/checkasm/bswapdsp.c index 829ebaa8a8..5f7555037d 100644 --- a/tests/checkasm/bswapdsp.c +++ b/tests/checkasm/bswapdsp.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2015 Henrik Gramner * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 61515deb88..b8b0e32dbd 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -3,23 +3,31 @@ * Copyright (c) 2015 Henrik Gramner * Copyright (c) 2008 Loren Merritt * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" + +#if CONFIG_LINUX_PERF +# ifndef _GNU_SOURCE +# define _GNU_SOURCE // for syscall (performance monitoring API) +# endif +#endif + #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -64,47 +72,84 @@ static const struct { const char *name; void (*func)(void); } tests[] = { -#if CONFIG_AUDIODSP - { "audiodsp", checkasm_check_audiodsp }, -#endif -#if CONFIG_BLOCKDSP - { "blockdsp", checkasm_check_blockdsp }, -#endif -#if CONFIG_BSWAPDSP - { "bswapdsp", checkasm_check_bswapdsp }, -#endif -#if CONFIG_DCA_DECODER - { "dcadsp", checkasm_check_dcadsp }, - { "synth_filter", checkasm_check_synth_filter }, -#endif -#if CONFIG_FMTCONVERT - { "fmtconvert", checkasm_check_fmtconvert }, -#endif -#if CONFIG_H264DSP - { "h264dsp", checkasm_check_h264dsp }, +#if CONFIG_AVCODEC + #if CONFIG_AAC_DECODER + { "aacpsdsp", checkasm_check_aacpsdsp }, + { "sbrdsp", checkasm_check_sbrdsp }, + #endif + #if CONFIG_ALAC_DECODER + { "alacdsp", checkasm_check_alacdsp }, + #endif + #if CONFIG_AUDIODSP + { "audiodsp", checkasm_check_audiodsp }, + #endif + #if CONFIG_BLOCKDSP + { "blockdsp", checkasm_check_blockdsp }, + #endif + #if CONFIG_BSWAPDSP + { "bswapdsp", checkasm_check_bswapdsp }, + #endif + #if CONFIG_DCA_DECODER + { "synth_filter", checkasm_check_synth_filter }, + #endif + #if CONFIG_EXR_DECODER + { "exrdsp", checkasm_check_exrdsp }, + #endif + #if CONFIG_FLACDSP + { "flacdsp", checkasm_check_flacdsp }, + #endif + #if CONFIG_FMTCONVERT + { "fmtconvert", checkasm_check_fmtconvert }, + #endif + #if CONFIG_G722DSP + { "g722dsp", checkasm_check_g722dsp }, + #endif + #if CONFIG_H264DSP + { "h264dsp", checkasm_check_h264dsp }, + #endif + #if CONFIG_H264PRED + { "h264pred", checkasm_check_h264pred }, + #endif + #if CONFIG_H264QPEL + { "h264qpel", checkasm_check_h264qpel }, + #endif + #if CONFIG_HEVC_DECODER + { "hevc_add_res", checkasm_check_hevc_add_res }, + { "hevc_idct", checkasm_check_hevc_idct }, + #endif + #if CONFIG_JPEG2000_DECODER + { "jpeg2000dsp", checkasm_check_jpeg2000dsp }, + #endif + #if CONFIG_HUFFYUVDSP + { "llviddsp", checkasm_check_llviddsp }, + #endif + #if CONFIG_PIXBLOCKDSP + { "pixblockdsp", checkasm_check_pixblockdsp }, + #endif + #if CONFIG_V210_ENCODER + { "v210enc", checkasm_check_v210enc }, + #endif + #if CONFIG_VP8DSP + { "vp8dsp", checkasm_check_vp8dsp }, + #endif + #if CONFIG_VP9_DECODER + { "vp9dsp", checkasm_check_vp9dsp }, + #endif + #if CONFIG_VIDEODSP + { "videodsp", checkasm_check_videodsp }, + #endif #endif -#if CONFIG_H264PRED - { "h264pred", checkasm_check_h264pred }, +#if CONFIG_AVFILTER + #if CONFIG_BLEND_FILTER + { "vf_blend", checkasm_check_blend }, + #endif + #if CONFIG_COLORSPACE_FILTER + { "vf_colorspace", checkasm_check_colorspace }, + #endif #endif -#if CONFIG_H264QPEL - { "h264qpel", checkasm_check_h264qpel }, -#endif -#if CONFIG_HEVC_DECODER - { "hevc_add_res", checkasm_check_hevc_add_res }, - { "hevc_idct", checkasm_check_hevc_idct }, - { "hevc_mc", checkasm_check_hevc_mc }, -#endif -#if CONFIG_HUFFYUVDSP - { "huffyuvdsp", checkasm_check_huffyuvdsp }, -#endif -#if CONFIG_V210_ENCODER - { "v210enc", checkasm_check_v210enc }, -#endif -#if CONFIG_VP8DSP - { "vp8dsp", checkasm_check_vp8dsp }, -#endif -#if CONFIG_VP9_DECODER - { "vp9dsp", checkasm_check_vp9dsp }, +#if CONFIG_AVUTIL + { "fixed_dsp", checkasm_check_fixed_dsp }, + { "float_dsp", checkasm_check_float_dsp }, #endif { NULL } }; @@ -141,6 +186,7 @@ static const struct { { "SSSE3", "ssse3", AV_CPU_FLAG_SSSE3|AV_CPU_FLAG_ATOM }, { "SSE4.1", "sse4", AV_CPU_FLAG_SSE4 }, { "SSE4.2", "sse42", AV_CPU_FLAG_SSE42 }, + { "AES-NI", "aesni", AV_CPU_FLAG_AESNI }, { "AVX", "avx", AV_CPU_FLAG_AVX }, { "XOP", "xop", AV_CPU_FLAG_XOP }, { "FMA3", "fma3", AV_CPU_FLAG_FMA3 }, @@ -155,8 +201,7 @@ typedef struct CheckasmFuncVersion { void *func; int ok; int cpu; - int iterations; - uint64_t cycles; + CheckasmPerf perf; } CheckasmFuncVersion; /* Binary search tree node */ @@ -177,7 +222,11 @@ static struct { int bench_pattern_len; int num_checked; int num_failed; + + /* perf */ int nop_time; + int sysfd; + int cpu_flag; const char *cpu_flag_name; const char *test_name; @@ -258,6 +307,25 @@ int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps, return 1; } +int double_near_abs_eps(double a, double b, double eps) +{ + double abs_diff = fabs(a - b); + + return abs_diff < eps; +} + +int double_near_abs_eps_array(const double *a, const double *b, double eps, + unsigned len) +{ + unsigned i; + + for (i = 0; i < len; i++) { + if (!double_near_abs_eps(a[i], b[i], eps)) + return 0; + } + return 1; +} + /* Print colored text to stderr if the terminal supports it */ static void color_printf(int color, const char *fmt, ...) { @@ -342,7 +410,6 @@ static const char *cpu_suffix(int cpu) return "c"; } -#ifdef AV_READ_TIME static int cmp_nop(const void *a, const void *b) { return *(const uint16_t*)a - *(const uint16_t*)b; @@ -353,10 +420,13 @@ static int measure_nop_time(void) { uint16_t nops[10000]; int i, nop_sum = 0; + av_unused const int sysfd = state.sysfd; + uint64_t t = 0; for (i = 0; i < 10000; i++) { - uint64_t t = AV_READ_TIME(); - nops[i] = AV_READ_TIME() - t; + PERF_START(t); + PERF_STOP(t); + nops[i] = t; } qsort(nops, 10000, sizeof(uint16_t), cmp_nop); @@ -376,8 +446,9 @@ static void print_benchs(CheckasmFunc *f) if (f->versions.cpu || f->versions.next) { CheckasmFuncVersion *v = &f->versions; do { - if (v->iterations) { - int decicycles = (10*v->cycles/v->iterations - state.nop_time) / 4; + CheckasmPerf *p = &v->perf; + if (p->iterations) { + int decicycles = (10*p->cycles/p->iterations - state.nop_time) / 4; printf("%s_%s: %d.%d\n", f->name, cpu_suffix(v->cpu), decicycles/10, decicycles%10); } } while ((v = v->next)); @@ -386,7 +457,6 @@ static void print_benchs(CheckasmFunc *f) print_benchs(f->child[1]); } } -#endif /* ASCIIbetical sort except preserving natural order for numbers */ static int cmp_func_names(const char *a, const char *b) @@ -463,8 +533,9 @@ static void check_cpu_flag(const char *name, int flag) int old_cpu_flag = state.cpu_flag; flag |= old_cpu_flag; - av_set_cpu_flags_mask(flag); - state.cpu_flag = av_get_cpu_flags(); + av_force_cpu_flags(-1); + state.cpu_flag = flag & av_get_cpu_flags(); + av_force_cpu_flags(state.cpu_flag); if (!flag || state.cpu_flag != old_cpu_flag) { int i; @@ -488,6 +559,63 @@ static void print_cpu_name(void) } } +#if CONFIG_LINUX_PERF +static int bench_init_linux(void) +{ + struct perf_event_attr attr = { + .type = PERF_TYPE_HARDWARE, + .size = sizeof(struct perf_event_attr), + .config = PERF_COUNT_HW_CPU_CYCLES, + .disabled = 1, // start counting only on demand + .exclude_kernel = 1, + .exclude_hv = 1, + }; + + printf("benchmarking with Linux Perf Monitoring API\n"); + + state.sysfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0); + if (state.sysfd == -1) { + perror("syscall"); + return -1; + } + return 0; +} +#endif + +static int bench_init_ffmpeg(void) +{ +#ifdef AV_READ_TIME + printf("benchmarking with native FFmpeg timers\n"); + return 0; +#else + fprintf(stderr, "checkasm: --bench is not supported on your system\n"); + return -1; +#endif +} + +static int bench_init(void) +{ +#if CONFIG_LINUX_PERF + int ret = bench_init_linux(); +#else + int ret = bench_init_ffmpeg(); +#endif + if (ret < 0) + return ret; + + state.nop_time = measure_nop_time(); + printf("nop: %d.%d\n", state.nop_time/10, state.nop_time%10); + return 0; +} + +static void bench_uninit(void) +{ +#if CONFIG_LINUX_PERF + if (state.sysfd > 0) + close(state.sysfd); +#endif +} + int main(int argc, char *argv[]) { unsigned int seed = av_get_random_seed(); @@ -505,10 +633,8 @@ int main(int argc, char *argv[]) while (argc > 1) { if (!strncmp(argv[1], "--bench", 7)) { -#ifndef AV_READ_TIME - fprintf(stderr, "checkasm: --bench is not supported on your system\n"); - return 1; -#endif + if (bench_init() < 0) + return 1; if (argv[1][7] == '=') { state.bench_pattern = argv[1] + 8; state.bench_pattern_len = strlen(state.bench_pattern); @@ -536,16 +662,13 @@ int main(int argc, char *argv[]) ret = 1; } else { fprintf(stderr, "checkasm: all %d tests passed\n", state.num_checked); -#ifdef AV_READ_TIME if (state.bench_pattern) { - state.nop_time = measure_nop_time(); - printf("nop: %d.%d\n", state.nop_time/10, state.nop_time%10); print_benchs(state.funcs); } -#endif } destroy_func_tree(state.funcs); + bench_uninit(); return ret; } @@ -623,11 +746,13 @@ void checkasm_fail_func(const char *msg, ...) } } -/* Update benchmark results of the current function */ -void checkasm_update_bench(int iterations, uint64_t cycles) +/* Get the benchmark context of the current function */ +CheckasmPerf *checkasm_get_perf_context(void) { - state.current_func_ver->iterations += iterations; - state.current_func_ver->cycles += cycles; + CheckasmPerf *perf = &state.current_func_ver->perf; + memset(perf, 0, sizeof(*perf)); + perf->sysfd = state.sysfd; + return perf; } /* Print the outcome of all tests performed since the last time this function was called */ diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index db71382ac3..e5b1877dc0 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -3,20 +3,20 @@ * Copyright (c) 2015 Henrik Gramner * Copyright (c) 2008 Loren Merritt * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ @@ -25,33 +25,54 @@ #include <stdint.h> #include "config.h" + +#if CONFIG_LINUX_PERF +#include <unistd.h> // read(3) +#include <sys/ioctl.h> +#include <asm/unistd.h> +#include <linux/perf_event.h> +#endif + #include "libavutil/avstring.h" #include "libavutil/cpu.h" #include "libavutil/internal.h" #include "libavutil/lfg.h" #include "libavutil/timer.h" +void checkasm_check_aacpsdsp(void); +void checkasm_check_alacdsp(void); void checkasm_check_audiodsp(void); +void checkasm_check_blend(void); void checkasm_check_blockdsp(void); void checkasm_check_bswapdsp(void); -void checkasm_check_dcadsp(void); +void checkasm_check_colorspace(void); +void checkasm_check_exrdsp(void); +void checkasm_check_fixed_dsp(void); +void checkasm_check_flacdsp(void); +void checkasm_check_float_dsp(void); void checkasm_check_fmtconvert(void); +void checkasm_check_g722dsp(void); void checkasm_check_h264dsp(void); void checkasm_check_h264pred(void); void checkasm_check_h264qpel(void); void checkasm_check_hevc_add_res(void); void checkasm_check_hevc_idct(void); -void checkasm_check_hevc_mc(void); -void checkasm_check_huffyuvdsp(void); +void checkasm_check_jpeg2000dsp(void); +void checkasm_check_llviddsp(void); +void checkasm_check_pixblockdsp(void); +void checkasm_check_sbrdsp(void); void checkasm_check_synth_filter(void); void checkasm_check_v210enc(void); void checkasm_check_vp8dsp(void); void checkasm_check_vp9dsp(void); +void checkasm_check_videodsp(void); + +struct CheckasmPerf; void *checkasm_check_func(void *func, const char *name, ...) av_printf_format(2, 3); int checkasm_bench_func(void); void checkasm_fail_func(const char *msg, ...) av_printf_format(1, 2); -void checkasm_update_bench(int iterations, uint64_t cycles); +struct CheckasmPerf *checkasm_get_perf_context(void); void checkasm_report(const char *name, ...) av_printf_format(1, 2); /* float compare utilities */ @@ -64,6 +85,9 @@ int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len); int float_near_abs_eps_array_ulp(const float *a, const float *b, float eps, unsigned max_ulp, unsigned len); +int double_near_abs_eps(double a, double b, double eps); +int double_near_abs_eps_array(const double *a, const double *b, double eps, + unsigned len); extern AVLFG checkasm_lfg; #define rnd() av_lfg_get(&checkasm_lfg) @@ -78,6 +102,7 @@ static av_unused void *func_ref, *func_new; /* Declare the function prototype. The first argument is the return value, the remaining * arguments are the function parameters. Naming parameters is optional. */ #define declare_func(ret, ...) declare_new(ret, __VA_ARGS__) typedef ret func_type(__VA_ARGS__) +#define declare_func_float(ret, ...) declare_new_float(ret, __VA_ARGS__) typedef ret func_type(__VA_ARGS__) #define declare_func_emms(cpu_flags, ret, ...) declare_new_emms(cpu_flags, ret, __VA_ARGS__) typedef ret func_type(__VA_ARGS__) /* Indicate that the current test has failed */ @@ -96,6 +121,9 @@ void checkasm_checked_call(void *func, ...); /* Verifies that clobbered callee-saved registers are properly saved and restored * and issues emms for asm functions which are not required to do so */ void checkasm_checked_call_emms(void *func, ...); +/* Verifies that clobbered callee-saved registers are properly saved and restored + * but doesn't issue emms. Meant for dsp functions returning float or double */ +void checkasm_checked_call_float(void *func, ...); #if ARCH_X86_64 /* Evil hack: detect incorrect assumptions that 32-bit ints are zero-extended to 64-bit. @@ -110,6 +138,8 @@ void checkasm_checked_call_emms(void *func, ...); void checkasm_stack_clobber(uint64_t clobber, ...); #define declare_new(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, __VA_ARGS__)\ = (void *)checkasm_checked_call; +#define declare_new_float(ret, ...) ret (*checked_call)(void *, int, int, int, int, int, __VA_ARGS__)\ + = (void *)checkasm_checked_call_float; #define declare_new_emms(cpu_flags, ret, ...) \ ret (*checked_call)(void *, int, int, int, int, int, __VA_ARGS__) = \ ((cpu_flags) & av_get_cpu_flags()) ? (void *)checkasm_checked_call_emms : \ @@ -120,6 +150,7 @@ void checkasm_stack_clobber(uint64_t clobber, ...); checked_call(func_new, 0, 0, 0, 0, 0, __VA_ARGS__)) #elif ARCH_X86_32 #define declare_new(ret, ...) ret (*checked_call)(void *, __VA_ARGS__) = (void *)checkasm_checked_call; +#define declare_new_float(ret, ...) ret (*checked_call)(void *, __VA_ARGS__) = (void *)checkasm_checked_call_float; #define declare_new_emms(cpu_flags, ret, ...) ret (*checked_call)(void *, __VA_ARGS__) = \ ((cpu_flags) & av_get_cpu_flags()) ? (void *)checkasm_checked_call_emms : \ (void *)checkasm_checked_call; @@ -145,6 +176,7 @@ void checkasm_checked_call(void *func, ...); checked_call(func_new, 0, 0, 0, 0, 0, 0, 0, __VA_ARGS__)) #else #define declare_new(ret, ...) +#define declare_new_float(ret, ...) #define declare_new_emms(cpu_flags, ret, ...) /* Call the function */ #define call_new(...) ((func_type *)func_new)(__VA_ARGS__) @@ -153,33 +185,63 @@ void checkasm_checked_call(void *func, ...); #ifndef declare_new_emms #define declare_new_emms(cpu_flags, ret, ...) declare_new(ret, __VA_ARGS__) #endif +#ifndef declare_new_float +#define declare_new_float(ret, ...) declare_new(ret, __VA_ARGS__) +#endif + +typedef struct CheckasmPerf { + int sysfd; + uint64_t cycles; + int iterations; +} CheckasmPerf; + +#if defined(AV_READ_TIME) || CONFIG_LINUX_PERF + +#if CONFIG_LINUX_PERF +#define PERF_START(t) do { \ + ioctl(sysfd, PERF_EVENT_IOC_RESET, 0); \ + ioctl(sysfd, PERF_EVENT_IOC_ENABLE, 0); \ +} while (0) +#define PERF_STOP(t) do { \ + ioctl(sysfd, PERF_EVENT_IOC_DISABLE, 0); \ + read(sysfd, &t, sizeof(t)); \ +} while (0) +#else +#define PERF_START(t) t = AV_READ_TIME() +#define PERF_STOP(t) t = AV_READ_TIME() - t +#endif /* Benchmark the function */ -#ifdef AV_READ_TIME #define bench_new(...)\ do {\ if (checkasm_bench_func()) {\ + struct CheckasmPerf *perf = checkasm_get_perf_context();\ + av_unused const int sysfd = perf->sysfd;\ func_type *tfunc = func_new;\ uint64_t tsum = 0;\ int ti, tcount = 0;\ + uint64_t t = 0; \ for (ti = 0; ti < BENCH_RUNS; ti++) {\ - uint64_t t = AV_READ_TIME();\ + PERF_START(t);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ tfunc(__VA_ARGS__);\ - t = AV_READ_TIME() - t;\ + PERF_STOP(t);\ if (t*tcount <= tsum*4 && ti > 0) {\ tsum += t;\ tcount++;\ }\ }\ emms_c();\ - checkasm_update_bench(tcount, tsum);\ + perf->cycles += t;\ + perf->iterations++;\ }\ } while (0) #else #define bench_new(...) while(0) +#define PERF_START(t) while(0) +#define PERF_STOP(t) while(0) #endif #endif /* TESTS_CHECKASM_CHECKASM_H */ diff --git a/tests/checkasm/dcadsp.c b/tests/checkasm/dcadsp.c deleted file mode 100644 index 7251362a1e..0000000000 --- a/tests/checkasm/dcadsp.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2015 Janne Grunau - * - * This file is part of Libav. - * - * Libav 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. - * - * Libav 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 Libav; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <math.h> -#include <string.h> -#include <stdlib.h> - -#include "libavutil/internal.h" -#include "libavutil/intfloat.h" -#include "libavcodec/dca.h" -#include "libavcodec/dcadsp.h" -#include "libavcodec/dcadata.h" - -#include "checkasm.h" - -#define randomize_lfe_fir(size) \ - do { \ - int i; \ - for (i = 0; i < size; i++) { \ - float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f; \ - in[i] = f; \ - } \ - for (i = 0; i < 256; i++) { \ - float f = (float)rnd() / (UINT_MAX >> 1) - 1.0f; \ - coeffs[i] = f; \ - } \ - } while (0) - -#define check_lfe_fir(decifactor, eps) \ - do { \ - LOCAL_ALIGNED_16(float, in, [256 / decifactor]); \ - LOCAL_ALIGNED_16(float, out0, [decifactor * 2]); \ - LOCAL_ALIGNED_16(float, out1, [decifactor * 2]); \ - LOCAL_ALIGNED_16(float, coeffs, [256]); \ - int i; \ - const float * in_ptr = in + (256 / decifactor) - 1; \ - declare_func(void, float *out, const float *in, const float *coeffs); \ - /* repeat the test several times */ \ - for (i = 0; i < 32; i++) { \ - int j; \ - memset(out0, 0, sizeof(*out0) * 2 * decifactor); \ - memset(out1, 0xFF, sizeof(*out1) * 2 * decifactor); \ - randomize_lfe_fir(256 / decifactor); \ - call_ref(out0, in_ptr, coeffs); \ - call_new(out1, in_ptr, coeffs); \ - for (j = 0; j < 2 * decifactor; j++) { \ - if (!float_near_abs_eps(out0[j], out1[j], eps)) { \ - if (0) { \ - union av_intfloat32 x, y; x.f = out0[j]; y.f = out1[j]; \ - fprintf(stderr, "%3d: %11g (0x%08x); %11g (0x%08x)\n", \ - j, x.f, x.i, y.f, y.i); \ - } \ - fail(); \ - break; \ - } \ - } \ - bench_new(out1, in_ptr, coeffs); \ - } \ - } while (0) - -void checkasm_check_dcadsp(void) -{ - DCADSPContext c; - - ff_dcadsp_init(&c); - - /* values are limited to {-8, 8} so absolute epsilon is good enough */ - if (check_func(c.lfe_fir[0], "dca_lfe_fir0")) - check_lfe_fir(32, 1.0e-6f); - - if (check_func(c.lfe_fir[1], "dca_lfe_fir1")) - check_lfe_fir(64, 1.0e-6f); - - report("dcadsp"); -} diff --git a/tests/checkasm/exrdsp.c b/tests/checkasm/exrdsp.c new file mode 100644 index 0000000000..754a079f83 --- /dev/null +++ b/tests/checkasm/exrdsp.c @@ -0,0 +1,91 @@ +/* + * 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/avcodec.h" +#include "libavcodec/exrdsp.h" +#include "libavutil/intreadwrite.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"); +} diff --git a/tests/checkasm/fixed_dsp.c b/tests/checkasm/fixed_dsp.c new file mode 100644 index 0000000000..fa11f2e23f --- /dev/null +++ b/tests/checkasm/fixed_dsp.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2015 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 "checkasm.h" +#include "libavutil/common.h" +#include "libavutil/fixed_dsp.h" +#include "libavutil/internal.h" +#include "libavutil/mem.h" + +#define BUF_SIZE 256 + +#define randomize_buffers() \ + do { \ + int i; \ + for (i = 0; i < BUF_SIZE; i++) { \ + src0[i] = sign_extend(rnd(), 24); \ + src1[i] = sign_extend(rnd(), 24); \ + src2[i] = sign_extend(rnd(), 24); \ + } \ + } while (0) + +static void check_vector_fmul(const int *src0, const int *src1) +{ + LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]); + LOCAL_ALIGNED_32(int, new, [BUF_SIZE]); + + declare_func(void, int *dst, const int *src0, const int *src1, int len); + + call_ref(ref, src0, src1, BUF_SIZE); + call_new(new, src0, src1, BUF_SIZE); + if (memcmp(ref, new, BUF_SIZE * sizeof(int))) + fail(); + bench_new(new, src0, src1, BUF_SIZE); +} + +static void check_vector_fmul_add(const int *src0, const int *src1, const int *src2) +{ + LOCAL_ALIGNED_32(int, ref, [BUF_SIZE]); + LOCAL_ALIGNED_32(int, new, [BUF_SIZE]); + + declare_func(void, int *dst, const int *src0, const int *src1, const int *src2, int len); + + call_ref(ref, src0, src1, src2, BUF_SIZE); + call_new(new, src0, src1, src2, BUF_SIZE); + if (memcmp(ref, new, BUF_SIZE * sizeof(int))) + fail(); + bench_new(new, src0, src1, src2, BUF_SIZE); +} + +static void check_vector_fmul_window(const int32_t *src0, const int32_t *src1, const int32_t *win) +{ + LOCAL_ALIGNED_32(int32_t, ref, [BUF_SIZE]); + LOCAL_ALIGNED_32(int32_t, new, [BUF_SIZE]); + + declare_func(void, int32_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len); + + call_ref(ref, src0, src1, win, BUF_SIZE / 2); + call_new(new, src0, src1, win, BUF_SIZE / 2); + if (memcmp(ref, new, BUF_SIZE * sizeof(int32_t))) + fail(); + bench_new(new, src0, src1, win, BUF_SIZE / 2); +} + +static void check_vector_fmul_window_scaled(const int32_t *src0, const int32_t *src1, const int32_t *win) +{ + LOCAL_ALIGNED_16(int16_t, ref, [BUF_SIZE]); + LOCAL_ALIGNED_16(int16_t, new, [BUF_SIZE]); + + declare_func(void, int16_t *dst, const int32_t *src0, const int32_t *src1, const int32_t *win, int len, uint8_t bits); + + call_ref(ref, src0, src1, win, BUF_SIZE / 2, 2); + call_new(new, src0, src1, win, BUF_SIZE / 2, 2); + if (memcmp(ref, new, BUF_SIZE * sizeof(int16_t))) + fail(); + bench_new(new, src0, src1, win, BUF_SIZE / 2, 2); +} + +static void check_butterflies(const int *src0, const int *src1) +{ + LOCAL_ALIGNED_16(int, ref0, [BUF_SIZE]); + LOCAL_ALIGNED_16(int, ref1, [BUF_SIZE]); + LOCAL_ALIGNED_16(int, new0, [BUF_SIZE]); + LOCAL_ALIGNED_16(int, new1, [BUF_SIZE]); + + declare_func(void, int *av_restrict src0, int *av_restrict src1, int len); + + memcpy(ref0, src0, BUF_SIZE * sizeof(*src0)); + memcpy(ref1, src1, BUF_SIZE * sizeof(*src1)); + memcpy(new0, src0, BUF_SIZE * sizeof(*src0)); + memcpy(new1, src1, BUF_SIZE * sizeof(*src1)); + + call_ref(ref0, ref1, BUF_SIZE); + call_new(new0, new1, BUF_SIZE); + if (memcmp(ref0, new0, BUF_SIZE * sizeof(*ref0)) || + memcmp(ref1, new1, BUF_SIZE * sizeof(*ref1))) + fail(); + memcpy(new0, src0, BUF_SIZE * sizeof(*src0)); + memcpy(new1, src1, BUF_SIZE * sizeof(*src1)); + bench_new(new0, new1, BUF_SIZE); +} + +static void check_scalarproduct_fixed(const int *src0, const int *src1) +{ + int ref, new; + + declare_func(int, const int *src0, const int *src1, int len); + + ref = call_ref(src0, src1, BUF_SIZE); + new = call_new(src0, src1, BUF_SIZE); + if (ref != new) + fail(); + bench_new(src0, src1, BUF_SIZE); +} + +void checkasm_check_fixed_dsp(void) +{ + LOCAL_ALIGNED_32(int32_t, src0, [BUF_SIZE]); + LOCAL_ALIGNED_32(int32_t, src1, [BUF_SIZE]); + LOCAL_ALIGNED_32(int32_t, src2, [BUF_SIZE]); + AVFixedDSPContext *fdsp = avpriv_alloc_fixed_dsp(1); + + randomize_buffers(); + if (check_func(fdsp->vector_fmul, "vector_fmul_fixed")) + check_vector_fmul(src0, src1); + if (check_func(fdsp->vector_fmul_add, "vector_fmul_add_fixed")) + check_vector_fmul_add(src0, src1, src2); + if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse_fixed")) + check_vector_fmul(src0, src1); + if (check_func(fdsp->vector_fmul_window, "vector_fmul_window_fixed")) + check_vector_fmul_window(src0, src1, src2); + if (check_func(fdsp->vector_fmul_window_scaled, "vector_fmul_window_scaled_fixed")) + check_vector_fmul_window_scaled(src0, src1, src2); + report("vector_fmul"); + if (check_func(fdsp->butterflies_fixed, "butterflies_fixed")) + check_butterflies(src0, src1); + report("butterflies_fixed"); + if (check_func(fdsp->scalarproduct_fixed, "scalarproduct_fixed")) + check_scalarproduct_fixed(src0, src1); + report("scalarproduct_fixed"); + + av_freep(&fdsp); +} diff --git a/tests/checkasm/flacdsp.c b/tests/checkasm/flacdsp.c new file mode 100644 index 0000000000..dccb54d672 --- /dev/null +++ b/tests/checkasm/flacdsp.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2015 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/flacdsp.h" +#include "libavutil/common.h" +#include "libavutil/internal.h" +#include "libavutil/intreadwrite.h" + +#define BUF_SIZE 256 +#define MAX_CHANNELS 8 + +#define randomize_buffers() \ + do { \ + int i, j; \ + for (i = 0; i < BUF_SIZE; i += 4) { \ + for (j = 0; j < channels; j++) { \ + uint32_t r = rnd() & (1 << (bits - 2)) - 1; \ + AV_WN32A(ref_src[j] + i, r); \ + AV_WN32A(new_src[j] + i, r); \ + } \ + } \ + } while (0) + +static void check_decorrelate(uint8_t **ref_dst, uint8_t **ref_src, uint8_t **new_dst, uint8_t **new_src, + int channels, int bits) { + declare_func(void, uint8_t **out, int32_t **in, int channels, int len, int shift); + + randomize_buffers(); + call_ref(ref_dst, (int32_t **)ref_src, channels, BUF_SIZE / sizeof(int32_t), 8); + call_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8); + if (memcmp(*ref_dst, *new_dst, bits == 16 ? BUF_SIZE * (channels/2) : BUF_SIZE * channels) || + memcmp(*ref_src, *new_src, BUF_SIZE * channels)) + fail(); + bench_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8); +} + +void checkasm_check_flacdsp(void) +{ + LOCAL_ALIGNED_16(uint8_t, ref_dst, [BUF_SIZE*MAX_CHANNELS]); + LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]); + LOCAL_ALIGNED_16(uint8_t, new_dst, [BUF_SIZE*MAX_CHANNELS]); + LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS]); + uint8_t *ref_src[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1], &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3], + &ref_buf[BUF_SIZE*4], &ref_buf[BUF_SIZE*5], &ref_buf[BUF_SIZE*6], &ref_buf[BUF_SIZE*7] }; + uint8_t *new_src[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1], &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3], + &new_buf[BUF_SIZE*4], &new_buf[BUF_SIZE*5], &new_buf[BUF_SIZE*6], &new_buf[BUF_SIZE*7] }; + static const char * const names[3] = { "ls", "rs", "ms" }; + static const struct { + enum AVSampleFormat fmt; + int bits; + } fmts[] = { + { AV_SAMPLE_FMT_S16, 16 }, + { AV_SAMPLE_FMT_S32, 32 }, + }; + FLACDSPContext h; + int i, j; + + for (i = 0; i < 2; i++) { + ff_flacdsp_init(&h, fmts[i].fmt, 2, 0); + for (j = 0; j < 3; j++) + if (check_func(h.decorrelate[j], "flac_decorrelate_%s_%d", names[j], fmts[i].bits)) + check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, 2, fmts[i].bits); + for (j = 2; j <= MAX_CHANNELS; j += 2) { + ff_flacdsp_init(&h, fmts[i].fmt, j, 0); + if (check_func(h.decorrelate[0], "flac_decorrelate_indep%d_%d", j, fmts[i].bits)) + check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, j, fmts[i].bits); + } + } + + report("decorrelate"); +} diff --git a/tests/checkasm/float_dsp.c b/tests/checkasm/float_dsp.c new file mode 100644 index 0000000000..9b0a221c25 --- /dev/null +++ b/tests/checkasm/float_dsp.c @@ -0,0 +1,310 @@ +/* + * 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 "config.h" + +#include <float.h> +#include <stdint.h> + +#include "libavutil/float_dsp.h" +#include "libavutil/internal.h" +#include "checkasm.h" + +#define LEN 256 + +#define randomize_buffer(buf) \ +do { \ + int i; \ + double bmg[2], stddev = 10.0, mean = 0.0; \ + \ + for (i = 0; i < LEN; i += 2) { \ + av_bmg_get(&checkasm_lfg, bmg); \ + buf[i] = bmg[0] * stddev + mean; \ + buf[i + 1] = bmg[1] * stddev + mean; \ + } \ +} while(0); + +static void test_vector_fmul(const float *src0, const float *src1) +{ + LOCAL_ALIGNED_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src0, const float *src1, + int len); + + call_ref(cdst, src0, src1, LEN); + call_new(odst, src0, src1, LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1, LEN); +} + +#define ARBITRARY_FMUL_ADD_CONST 0.005 +static void test_vector_fmul_add(const float *src0, const float *src1, const float *src2) +{ + LOCAL_ALIGNED_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src0, const float *src1, + const float *src2, int len); + + call_ref(cdst, src0, src1, src2, LEN); + call_new(odst, src0, src1, src2, LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMUL_ADD_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1, src2, LEN); +} + +static void test_vector_fmul_scalar(const float *src0, const float *src1) +{ + LOCAL_ALIGNED_16(float, cdst, [LEN]); + LOCAL_ALIGNED_16(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src, float mul, int len); + + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1[0], LEN); +} + +#define ARBITRARY_FMUL_WINDOW_CONST 0.008 +static void test_vector_fmul_window(const float *src0, const float *src1, const float *win) +{ + LOCAL_ALIGNED_16(float, cdst, [LEN]); + LOCAL_ALIGNED_16(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src0, const float *src1, + const float *win, int len); + + call_ref(cdst, src0, src1, win, LEN / 2); + call_new(odst, src0, src1, win, LEN / 2); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMUL_WINDOW_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1, win, LEN / 2); +} + +#define ARBITRARY_FMAC_SCALAR_CONST 0.005 +static void test_vector_fmac_scalar(const float *src0, const float *src1, const float *src2) +{ + LOCAL_ALIGNED_32(float, cdst, [LEN]); + LOCAL_ALIGNED_32(float, odst, [LEN]); + int i; + + declare_func(void, float *dst, const float *src, float mul, int len); + + memcpy(cdst, src2, LEN * sizeof(*src2)); + memcpy(odst, src2, LEN * sizeof(*src2)); + + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], ARBITRARY_FMAC_SCALAR_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + memcpy(odst, src2, LEN * sizeof(*src2)); + bench_new(odst, src0, src1[0], LEN); +} + +static void test_vector_dmul_scalar(const double *src0, const double *src1) +{ + LOCAL_ALIGNED_32(double, cdst, [LEN]); + LOCAL_ALIGNED_32(double, odst, [LEN]); + int i; + + declare_func(void, double *dst, const double *src, double mul, int len); + + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!double_near_abs_eps(cdst[i], odst[i], DBL_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", i, + cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + bench_new(odst, src0, src1[0], LEN); +} + +#define ARBITRARY_DMAC_SCALAR_CONST 0.005 +static void test_vector_dmac_scalar(const double *src0, const double *src1, const double *src2) +{ + LOCAL_ALIGNED_32(double, cdst, [LEN]); + LOCAL_ALIGNED_32(double, odst, [LEN]); + int i; + + declare_func(void, double *dst, const double *src, double mul, int len); + + memcpy(cdst, src2, LEN * sizeof(*src2)); + memcpy(odst, src2, LEN * sizeof(*src2)); + call_ref(cdst, src0, src1[0], LEN); + call_new(odst, src0, src1[0], LEN); + for (i = 0; i < LEN; i++) { + if (!double_near_abs_eps(cdst[i], odst[i], ARBITRARY_DMAC_SCALAR_CONST)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fail(); + break; + } + } + memcpy(odst, src2, LEN * sizeof(*src2)); + bench_new(odst, src0, src1[0], LEN); +} + +static void test_butterflies_float(const float *src0, const float *src1) +{ + LOCAL_ALIGNED_16(float, cdst, [LEN]); + LOCAL_ALIGNED_16(float, odst, [LEN]); + LOCAL_ALIGNED_16(float, cdst1, [LEN]); + LOCAL_ALIGNED_16(float, odst1, [LEN]); + int i; + + declare_func(void, float *av_restrict src0, float *av_restrict src1, + int len); + + memcpy(cdst, src0, LEN * sizeof(*src0)); + memcpy(cdst1, src1, LEN * sizeof(*src1)); + memcpy(odst, src0, LEN * sizeof(*src0)); + memcpy(odst1, src1, LEN * sizeof(*src1)); + + call_ref(cdst, cdst1, LEN); + call_new(odst, odst1, LEN); + for (i = 0; i < LEN; i++) { + if (!float_near_abs_eps(cdst[i], odst[i], FLT_EPSILON) || + !float_near_abs_eps(cdst1[i], odst1[i], FLT_EPSILON)) { + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst[i], odst[i], cdst[i] - odst[i]); + fprintf(stderr, "%d: %- .12f - %- .12f = % .12g\n", + i, cdst1[i], odst1[i], cdst1[i] - odst1[i]); + fail(); + break; + } + } + memcpy(odst, src0, LEN * sizeof(*src0)); + memcpy(odst1, src1, LEN * sizeof(*src1)); + bench_new(odst, odst1, LEN); +} + +#define ARBITRARY_SCALARPRODUCT_CONST 0.2 +static void test_scalarproduct_float(const float *src0, const float *src1) +{ + float cprod, oprod; + + declare_func_float(float, const float *src0, const float *src1, int len); + + cprod = call_ref(src0, src1, LEN); + oprod = call_new(src0, src1, LEN); + if (!float_near_abs_eps(cprod, oprod, ARBITRARY_SCALARPRODUCT_CONST)) { + fprintf(stderr, "%- .12f - %- .12f = % .12g\n", + cprod, oprod, cprod - oprod); + fail(); + } + bench_new(src0, src1, LEN); +} + +void checkasm_check_float_dsp(void) +{ + LOCAL_ALIGNED_32(float, src0, [LEN]); + LOCAL_ALIGNED_32(float, src1, [LEN]); + LOCAL_ALIGNED_32(float, src2, [LEN]); + LOCAL_ALIGNED_16(float, src3, [LEN]); + LOCAL_ALIGNED_16(float, src4, [LEN]); + LOCAL_ALIGNED_16(float, src5, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src0, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src1, [LEN]); + LOCAL_ALIGNED_32(double, dbl_src2, [LEN]); + AVFloatDSPContext *fdsp = avpriv_float_dsp_alloc(1); + + if (!fdsp) { + fprintf(stderr, "floatdsp: Out of memory error\n"); + return; + } + + randomize_buffer(src0); + randomize_buffer(src1); + randomize_buffer(src2); + randomize_buffer(src3); + randomize_buffer(src4); + randomize_buffer(src5); + randomize_buffer(dbl_src0); + randomize_buffer(dbl_src1); + randomize_buffer(dbl_src2); + + if (check_func(fdsp->vector_fmul, "vector_fmul")) + test_vector_fmul(src0, src1); + if (check_func(fdsp->vector_fmul_add, "vector_fmul_add")) + test_vector_fmul_add(src0, src1, src2); + if (check_func(fdsp->vector_fmul_scalar, "vector_fmul_scalar")) + test_vector_fmul_scalar(src3, src4); + if (check_func(fdsp->vector_fmul_reverse, "vector_fmul_reverse")) + test_vector_fmul(src0, src1); + if (check_func(fdsp->vector_fmul_window, "vector_fmul_window")) + test_vector_fmul_window(src3, src4, src5); + report("vector_fmul"); + if (check_func(fdsp->vector_fmac_scalar, "vector_fmac_scalar")) + test_vector_fmac_scalar(src0, src1, src2); + report("vector_fmac"); + if (check_func(fdsp->vector_dmul_scalar, "vector_dmul_scalar")) + test_vector_dmul_scalar(dbl_src0, dbl_src1); + report("vector_dmul"); + if (check_func(fdsp->vector_dmac_scalar, "vector_dmac_scalar")) + test_vector_dmac_scalar(dbl_src0, dbl_src1, dbl_src2); + report("vector_dmac"); + if (check_func(fdsp->butterflies_float, "butterflies_float")) + test_butterflies_float(src3, src4); + report("butterflies_float"); + if (check_func(fdsp->scalarproduct_float, "scalarproduct_float")) + test_scalarproduct_float(src3, src4); + report("scalarproduct_float"); + + av_freep(&fdsp); +} diff --git a/tests/checkasm/fmtconvert.c b/tests/checkasm/fmtconvert.c index 1a843b0b02..50ad3ca2ea 100644 --- a/tests/checkasm/fmtconvert.c +++ b/tests/checkasm/fmtconvert.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2015 Janne Grunau * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/g722dsp.c b/tests/checkasm/g722dsp.c new file mode 100644 index 0000000000..6bcff11e3d --- /dev/null +++ b/tests/checkasm/g722dsp.c @@ -0,0 +1,63 @@ +/* + * 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/g722.h" +#include "libavcodec/g722dsp.h" +#include "libavcodec/mathops.h" + +#define randomize_buffers() \ + do { \ + int i; \ + for (i = 0; i < PREV_SAMPLES_BUF_SIZE; i++) { \ + src0[i] = src1[i] = sign_extend(rnd(), 16); \ + } \ + } while (0) + +static void check_qmf(void) { + int16_t src0[PREV_SAMPLES_BUF_SIZE]; + int16_t src1[PREV_SAMPLES_BUF_SIZE]; + const int16_t *tmp0 = src0; + const int16_t *tmp1 = src1; + int dst0[2], dst1[2]; + int i; + + declare_func(void, const int16_t *prev_samples, int xout[2]); + + randomize_buffers(); + for (i = 0; i < PREV_SAMPLES_BUF_SIZE - 24; i++) { + call_ref(tmp0++, dst0); + call_new(tmp1++, dst1); + if (memcmp(dst0, dst1, sizeof(dst0))) + fail(); + } + bench_new(src1, dst1); +} + +void checkasm_check_g722dsp(void) +{ + G722DSPContext h; + + ff_g722dsp_init(&h); + + if (check_func(h.apply_qmf, "g722_apply_qmf")) + check_qmf(); + + report("apply_qmf"); +} diff --git a/tests/checkasm/h264dsp.c b/tests/checkasm/h264dsp.c index c9ddd52a7f..945423703f 100644 --- a/tests/checkasm/h264dsp.c +++ b/tests/checkasm/h264dsp.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2016 Martin Storsjo * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/h264pred.c b/tests/checkasm/h264pred.c index 4994947b1b..59dcb2f427 100644 --- a/tests/checkasm/h264pred.c +++ b/tests/checkasm/h264pred.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2015 Henrik Gramner * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/h264qpel.c b/tests/checkasm/h264qpel.c index d92f223ba1..ba069f1259 100644 --- a/tests/checkasm/h264qpel.c +++ b/tests/checkasm/h264qpel.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2015 Henrik Gramner * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/hevc_add_res.c b/tests/checkasm/hevc_add_res.c index c9ed86b5cc..e92c6b427b 100644 --- a/tests/checkasm/hevc_add_res.c +++ b/tests/checkasm/hevc_add_res.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2016 Alexandra Hájková * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ @@ -45,10 +45,10 @@ static void check_add_res(HEVCDSPContext h, int bit_depth) { int i; - LOCAL_ALIGNED(32, int16_t, res0, [32 * 32]); - LOCAL_ALIGNED(32, int16_t, res1, [32 * 32]); - LOCAL_ALIGNED(32, uint8_t, dst0, [32 * 32 * 2]); - LOCAL_ALIGNED(32, uint8_t, dst1, [32 * 32 * 2]); + LOCAL_ALIGNED_32(int16_t, res0, [32 * 32]); + LOCAL_ALIGNED_32(int16_t, res1, [32 * 32]); + LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]); for (i = 2; i <= 5; i++) { int block_size = 1 << i; @@ -59,7 +59,7 @@ static void check_add_res(HEVCDSPContext h, int bit_depth) randomize_buffers(res0, size); randomize_buffers2(dst0, size); memcpy(res1, res0, sizeof(*res0) * size); - memcpy(dst1, dst0, size); + memcpy(dst1, dst0, sizeof(int16_t) * size); if (check_func(h.add_residual[i - 2], "hevc_add_res_%dx%d_%d", block_size, block_size, bit_depth)) { call_ref(dst0, res0, stride); diff --git a/tests/checkasm/hevc_idct.c b/tests/checkasm/hevc_idct.c index dd4dc0d064..eea712101d 100644 --- a/tests/checkasm/hevc_idct.c +++ b/tests/checkasm/hevc_idct.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2016 Alexandra Hájková * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/hevc_mc.c b/tests/checkasm/hevc_mc.c deleted file mode 100644 index 70f35ce78a..0000000000 --- a/tests/checkasm/hevc_mc.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright (c) 2015 Anton Khirnov - * - * This file is part of Libav. - * - * Libav 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. - * - * Libav 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 Libav; 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/avcodec.h" -#include "libavcodec/hevcdsp.h" - -#include "libavutil/common.h" -#include "libavutil/intreadwrite.h" - -// max PU size + interpolation stencil -#define BUF_SIZE (FFALIGN(64 + 7, 16) * (64 + 7) * 2) - -#define PIXEL_SIZE(depth) ((depth + 7) / 8) - -#define randomize_buffers(buf, size, depth) \ - do { \ - uint32_t mask = pixel_mask[depth - 8]; \ - int i; \ - for (i = 0; i < size; i += 4) { \ - uint32_t r = rnd() & mask; \ - AV_WN32A(buf + i, r); \ - } \ - } while (0) - -static const uint32_t pixel_mask[3] = { 0xffffffff, 0x01ff01ff, 0x03ff03ff }; - -static const int pred_heights[][7] = { - [2] = { 8, 4, 2, 0 }, - [4] = { 16, 8, 4, 2, 0 }, - [6] = { 8, 0 }, - [8] = { 32, 16, 8, 4, 2, 0 }, - [12] = { 16, 0 }, - [16] = { 64, 32, 16, 12, 8, 4, 0 }, - [24] = { 32, 0 }, - [32] = { 64, 32, 24, 16, 8, 0 }, - [48] = { 64, 0 }, - [64] = { 64, 48, 32, 16, 0 }, -}; - -static const int pred_widths[] = { 4, 8, 12, 16, 24, 32, 48, 64 }; - -static const char *interp_names[2][2] = { { "pixels", "h" }, { "v", "hv" } }; - -#define UNWEIGHTED_PRED(dst0, dst1, src0, width, bit_depth) \ -do { \ - int i; \ - for (i = 0; i < FF_ARRAY_ELEMS(pred_heights[i]); i++) { \ - int height = pred_heights[width][i]; \ - if (!height) \ - break; \ - call_ref(dst0, dststride, src0, srcstride, height); \ - call_new(dst1, dststride, src0, srcstride, height); \ - if (memcmp(dst0, dst1, dststride * height)) \ - fail(); \ - bench_new(dst1, dststride, src0, srcstride, height); \ - } \ -} while (0) - -#define UNWEIGHTED_PRED_AVG(dst0, dst1, src0, src1, width, bit_depth) \ -do { \ - int i; \ - for (i = 0; i < FF_ARRAY_ELEMS(pred_heights[i]); i++) { \ - int height = pred_heights[width][i]; \ - if (!height) \ - break; \ - call_ref(dst0, dststride, src0, src1, srcstride, height); \ - call_new(dst1, dststride, src0, src1, srcstride, height); \ - if (memcmp(dst0, dst1, dststride * height)) \ - fail(); \ - bench_new(dst1, dststride, src0, src1, srcstride, height); \ - } \ -} while (0) - -static void check_unweighted_pred(HEVCDSPContext *h, uint8_t *dst0, uint8_t *dst1, - int16_t *src0, int16_t *src1, int bit_depth) -{ - int i; - - randomize_buffers(src0, BUF_SIZE, 8); - randomize_buffers(src1, BUF_SIZE, 8); - - memset(dst0, 0, BUF_SIZE * sizeof(*dst0)); - memset(dst1, 0, BUF_SIZE * sizeof(*dst1)); - - for (i = 0; i < FF_ARRAY_ELEMS(pred_widths); i++) { - const int width = pred_widths[i]; - const ptrdiff_t srcstride = FFALIGN(width, 16) * sizeof(*src0); - const ptrdiff_t dststride = FFALIGN(width, 16) * PIXEL_SIZE(bit_depth); - - { - declare_func(void, uint8_t *dst, ptrdiff_t dststride, int16_t *src, ptrdiff_t srcstride, int height); - if (check_func(h->put_unweighted_pred[i], "put_unweighted_pred_%d_%d", width, bit_depth)) - UNWEIGHTED_PRED(dst0, dst1, src0, width, bit_depth); - if (check_func(h->put_unweighted_pred_chroma[i], "put_unweighted_pred_%d_%d", width / 2, bit_depth)) - UNWEIGHTED_PRED(dst0, dst1, src0, width, bit_depth); - } - { - declare_func(void, uint8_t *dst, ptrdiff_t dststride, - int16_t *src0, int16_t *src1, ptrdiff_t srcstride, int height); - if (check_func(h->put_unweighted_pred_avg[i], "put_unweighted_pred_avg_%d_%d", width, bit_depth)) - UNWEIGHTED_PRED_AVG(dst0, dst1, src0, src1, width, bit_depth); - if (check_func(h->put_unweighted_pred_avg_chroma[i], "put_unweighted_pred_avg_%d_%d", width / 2, bit_depth)) - UNWEIGHTED_PRED_AVG(dst0, dst1, src0, src1, width, bit_depth); - } - } -} - -#define WEIGHTED_PRED(dst0, dst1, src0, width, bit_depth) \ -do { \ - int i; \ - for (i = 0; i < FF_ARRAY_ELEMS(pred_heights[i]); i++) { \ - int height = pred_heights[width][i]; \ - if (!height) \ - break; \ - call_ref(denom, weight0, offset0, dst0, dststride, src0, srcstride, height); \ - call_new(denom, weight0, offset0, dst1, dststride, src0, srcstride, height); \ - if (memcmp(dst0, dst1, dststride * height)) \ - fail(); \ - bench_new(denom, weight0, offset0, dst1, dststride, src0, srcstride, height); \ - } \ -} while (0) - -#define WEIGHTED_PRED_AVG(dst0, dst1, src0, src1, width, bit_depth) \ -do { \ - int i; \ - for (i = 0; i < FF_ARRAY_ELEMS(pred_heights[i]); i++) { \ - int height = pred_heights[width][i]; \ - if (!height) \ - break; \ - call_ref(denom, weight0, weight1, offset0, offset1, dst0, dststride, src0, src1, srcstride, height); \ - call_new(denom, weight0, weight1, offset0, offset1, dst1, dststride, src0, src1, srcstride, height); \ - if (memcmp(dst0, dst1, dststride * height)) \ - fail(); \ - bench_new(denom, weight0, weight1, offset0, offset1, dst1, dststride, src0, src1, srcstride, height); \ - } \ -} while (0) - -static void check_weighted_pred(HEVCDSPContext *h, uint8_t *dst0, uint8_t *dst1, - int16_t *src0, int16_t *src1, int bit_depth) -{ - uint8_t denom; - int16_t weight0, weight1, offset0, offset1; - int i; - - randomize_buffers(src0, BUF_SIZE, 8); - randomize_buffers(src1, BUF_SIZE, 8); - - denom = rnd() & 7; - weight0 = denom + ((rnd() & 255) - 128); - weight1 = denom + ((rnd() & 255) - 128); - offset0 = (rnd() & 255) - 128; - offset1 = (rnd() & 255) - 128; - - memset(dst0, 0, BUF_SIZE * sizeof(*dst0)); - memset(dst1, 0, BUF_SIZE * sizeof(*dst1)); - - for (i = 0; i < FF_ARRAY_ELEMS(pred_widths); i++) { - const int width = pred_widths[i]; - const ptrdiff_t srcstride = FFALIGN(width, 16) * sizeof(*src0); - const ptrdiff_t dststride = FFALIGN(width, 16) * PIXEL_SIZE(bit_depth); - - { - declare_func(void, uint8_t denom, int16_t weight, int16_t offset, - uint8_t *dst, ptrdiff_t dststride, int16_t *src, ptrdiff_t srcstride, int height); - if (check_func(h->weighted_pred[i], "weighted_pred_%d_%d", width, bit_depth)) - WEIGHTED_PRED(dst0, dst1, src0, width, bit_depth); - if (check_func(h->weighted_pred_chroma[i], "weighted_pred_%d_%d", width / 2, bit_depth)) - WEIGHTED_PRED(dst0, dst1, src0, width, bit_depth); - } - { - declare_func(void, uint8_t denom, int16_t weight0, int16_t weight1, int16_t offset0, int16_t offset1, - uint8_t *dst, ptrdiff_t dststride, int16_t *src0, int16_t *src1, ptrdiff_t srcstride, int height); - if (check_func(h->weighted_pred_avg[i], "weighted_pred_avg_%d_%d", width, bit_depth)) - WEIGHTED_PRED_AVG(dst0, dst1, src0, src1, width, bit_depth); - if (check_func(h->weighted_pred_avg_chroma[i], "weighted_pred_avg_%d_%d", width / 2, bit_depth)) - WEIGHTED_PRED_AVG(dst0, dst1, src0, src1, width, bit_depth); - } - } -} - -static void check_epel(HEVCDSPContext *h, int16_t *dst0, int16_t *dst1, - uint8_t *src, int16_t *mcbuffer, int bit_depth) -{ - int i, j, k, l, mx, my; - - declare_func(void, int16_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, - int height, int mx, int my, int16_t *mcbuffer); - - randomize_buffers(src, BUF_SIZE, bit_depth); - - memset(dst0, 0, BUF_SIZE * sizeof(*dst0)); - memset(dst1, 0, BUF_SIZE * sizeof(*dst1)); - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - for (k = 0; k < FF_ARRAY_ELEMS(h->put_hevc_epel[i][j]); k++) { - int width = pred_widths[k] / 2; - ptrdiff_t dststride = FFALIGN(width, 16) * sizeof(*dst0); - ptrdiff_t srcstride = FFALIGN(width + 3, 8) * PIXEL_SIZE(bit_depth); - - if (!check_func(h->put_hevc_epel[i][j][k], "epel_%s_%d_%d", interp_names[i][j], width, bit_depth)) - continue; - - for (l = 0; l < FF_ARRAY_ELEMS(pred_heights[0]); l++) { - int height = pred_heights[width][l]; - - if (!height) - continue; - - for (my = i; my < (i ? 8 : 1); my++) - for (mx = j; mx < (j ? 8 : 1); mx++) { - call_ref(dst0, dststride, src + srcstride + PIXEL_SIZE(bit_depth), srcstride, height, mx, my, mcbuffer); - call_new(dst1, dststride, src + srcstride + PIXEL_SIZE(bit_depth), srcstride, height, mx, my, mcbuffer); - - if (memcmp(dst0, dst1, dststride * height * sizeof(*dst0))) - fail(); - - bench_new(dst1, dststride, src + srcstride + PIXEL_SIZE(bit_depth), srcstride, height, mx, my, mcbuffer); - } - } - } - } - } -} - -static void check_qpel(HEVCDSPContext *h, int16_t *dst0, int16_t *dst1, - uint8_t *src, int16_t *mcbuffer, int bit_depth) -{ - int i, j, k, l, mx, my; - - declare_func(void, int16_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, - int height, int mx, int my, int16_t *mcbuffer); - - randomize_buffers(src, BUF_SIZE, bit_depth); - - memset(dst0, 0, BUF_SIZE * sizeof(*dst0)); - memset(dst1, 0, BUF_SIZE * sizeof(*dst1)); - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - for (k = 0; k < FF_ARRAY_ELEMS(h->put_hevc_qpel[i][j]); k++) { - int width = pred_widths[k]; - ptrdiff_t dststride = FFALIGN(width, 16) * sizeof(*dst0); - ptrdiff_t srcstride = FFALIGN(width + 7, 8) * PIXEL_SIZE(bit_depth); - - if (!check_func(h->put_hevc_qpel[i][j][k], "qpel_%s_%d_%d", interp_names[i][j], width, bit_depth)) - continue; - - for (l = 0; l < FF_ARRAY_ELEMS(pred_heights[0]); l++) { - int height = pred_heights[width][l]; - - if (!height) - continue; - - for (my = i; my < (i ? 2 : 1); my++) - for (mx = j; mx < (j ? 2 : 1); mx++) { - call_ref(dst0, dststride, src + 3 * srcstride + 3 * PIXEL_SIZE(bit_depth), srcstride, height, mx, my, mcbuffer); - call_new(dst1, dststride, src + 3 * srcstride + 3 * PIXEL_SIZE(bit_depth), srcstride, height, mx, my, mcbuffer); - - if (memcmp(dst0, dst1, dststride * height * sizeof(*dst0))) - fail(); - - bench_new(dst1, dststride, src + 3 * srcstride + 3 * PIXEL_SIZE(bit_depth), srcstride, height, mx, my, mcbuffer); - } - } - } - } - } -} - -void checkasm_check_hevc_mc(void) -{ - DECLARE_ALIGNED(16, uint8_t, buf8_0)[BUF_SIZE]; - DECLARE_ALIGNED(16, uint8_t, buf8_1)[BUF_SIZE]; - - DECLARE_ALIGNED(16, int16_t, buf16_0)[BUF_SIZE]; - DECLARE_ALIGNED(16, int16_t, buf16_1)[BUF_SIZE]; - - DECLARE_ALIGNED(16, int16_t, mcbuffer)[BUF_SIZE]; - - HEVCDSPContext h; - int bit_depth; - - for (bit_depth = 8; bit_depth <= 10; bit_depth++) { - ff_hevc_dsp_init(&h, bit_depth); - check_qpel(&h, buf16_0, buf16_1, buf8_0, mcbuffer, bit_depth); - } - report("qpel"); - - for (bit_depth = 8; bit_depth <= 10; bit_depth++) { - ff_hevc_dsp_init(&h, bit_depth); - check_epel(&h, buf16_0, buf16_1, buf8_0, mcbuffer, bit_depth); - } - report("epel"); - - for (bit_depth = 8; bit_depth <= 10; bit_depth++) { - ff_hevc_dsp_init(&h, bit_depth); - check_unweighted_pred(&h, buf8_0, buf8_1, buf16_0, buf16_1, bit_depth); - } - report("unweighted_pred"); - - for (bit_depth = 8; bit_depth <= 10; bit_depth++) { - ff_hevc_dsp_init(&h, bit_depth); - check_weighted_pred(&h, buf8_0, buf8_1, buf16_0, buf16_1, bit_depth); - } - report("weighted_pred"); -} diff --git a/tests/checkasm/jpeg2000dsp.c b/tests/checkasm/jpeg2000dsp.c new file mode 100644 index 0000000000..48559df085 --- /dev/null +++ b/tests/checkasm/jpeg2000dsp.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015 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 "checkasm.h" +#include "libavcodec/jpeg2000dsp.h" +#include "libavutil/common.h" +#include "libavutil/internal.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(ref0 + i, r); \ + AV_WN32A(new0 + i, r); \ + r = rnd(); \ + AV_WN32A(ref1 + i, r); \ + AV_WN32A(new1 + i, r); \ + r = rnd(); \ + AV_WN32A(ref2 + i, r); \ + AV_WN32A(new2 + i, r); \ + } \ + } while (0) + +static void check_mct(uint8_t *ref0, uint8_t *ref1, uint8_t *ref2, + uint8_t *new0, uint8_t *new1, uint8_t *new2) { + declare_func(void, void *src0, void *src1, void *src2, int csize); + + randomize_buffers(); + call_ref(ref0, ref1, ref2, BUF_SIZE / sizeof(int32_t)); + call_new(new0, new1, new2, BUF_SIZE / sizeof(int32_t)); + if (memcmp(ref0, new0, BUF_SIZE) || memcmp(ref1, new1, BUF_SIZE) || + memcmp(ref2, new2, BUF_SIZE)) + fail(); + bench_new(new0, new1, new2, BUF_SIZE / sizeof(int32_t)); +} + +void checkasm_check_jpeg2000dsp(void) +{ + LOCAL_ALIGNED_32(uint8_t, ref, [BUF_SIZE*3]); + LOCAL_ALIGNED_32(uint8_t, new, [BUF_SIZE*3]); + Jpeg2000DSPContext h; + + ff_jpeg2000dsp_init(&h); + + if (check_func(h.mct_decode[FF_DWT53], "jpeg2000_rct_int")) + check_mct(&ref[BUF_SIZE*0], &ref[BUF_SIZE*1], &ref[BUF_SIZE*2], + &new[BUF_SIZE*0], &new[BUF_SIZE*1], &new[BUF_SIZE*2]); + + report("mct_decode"); +} diff --git a/tests/checkasm/huffyuvdsp.c b/tests/checkasm/llviddsp.c index 59e0f6a65a..b1f3b83b43 100644 --- a/tests/checkasm/huffyuvdsp.c +++ b/tests/checkasm/llviddsp.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2016 Alexandra Hájková * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ @@ -24,7 +24,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/mem.h" -#include "libavcodec/huffyuvdsp.h" +#include "libavcodec/lossless_videodsp.h" #include "checkasm.h" @@ -35,13 +35,13 @@ buf[j] = rnd() & 0xFF; \ } while (0) -static void check_add_bytes(HuffYUVDSPContext c, int width) +static void check_add_bytes(LLVidDSPContext c, int width) { uint8_t *src0 = av_mallocz(width); uint8_t *src1 = av_mallocz(width); uint8_t *dst0 = av_mallocz(width); uint8_t *dst1 = av_mallocz(width); - declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, int w); + declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t w); if (!src0 || !src1 || !dst0 || !dst1) fail(); @@ -63,12 +63,12 @@ static void check_add_bytes(HuffYUVDSPContext c, int width) av_free(dst1); } -void checkasm_check_huffyuvdsp(void) +void checkasm_check_llviddsp(void) { - HuffYUVDSPContext c; + LLVidDSPContext c; int width = 16 * av_clip(rnd(), 16, 128); - ff_huffyuvdsp_init(&c); + ff_llviddsp_init(&c); check_add_bytes(c, width); diff --git a/tests/checkasm/pixblockdsp.c b/tests/checkasm/pixblockdsp.c new file mode 100644 index 0000000000..e14b0a90de --- /dev/null +++ b/tests/checkasm/pixblockdsp.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015 Tiancheng "Timothy" Gu + * + * 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/pixblockdsp.h" +#include "libavutil/common.h" +#include "libavutil/internal.h" +#include "libavutil/intreadwrite.h" + +#define BUF_UNITS 8 +#define BUF_SIZE (BUF_UNITS * 128 + 8 * BUF_UNITS) + +#define randomize_buffers() \ + do { \ + int i; \ + for (i = 0; i < BUF_SIZE; i += 4) { \ + uint32_t r = rnd(); \ + AV_WN32A(src10 + i, r); \ + AV_WN32A(src11 + i, r); \ + r = rnd(); \ + AV_WN32A(src20 + i, r); \ + AV_WN32A(src21 + i, r); \ + r = rnd(); \ + AV_WN32A(dst0_ + i, r); \ + AV_WN32A(dst1_ + i, r); \ + } \ + } while (0) + +#define check_get_pixels(type) \ + do { \ + int i; \ + declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t *block, const uint8_t *pixels, ptrdiff_t line_size); \ + \ + for (i = 0; i < BUF_UNITS; i++) { \ + int src_offset = i * 64 * sizeof(type) + 8 * i; /* Test various alignments */ \ + int dst_offset = i * 64; /* dst must be aligned */ \ + randomize_buffers(); \ + call_ref(dst0 + dst_offset, src10 + src_offset, 8); \ + call_new(dst1 + dst_offset, src11 + src_offset, 8); \ + if (memcmp(src10, src11, BUF_SIZE)|| memcmp(dst0, dst1, BUF_SIZE)) \ + fail(); \ + bench_new(dst1 + dst_offset, src11 + src_offset, 8); \ + } \ + } while (0) + +#define check_diff_pixels(type) \ + do { \ + int i; \ + declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t *av_restrict block, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride); \ + \ + for (i = 0; i < BUF_UNITS; i++) { \ + int src_offset = i * 64 * sizeof(type) + 8 * i; /* Test various alignments */ \ + int dst_offset = i * 64; /* dst must be aligned */ \ + randomize_buffers(); \ + call_ref(dst0 + dst_offset, src10 + src_offset, src20 + src_offset, 8); \ + call_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \ + if (memcmp(src10, src11, BUF_SIZE) || memcmp(src20, src21, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE)) \ + fail(); \ + bench_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \ + } \ + } while (0) + +void checkasm_check_pixblockdsp(void) +{ + LOCAL_ALIGNED_16(uint8_t, src10, [BUF_SIZE]); + LOCAL_ALIGNED_16(uint8_t, src11, [BUF_SIZE]); + LOCAL_ALIGNED_16(uint8_t, src20, [BUF_SIZE]); + LOCAL_ALIGNED_16(uint8_t, src21, [BUF_SIZE]); + LOCAL_ALIGNED_16(uint8_t, dst0_, [BUF_SIZE]); + LOCAL_ALIGNED_16(uint8_t, dst1_, [BUF_SIZE]); + uint16_t *dst0 = (uint16_t *)dst0_; + uint16_t *dst1 = (uint16_t *)dst1_; + PixblockDSPContext h; + AVCodecContext avctx = { + .bits_per_raw_sample = 8, + }; + + ff_pixblockdsp_init(&h, &avctx); + + if (check_func(h.get_pixels, "get_pixels")) + check_get_pixels(uint8_t); + + report("get_pixels"); + + if (check_func(h.diff_pixels, "diff_pixels")) + check_diff_pixels(uint8_t); + + report("diff_pixels"); +} diff --git a/tests/checkasm/sbrdsp.c b/tests/checkasm/sbrdsp.c new file mode 100644 index 0000000000..558f452c9b --- /dev/null +++ b/tests/checkasm/sbrdsp.c @@ -0,0 +1,298 @@ +/* + * 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 "libavcodec/sbrdsp.h" + +#include "checkasm.h" + +#define randomize(buf, len) do { \ + int i; \ + for (i = 0; i < len; i++) { \ + const INTFLOAT f = (INTFLOAT)rnd() / UINT_MAX; \ + (buf)[i] = f; \ + } \ +} while (0) + +#define EPS 0.0001 + +static void test_sum64x5(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, dst0, [64 + 256]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [64 + 256]); + + declare_func(void, INTFLOAT *z); + + randomize((INTFLOAT *)dst0, 64 + 256); + memcpy(dst1, dst0, (64 + 256) * sizeof(INTFLOAT)); + call_ref(dst0); + call_new(dst1); + if (!float_near_abs_eps_array(dst0, dst1, EPS, 64 + 256)) + fail(); + bench_new(dst1); +} + +static void test_sum_square(void) +{ + INTFLOAT res0; + INTFLOAT res1; + LOCAL_ALIGNED_16(INTFLOAT, src, [256], [2]); + + declare_func_float(INTFLOAT, INTFLOAT (*x)[2], int n); + + randomize((INTFLOAT *)src, 256 * 2); + res0 = call_ref(src, 256); + res1 = call_new(src, 256); + if (!float_near_abs_eps(res0, res1, EPS)) + fail(); + bench_new(src, 256); +} + +static void test_neg_odd_64(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]); + + declare_func(void, INTFLOAT *x); + + randomize((INTFLOAT *)dst0, 64); + memcpy(dst1, dst0, (64) * sizeof(INTFLOAT)); + call_ref(dst0); + call_new(dst1); + if (!float_near_abs_eps_array(dst0, dst1, EPS, 64)) + fail(); + bench_new(dst1); +} + +static void test_qmf_pre_shuffle(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]); + + declare_func(void, INTFLOAT *z); + + randomize((INTFLOAT *)dst0, 128); + memcpy(dst1, dst0, (128) * sizeof(INTFLOAT)); + call_ref(dst0); + call_new(dst1); + if (!float_near_abs_eps_array(dst0, dst1, EPS, 128)) + fail(); + bench_new(dst1); +} + +static void test_qmf_post_shuffle(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, src, [64]); + LOCAL_ALIGNED_16(INTFLOAT, dst0, [32], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [32], [2]); + + declare_func(void, INTFLOAT W[32][2], const INTFLOAT *z); + + randomize((INTFLOAT *)src, 64); + call_ref(dst0, src); + call_new(dst1, src); + if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 64)) + fail(); + bench_new(dst1, src); +} + +static void test_qmf_deint_neg(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, src, [64]); + LOCAL_ALIGNED_16(INTFLOAT, dst0, [64]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [64]); + + declare_func(void, INTFLOAT *v, const INTFLOAT *src); + + randomize((INTFLOAT *)src, 64); + call_ref(dst0, src); + call_new(dst1, src); + if (!float_near_abs_eps_array(dst0, dst1, EPS, 64)) + fail(); + bench_new(dst1, src); +} + +static void test_qmf_deint_bfly(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, src0, [64]); + LOCAL_ALIGNED_16(INTFLOAT, src1, [64]); + LOCAL_ALIGNED_16(INTFLOAT, dst0, [128]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [128]); + + declare_func(void, INTFLOAT *v, const INTFLOAT *src0, const INTFLOAT *src1); + + memset(dst0, 0, 128 * sizeof(INTFLOAT)); + memset(dst1, 0, 128 * sizeof(INTFLOAT)); + + randomize((INTFLOAT *)src0, 64); + randomize((INTFLOAT *)src1, 64); + call_ref(dst0, src0, src1); + call_new(dst1, src0, src1); + if (!float_near_abs_eps_array(dst0, dst1, EPS, 128)) + fail(); + bench_new(dst1, src0, src1); +} + +static void test_autocorrelate(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, src, [40], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst0, [3], [2][2]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [3], [2][2]); + + declare_func(void, const INTFLOAT x[40][2], INTFLOAT phi[3][2][2]); + + memset(dst0, 0, 3 * 2 * 2 * sizeof(INTFLOAT)); + memset(dst1, 0, 3 * 2 * 2 * sizeof(INTFLOAT)); + + randomize((INTFLOAT *)src, 80); + call_ref(src, dst0); + call_new(src, dst1); + if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 3 * 2 * 2)) + fail(); + bench_new(src, dst1); +} + +static void test_hf_gen(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, low, [128], [2]); + LOCAL_ALIGNED_16(INTFLOAT, alpha0, [2]); + LOCAL_ALIGNED_16(INTFLOAT, alpha1, [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]); + INTFLOAT bw = (INTFLOAT)rnd() / UINT_MAX; + int i; + + declare_func(void, INTFLOAT (*X_high)[2], const INTFLOAT (*X_low)[2], + const INTFLOAT alpha0[2], const INTFLOAT alpha1[2], + INTFLOAT bw, int start, int end); + + randomize((INTFLOAT *)low, 128 * 2); + randomize((INTFLOAT *)alpha0, 2); + randomize((INTFLOAT *)alpha1, 2); + for (i = 2; i < 64; i += 2) { + memset(dst0, 0, 128 * 2 * sizeof(INTFLOAT)); + memset(dst1, 0, 128 * 2 * sizeof(INTFLOAT)); + call_ref(dst0, low, alpha0, alpha1, 0.0, i, 128); + call_new(dst1, low, alpha0, alpha1, 0.0, i, 128); + if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2)) + fail(); + bench_new(dst1, low, alpha0, alpha1, bw, i, 128); + } +} + +static void test_hf_g_filt(void) +{ + LOCAL_ALIGNED_16(INTFLOAT, high, [128], [40][2]); + LOCAL_ALIGNED_16(INTFLOAT, g_filt, [128]); + LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]); + + declare_func(void, INTFLOAT (*Y)[2], const INTFLOAT (*X_high)[40][2], + const INTFLOAT *g_filt, int m_max, intptr_t ixh); + + randomize((INTFLOAT *)high, 128 * 40 * 2); + randomize((INTFLOAT *)g_filt, 128); + + call_ref(dst0, high, g_filt, 128, 20); + call_new(dst1, high, g_filt, 128, 20); + if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2)) + fail(); + bench_new(dst1, high, g_filt, 128, 20); +} + +static void test_hf_apply_noise(const SBRDSPContext *sbrdsp) +{ + LOCAL_ALIGNED_16(AAC_FLOAT, s_m, [128]); + LOCAL_ALIGNED_16(AAC_FLOAT, q_filt, [128]); + LOCAL_ALIGNED_16(INTFLOAT, ref, [128], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst0, [128], [2]); + LOCAL_ALIGNED_16(INTFLOAT, dst1, [128], [2]); + int noise = 0x2a; + int i, j; + + declare_func(void, INTFLOAT (*Y)[2], const AAC_FLOAT *s_m, + const AAC_FLOAT *q_filt, int noise, + int kx, int m_max); + + randomize((INTFLOAT *)ref, 128 * 2); + randomize((INTFLOAT *)s_m, 128); + randomize((INTFLOAT *)q_filt, 128); + + for (i = 0; i < 4; i++) { + if (check_func(sbrdsp->hf_apply_noise[i], "hf_apply_noise_%d", i)) { + for (j = 0; j < 2; j++) { + memcpy(dst0, ref, 128 * 2 * sizeof(INTFLOAT)); + memcpy(dst1, ref, 128 * 2 * sizeof(INTFLOAT)); + call_ref(dst0, s_m, q_filt, noise, j, 128); + call_new(dst1, s_m, q_filt, noise, j, 128); + if (!float_near_abs_eps_array((INTFLOAT *)dst0, (INTFLOAT *)dst1, EPS, 128 * 2)) + fail(); + bench_new(dst1, s_m, q_filt, noise, j, 128); + } + } + } +} + +void checkasm_check_sbrdsp(void) +{ + SBRDSPContext sbrdsp; + + ff_sbrdsp_init(&sbrdsp); + + if (check_func(sbrdsp.sum64x5, "sum64x5")) + test_sum64x5(); + report("sum64x5"); + + if (check_func(sbrdsp.sum_square, "sum_square")) + test_sum_square(); + report("sum_square"); + + if (check_func(sbrdsp.neg_odd_64, "neg_odd_64")) + test_neg_odd_64(); + report("neg_odd_64"); + + if (check_func(sbrdsp.qmf_pre_shuffle, "qmf_pre_shuffle")) + test_qmf_pre_shuffle(); + report("qmf_pre_shuffle"); + + if (check_func(sbrdsp.qmf_post_shuffle, "qmf_post_shuffle")) + test_qmf_post_shuffle(); + report("qmf_post_shuffle"); + + if (check_func(sbrdsp.qmf_deint_neg, "qmf_deint_neg")) + test_qmf_deint_neg(); + report("qmf_deint_neg"); + + if (check_func(sbrdsp.qmf_deint_bfly, "qmf_deint_bfly")) + test_qmf_deint_bfly(); + report("qmf_deint_bfly"); + + if (check_func(sbrdsp.autocorrelate, "autocorrelate")) + test_autocorrelate(); + report("autocorrelate"); + + if (check_func(sbrdsp.hf_gen, "hf_gen")) + test_hf_gen(); + report("hf_gen"); + + if (check_func(sbrdsp.hf_g_filt, "hf_g_filt")) + test_hf_g_filt(); + report("hf_g_filt"); + + test_hf_apply_noise(&sbrdsp); + report("hf_apply_noise"); +} diff --git a/tests/checkasm/synth_filter.c b/tests/checkasm/synth_filter.c index 157400b570..87e32ebc0e 100644 --- a/tests/checkasm/synth_filter.c +++ b/tests/checkasm/synth_filter.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2015 Janne Grunau * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/v210enc.c b/tests/checkasm/v210enc.c index 4f5f6ba4ba..ed3677659d 100644 --- a/tests/checkasm/v210enc.c +++ b/tests/checkasm/v210enc.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2015 Henrik Gramner * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/vf_blend.c b/tests/checkasm/vf_blend.c new file mode 100644 index 0000000000..be65730452 --- /dev/null +++ b/tests/checkasm/vf_blend.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2016 Tiancheng "Timothy" Gu + * + * 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 "libavfilter/blend.h" +#include "libavutil/common.h" +#include "libavutil/internal.h" +#include "libavutil/intreadwrite.h" + +#define WIDTH 256 +#define HEIGHT 256 +#define BUF_UNITS 3 +#define SIZE_PER_UNIT (WIDTH * HEIGHT) +#define BUF_SIZE (BUF_UNITS * SIZE_PER_UNIT) + +#define randomize_buffers() \ + do { \ + int i, j; \ + for (i = 0; i < HEIGHT; i++) { \ + for (j = 0; j < WIDTH; j++) { \ + top1[i * WIDTH + j] = \ + top2[i * WIDTH + j] = i; \ + bot1[i * WIDTH + j] = \ + bot2[i * WIDTH + j] = j; \ + } \ + } \ + for (i = 0; i < SIZE_PER_UNIT; i += 4) { \ + uint32_t r = rnd(); \ + AV_WN32A(dst1 + i, r); \ + AV_WN32A(dst2 + i, r); \ + } \ + for (; i < BUF_SIZE; i += 4) { \ + uint32_t r = rnd(); \ + AV_WN32A(top1 + i, r); \ + AV_WN32A(top2 + i, r); \ + r = rnd(); \ + AV_WN32A(bot1 + i, r); \ + AV_WN32A(bot2 + i, r); \ + r = rnd(); \ + AV_WN32A(dst1 + i, r); \ + AV_WN32A(dst2 + i, r); \ + } \ + } while (0) + +#define check_blend_func() \ + do { \ + int i; \ + declare_func(void, const uint8_t *top, ptrdiff_t top_linesize, \ + const uint8_t *bottom, ptrdiff_t bottom_linesize, \ + uint8_t *dst, ptrdiff_t dst_linesize, \ + ptrdiff_t width, ptrdiff_t height, \ + struct FilterParams *param, double *values); \ + \ + for (i = 0; i < BUF_UNITS - 1; i++) { \ + int src_offset = i * SIZE_PER_UNIT + i; /* Test various alignments */ \ + int dst_offset = i * SIZE_PER_UNIT; /* dst must be aligned */ \ + randomize_buffers(); \ + call_ref(top1 + src_offset, WIDTH, bot1 + src_offset, WIDTH, \ + dst1 + dst_offset, WIDTH, WIDTH, HEIGHT, ¶m, NULL); \ + call_new(top2 + src_offset, WIDTH, bot2 + src_offset, WIDTH, \ + dst2 + dst_offset, WIDTH, WIDTH, HEIGHT, ¶m, NULL); \ + if (memcmp(top1, top2, BUF_SIZE) || memcmp(bot1, bot2, BUF_SIZE) || memcmp(dst1, dst2, BUF_SIZE)) \ + fail(); \ + } \ + bench_new(top2, WIDTH / 4, bot2, WIDTH / 4, dst2, WIDTH / 4, \ + WIDTH / 4, HEIGHT / 4, ¶m, NULL); \ + } while (0) + +void checkasm_check_blend(void) +{ + uint8_t *top1 = av_malloc(BUF_SIZE); + uint8_t *top2 = av_malloc(BUF_SIZE); + uint8_t *bot1 = av_malloc(BUF_SIZE); + uint8_t *bot2 = av_malloc(BUF_SIZE); + uint8_t *dst1 = av_malloc(BUF_SIZE); + uint8_t *dst2 = av_malloc(BUF_SIZE); + FilterParams param = { + .opacity = 1.0, + }; + +#define check_and_report(name, val) \ + param.mode = val; \ + ff_blend_init(¶m, 0); \ + if (check_func(param.blend, #name)) \ + check_blend_func(); + + check_and_report(addition, BLEND_ADDITION) + check_and_report(grainmerge, BLEND_GRAINMERGE) + check_and_report(and, BLEND_AND) + check_and_report(average, BLEND_AVERAGE) + check_and_report(darken, BLEND_DARKEN) + check_and_report(grainextract, BLEND_GRAINEXTRACT) + check_and_report(hardmix, BLEND_HARDMIX) + check_and_report(lighten, BLEND_LIGHTEN) + check_and_report(multiply, BLEND_MULTIPLY) + check_and_report(or, BLEND_OR) + check_and_report(phoenix, BLEND_PHOENIX) + check_and_report(screen, BLEND_SCREEN) + check_and_report(subtract, BLEND_SUBTRACT) + check_and_report(xor, BLEND_XOR) + check_and_report(difference, BLEND_DIFFERENCE) + check_and_report(extremity, BLEND_EXTREMITY) + check_and_report(negation, BLEND_NEGATION) + + report("8bit"); + + av_freep(&top1); + av_freep(&top2); + av_freep(&bot1); + av_freep(&bot2); + av_freep(&dst1); + av_freep(&dst2); +} diff --git a/tests/checkasm/vf_colorspace.c b/tests/checkasm/vf_colorspace.c new file mode 100644 index 0000000000..10b7b83924 --- /dev/null +++ b/tests/checkasm/vf_colorspace.c @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com> + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 "libavfilter/colorspacedsp.h" +#include "libavutil/common.h" +#include "libavutil/internal.h" +#include "libavutil/intreadwrite.h" + +#define W 64 +#define H 64 + +#define randomize_buffers() \ + do { \ + unsigned mask = bpp_mask[idepth]; \ + int n, m; \ + int bpp = 1 + (!!idepth); \ + int buf_size = W * H * bpp; \ + for (m = 0; m < 3; m++) { \ + int ss = m ? ss_w + ss_h : 0; \ + int plane_sz = buf_size >> ss; \ + for (n = 0; n < plane_sz; n += 4) { \ + unsigned r = rnd() & mask; \ + AV_WN32A(&src[m][n], r); \ + } \ + } \ + } while (0) + +static const char *format_string[] = { + "444", "422", "420" +}; + +static const unsigned bpp_mask[] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff }; + +static void check_yuv2yuv(void) +{ + declare_func(void, uint8_t *dst[3], ptrdiff_t dst_stride[3], + uint8_t *src[3], ptrdiff_t src_stride[3], + int w, int h, const int16_t coeff[3][3][8], + const int16_t off[2][8]); + ColorSpaceDSPContext dsp; + int idepth, odepth, fmt, n; + LOCAL_ALIGNED_32(uint8_t, src_y, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, src_u, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, src_v, [W * H * 2]); + uint8_t *src[3] = { src_y, src_u, src_v }; + LOCAL_ALIGNED_32(uint8_t, dst0_y, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0_u, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0_v, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_y, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_u, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_v, [W * H * 2]); + uint8_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v }; + LOCAL_ALIGNED_32(int16_t, offset_buf, [16]); + LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]); + int16_t (*offset)[8] = (int16_t(*)[8]) offset_buf; + int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf; + + ff_colorspacedsp_init(&dsp); + for (n = 0; n < 8; n++) { + offset[0][n] = offset[1][n] = 16; + + coeff[0][0][n] = (1 << 14) + (1 << 7) + 1; + coeff[0][1][n] = (1 << 7) - 1; + coeff[0][2][n] = -(1 << 8); + coeff[1][0][n] = coeff[2][0][n] = 0; + coeff[1][1][n] = (1 << 14) + (1 << 7); + coeff[1][2][n] = -(1 << 7); + coeff[2][2][n] = (1 << 14) - (1 << 6); + coeff[2][1][n] = 1 << 6; + } + for (idepth = 0; idepth < 3; idepth++) { + for (odepth = 0; odepth < 3; odepth++) { + for (fmt = 0; fmt < 3; fmt++) { + if (check_func(dsp.yuv2yuv[idepth][odepth][fmt], + "ff_colorspacedsp_yuv2yuv_%sp%dto%d", + format_string[fmt], + idepth * 2 + 8, odepth * 2 + 8)) { + int ss_w = !!fmt, ss_h = fmt == 2; + int y_src_stride = W << !!idepth, y_dst_stride = W << !!odepth; + int uv_src_stride = y_src_stride >> ss_w, uv_dst_stride = y_dst_stride >> ss_w; + + randomize_buffers(); + call_ref(dst0, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride }, + src, (ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride }, + W, H, coeff, offset); + call_new(dst1, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride }, + src, (ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride }, + W, H, coeff, offset); + if (memcmp(dst0[0], dst1[0], y_dst_stride * H) || + memcmp(dst0[1], dst1[1], uv_dst_stride * H >> ss_h) || + memcmp(dst0[2], dst1[2], uv_dst_stride * H >> ss_h)) { + fail(); + } + } + } + } + } + + report("yuv2yuv"); +} + +static void check_yuv2rgb(void) +{ + declare_func(void, int16_t *dst[3], ptrdiff_t dst_stride, + uint8_t *src[3], ptrdiff_t src_stride[3], + int w, int h, const int16_t coeff[3][3][8], + const int16_t off[8]); + ColorSpaceDSPContext dsp; + int idepth, fmt, n; + LOCAL_ALIGNED_32(uint8_t, src_y, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, src_u, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, src_v, [W * H * 2]); + uint8_t *src[3] = { src_y, src_u, src_v }; + LOCAL_ALIGNED_32(int16_t, dst0_y, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst0_u, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst0_v, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst1_y, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst1_u, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst1_v, [W * H]); + int16_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v }; + LOCAL_ALIGNED_32(int16_t, offset, [8]); + LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]); + int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf; + + ff_colorspacedsp_init(&dsp); + for (n = 0; n < 8; n++) { + offset[n] = 16; + + coeff[0][0][n] = coeff[1][0][n] = coeff[2][0][n] = (1 << 14) | 1; + coeff[0][1][n] = coeff[2][2][n] = 0; + coeff[0][2][n] = 1 << 13; + coeff[1][1][n] = -(1 << 12); + coeff[1][2][n] = 1 << 12; + coeff[2][1][n] = 1 << 11; + } + for (idepth = 0; idepth < 3; idepth++) { + for (fmt = 0; fmt < 3; fmt++) { + if (check_func(dsp.yuv2rgb[idepth][fmt], + "ff_colorspacedsp_yuv2rgb_%sp%d", + format_string[fmt], idepth * 2 + 8)) { + int ss_w = !!fmt, ss_h = fmt == 2; + int y_src_stride = W << !!idepth; + int uv_src_stride = y_src_stride >> ss_w; + + randomize_buffers(); + call_ref(dst0, W, src, + (ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride }, + W, H, coeff, offset); + call_new(dst1, W, src, + (ptrdiff_t[3]) { y_src_stride, uv_src_stride, uv_src_stride }, + W, H, coeff, offset); + if (memcmp(dst0[0], dst1[0], W * H * sizeof(int16_t)) || + memcmp(dst0[1], dst1[1], W * H * sizeof(int16_t)) || + memcmp(dst0[2], dst1[2], W * H * sizeof(int16_t))) { + fail(); + } + } + } + } + + report("yuv2rgb"); +} + +#undef randomize_buffers +#define randomize_buffers() \ + do { \ + int y, x, p; \ + for (p = 0; p < 3; p++) { \ + for (y = 0; y < H; y++) { \ + for (x = 0; x < W; x++) { \ + int r = rnd() & 0x7fff; \ + r -= (32768 - 28672) >> 1; \ + src[p][y * W + x] = r; \ + } \ + } \ + } \ + } while (0) + +static void check_rgb2yuv(void) +{ + declare_func(void, uint8_t *dst[3], ptrdiff_t dst_stride[3], + int16_t *src[3], ptrdiff_t src_stride, + int w, int h, const int16_t coeff[3][3][8], + const int16_t off[8]); + ColorSpaceDSPContext dsp; + int odepth, fmt, n; + LOCAL_ALIGNED_32(int16_t, src_y, [W * H * 2]); + LOCAL_ALIGNED_32(int16_t, src_u, [W * H * 2]); + LOCAL_ALIGNED_32(int16_t, src_v, [W * H * 2]); + int16_t *src[3] = { src_y, src_u, src_v }; + LOCAL_ALIGNED_32(uint8_t, dst0_y, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0_u, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0_v, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_y, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_u, [W * H * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_v, [W * H * 2]); + uint8_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v }; + LOCAL_ALIGNED_32(int16_t, offset, [8]); + LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]); + int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf; + + ff_colorspacedsp_init(&dsp); + for (n = 0; n < 8; n++) { + offset[n] = 16; + + // these somewhat resemble bt601/smpte170m coefficients + coeff[0][0][n] = lrint(0.3 * (1 << 14)); + coeff[0][1][n] = lrint(0.6 * (1 << 14)); + coeff[0][2][n] = lrint(0.1 * (1 << 14)); + coeff[1][0][n] = lrint(-0.15 * (1 << 14)); + coeff[1][1][n] = lrint(-0.35 * (1 << 14)); + coeff[1][2][n] = lrint(0.5 * (1 << 14)); + coeff[2][0][n] = lrint(0.5 * (1 << 14)); + coeff[2][1][n] = lrint(-0.42 * (1 << 14)); + coeff[2][2][n] = lrint(-0.08 * (1 << 14)); + } + for (odepth = 0; odepth < 3; odepth++) { + for (fmt = 0; fmt < 3; fmt++) { + if (check_func(dsp.rgb2yuv[odepth][fmt], + "ff_colorspacedsp_rgb2yuv_%sp%d", + format_string[fmt], odepth * 2 + 8)) { + int ss_w = !!fmt, ss_h = fmt == 2; + int y_dst_stride = W << !!odepth; + int uv_dst_stride = y_dst_stride >> ss_w; + + randomize_buffers(); + call_ref(dst0, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride }, + src, W, W, H, coeff, offset); + call_new(dst1, (ptrdiff_t[3]) { y_dst_stride, uv_dst_stride, uv_dst_stride }, + src, W, W, H, coeff, offset); + if (memcmp(dst0[0], dst1[0], H * y_dst_stride) || + memcmp(dst0[1], dst1[1], H * uv_dst_stride >> ss_h) || + memcmp(dst0[2], dst1[2], H * uv_dst_stride >> ss_h)) { + fail(); + } + } + } + } + + report("rgb2yuv"); +} + +static void check_multiply3x3(void) +{ + declare_func(void, int16_t *data[3], ptrdiff_t stride, + int w, int h, const int16_t coeff[3][3][8]); + ColorSpaceDSPContext dsp; + LOCAL_ALIGNED_32(int16_t, dst0_y, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst0_u, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst0_v, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst1_y, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst1_u, [W * H]); + LOCAL_ALIGNED_32(int16_t, dst1_v, [W * H]); + int16_t *dst0[3] = { dst0_y, dst0_u, dst0_v }, *dst1[3] = { dst1_y, dst1_u, dst1_v }; + int16_t **src = dst0; + LOCAL_ALIGNED_32(int16_t, coeff_buf, [3 * 3 * 8]); + int16_t (*coeff)[3][8] = (int16_t(*)[3][8]) coeff_buf; + int n; + + ff_colorspacedsp_init(&dsp); + for (n = 0; n < 8; n++) { + coeff[0][0][n] = lrint(0.85 * (1 << 14)); + coeff[0][1][n] = lrint(0.10 * (1 << 14)); + coeff[0][2][n] = lrint(0.05 * (1 << 14)); + coeff[1][0][n] = lrint(-0.1 * (1 << 14)); + coeff[1][1][n] = lrint(0.95 * (1 << 14)); + coeff[1][2][n] = lrint(0.15 * (1 << 14)); + coeff[2][0][n] = lrint(-0.2 * (1 << 14)); + coeff[2][1][n] = lrint(0.30 * (1 << 14)); + coeff[2][2][n] = lrint(0.90 * (1 << 14)); + } + if (check_func(dsp.multiply3x3, "ff_colorspacedsp_multiply3x3")) { + randomize_buffers(); + memcpy(dst1_y, dst0_y, W * H * sizeof(*dst1_y)); + memcpy(dst1_u, dst0_u, W * H * sizeof(*dst1_u)); + memcpy(dst1_v, dst0_v, W * H * sizeof(*dst1_v)); + call_ref(dst0, W, W, H, coeff); + call_new(dst1, W, W, H, coeff); + if (memcmp(dst0[0], dst1[0], H * W * sizeof(*dst0_y)) || + memcmp(dst0[1], dst1[1], H * W * sizeof(*dst0_u)) || + memcmp(dst0[2], dst1[2], H * W * sizeof(*dst0_v))) { + fail(); + } + } + + report("multiply3x3"); +} + +void checkasm_check_colorspace(void) +{ + check_yuv2yuv(); + check_yuv2rgb(); + check_rgb2yuv(); + check_multiply3x3(); +} diff --git a/tests/checkasm/videodsp.c b/tests/checkasm/videodsp.c new file mode 100644 index 0000000000..0a4424a28c --- /dev/null +++ b/tests/checkasm/videodsp.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com> + * + * 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/videodsp.h" +#include "libavutil/internal.h" +#include "libavutil/intreadwrite.h" + +#define randomize_buffers(w, h) \ + do { \ + int i; \ + for (i = 0; i < w * h * sizeof(*src0); i += 4) \ + AV_WN32A(((uint8_t *) src0) + i, rnd()); \ + } while (0) + +#define iter_1d(type, fix, fix_val, var, var_start, var_end) \ + for (fix = fix_val, var = var_start; var <= var_end; var++) { \ + call_ref((type *) dst0, (const type *) (src0 + y * pw + x), \ + bw * sizeof(type), pw * sizeof(type), \ + bw, bh, x, y, pw, ph); \ + call_new((type *) dst1, (const type *) (src1 + y * pw + x), \ + bw * sizeof(type), pw * sizeof(type), \ + bw, bh, x, y, pw, ph); \ + if (memcmp(dst0, dst1, bw * bh * sizeof(type))) \ + fail(); \ + bench_new((type *) dst1, (const type *) (src1 + y * pw + x),\ + bw * sizeof(type), pw * sizeof(type), \ + bw, bh, x, y, pw, ph); \ + } + +#define check_emu_edge_size(type, src_w, src_h, dst_w, dst_h) \ + do { \ + LOCAL_ALIGNED_16(type, src0, [src_w * src_h]); \ + LOCAL_ALIGNED_16(type, src1, [src_w * src_h]); \ + int bw = dst_w, bh = dst_h; \ + int pw = src_w, ph = src_h; \ + int y, x; \ + randomize_buffers(src_w, src_h); \ + memcpy(src1, src0, pw * ph * sizeof(type)); \ + iter_1d(type, y, 0 - src_h, x, 0 - src_w, src_w - 0); \ + iter_1d(type, x, src_w - 0, y, 0 - src_h, src_h - 0); \ + iter_1d(type, y, src_h - 0, x, 0 - src_w, src_w - 0); \ + iter_1d(type, x, 0 - src_w, y, 0 - src_h, src_h - 0); \ + } while (0) + +#define check_emu_edge(type) \ + do { \ + LOCAL_ALIGNED_16(type, dst0, [64 * 64]); \ + LOCAL_ALIGNED_16(type, dst1, [64 * 64]); \ + declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, \ + void, type *dst, const type *src, \ + ptrdiff_t dst_linesize, \ + ptrdiff_t src_linesize, \ + int block_w, int block_h, \ + int src_x, int src_y, \ + int src_w, int src_h); \ + check_emu_edge_size(type, 16, 1, 64, 64); \ + check_emu_edge_size(type, 16, 16, 64, 64); \ + check_emu_edge_size(type, 64, 64, 64, 64); \ + } while (0) + +void checkasm_check_videodsp(void) +{ + VideoDSPContext vdsp; + + ff_videodsp_init(&vdsp, 8); + if (check_func(vdsp.emulated_edge_mc, "emulated_edge_mc_8")) + check_emu_edge(uint8_t); + + report("emulated_edge_mc"); +} diff --git a/tests/checkasm/vp8dsp.c b/tests/checkasm/vp8dsp.c index 40e4061228..d93f73087f 100644 --- a/tests/checkasm/vp8dsp.c +++ b/tests/checkasm/vp8dsp.c @@ -1,20 +1,20 @@ /* * Copyright (c) 2016 Martin Storsjo * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/tests/checkasm/vp9dsp.c b/tests/checkasm/vp9dsp.c index 39b82e165b..a91577b94e 100644 --- a/tests/checkasm/vp9dsp.c +++ b/tests/checkasm/vp9dsp.c @@ -1,44 +1,105 @@ /* * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or modify + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software Foundation, Inc., + * with FFmpeg; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include <math.h> #include <string.h> - +#include "checkasm.h" +#include "libavcodec/vp9data.h" +#include "libavcodec/vp9.h" #include "libavutil/common.h" #include "libavutil/internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/mathematics.h" -#include "libavcodec/vp9.h" -#include "libavcodec/vp9data.h" +static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff }; +#define SIZEOF_PIXEL ((bit_depth + 7) / 8) + +#define randomize_buffers() \ + do { \ + uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \ + int k; \ + for (k = -4; k < SIZEOF_PIXEL * FFMAX(8, size); k += 4) { \ + uint32_t r = rnd() & mask; \ + AV_WN32A(a + k, r); \ + } \ + for (k = 0; k < size * SIZEOF_PIXEL; k += 4) { \ + uint32_t r = rnd() & mask; \ + AV_WN32A(l + k, r); \ + } \ + } while (0) -#include "checkasm.h" +static void check_ipred(void) +{ + LOCAL_ALIGNED_32(uint8_t, a_buf, [64 * 2]); + uint8_t *a = &a_buf[32 * 2]; + LOCAL_ALIGNED_32(uint8_t, l, [32 * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]); + VP9DSPContext dsp; + int tx, mode, bit_depth; + declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, + const uint8_t *left, const uint8_t *top); + static const char *const mode_names[N_INTRA_PRED_MODES] = { + [VERT_PRED] = "vert", + [HOR_PRED] = "hor", + [DC_PRED] = "dc", + [DIAG_DOWN_LEFT_PRED] = "diag_downleft", + [DIAG_DOWN_RIGHT_PRED] = "diag_downright", + [VERT_RIGHT_PRED] = "vert_right", + [HOR_DOWN_PRED] = "hor_down", + [VERT_LEFT_PRED] = "vert_left", + [HOR_UP_PRED] = "hor_up", + [TM_VP8_PRED] = "tm", + [LEFT_DC_PRED] = "dc_left", + [TOP_DC_PRED] = "dc_top", + [DC_128_PRED] = "dc_128", + [DC_127_PRED] = "dc_127", + [DC_129_PRED] = "dc_129", + }; -static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff }; + for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) { + ff_vp9dsp_init(&dsp, bit_depth, 0); + for (tx = 0; tx < 4; tx++) { + int size = 4 << tx; -#define BIT_DEPTH 8 -#define SIZEOF_PIXEL ((BIT_DEPTH + 7) / 8) + for (mode = 0; mode < N_INTRA_PRED_MODES; mode++) { + if (check_func(dsp.intra_pred[tx][mode], "vp9_%s_%dx%d_%dbpp", + mode_names[mode], size, size, bit_depth)) { + randomize_buffers(); + call_ref(dst0, size * SIZEOF_PIXEL, l, a); + call_new(dst1, size * SIZEOF_PIXEL, l, a); + if (memcmp(dst0, dst1, size * size * SIZEOF_PIXEL)) + fail(); + bench_new(dst1, size * SIZEOF_PIXEL,l, a); + } + } + } + } + report("ipred"); +} + +#undef randomize_buffers #define randomize_buffers() \ do { \ - uint32_t mask = pixel_mask[(BIT_DEPTH - 8) >> 1]; \ + uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \ for (y = 0; y < sz; y++) { \ for (x = 0; x < sz * SIZEOF_PIXEL; x += 4) { \ uint32_t r = rnd() & mask; \ @@ -46,7 +107,7 @@ static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff }; AV_WN32A(src + y * sz * SIZEOF_PIXEL + x, rnd() & mask); \ } \ for (x = 0; x < sz; x++) { \ - if (BIT_DEPTH == 8) { \ + if (bit_depth == 8) { \ coef[y * sz + x] = src[y * sz + x] - dst[y * sz + x]; \ } else { \ ((int32_t *) coef)[y * sz + x] = \ @@ -243,67 +304,69 @@ static int iszero(const int16_t *c, int sz) return 1; } -#define SIZEOF_COEF (2 * ((BIT_DEPTH + 7) / 8)) +#define SIZEOF_COEF (2 * ((bit_depth + 7) / 8)) static void check_itxfm(void) { LOCAL_ALIGNED_32(uint8_t, src, [32 * 32 * 2]); - LOCAL_ALIGNED(32, uint8_t, dst, [32 * 32 * 2]); - LOCAL_ALIGNED(32, uint8_t, dst0, [32 * 32 * 2]); - LOCAL_ALIGNED(32, uint8_t, dst1, [32 * 32 * 2]); - LOCAL_ALIGNED(32, int16_t, coef, [32 * 32 * 2]); - LOCAL_ALIGNED(32, int16_t, subcoef0, [32 * 32 * 2]); - LOCAL_ALIGNED(32, int16_t, subcoef1, [32 * 32 * 2]); - declare_func(void, uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob); + LOCAL_ALIGNED_32(uint8_t, dst, [32 * 32 * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]); + LOCAL_ALIGNED_32(int16_t, coef, [32 * 32 * 2]); + LOCAL_ALIGNED_32(int16_t, subcoef0, [32 * 32 * 2]); + LOCAL_ALIGNED_32(int16_t, subcoef1, [32 * 32 * 2]); + declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob); VP9DSPContext dsp; - int y, x, tx, txtp, sub; + int y, x, tx, txtp, bit_depth, sub; static const char *const txtp_types[N_TXFM_TYPES] = { [DCT_DCT] = "dct_dct", [DCT_ADST] = "adst_dct", [ADST_DCT] = "dct_adst", [ADST_ADST] = "adst_adst" }; - ff_vp9dsp_init(&dsp); - - for (tx = TX_4X4; tx <= N_TXFM_SIZES /* 4 = lossless */; tx++) { - int sz = 4 << (tx & 3); - int n_txtps = tx < TX_32X32 ? N_TXFM_TYPES : 1; - - for (txtp = 0; txtp < n_txtps; txtp++) { - // skip testing sub-IDCTs for WHT or ADST since they don't - // implement it in any of the SIMD functions. If they do, - // consider changing this to ensure we have complete test - // coverage. Test sub=1 for dc-only, then 2, 4, 8, 12, etc, - // since the arm version can distinguish them at that level. - for (sub = (txtp == 0 && tx < 4) ? 1 : sz; sub <= sz; - sub < 4 ? (sub <<= 1) : (sub += 4)) { - if (check_func(dsp.itxfm_add[tx][txtp], - "vp9_inv_%s_%dx%d_sub%d_add", - tx == 4 ? "wht_wht" : txtp_types[txtp], - sz, sz, sub)) { - int eob; + for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) { + ff_vp9dsp_init(&dsp, bit_depth, 0); + + for (tx = TX_4X4; tx <= N_TXFM_SIZES /* 4 = lossless */; tx++) { + int sz = 4 << (tx & 3); + int n_txtps = tx < TX_32X32 ? N_TXFM_TYPES : 1; + + for (txtp = 0; txtp < n_txtps; txtp++) { + // skip testing sub-IDCTs for WHT or ADST since they don't + // implement it in any of the SIMD functions. If they do, + // consider changing this to ensure we have complete test + // coverage. Test sub=1 for dc-only, then 2, 4, 8, 12, etc, + // since the arm version can distinguish them at that level. + for (sub = (txtp == 0 && tx < 4) ? 1 : sz; sub <= sz; + sub < 4 ? (sub <<= 1) : (sub += 4)) { + if (check_func(dsp.itxfm_add[tx][txtp], + "vp9_inv_%s_%dx%d_sub%d_add_%d", + tx == 4 ? "wht_wht" : txtp_types[txtp], + sz, sz, sub, bit_depth)) { + int eob; + + randomize_buffers(); + ftx(coef, tx, txtp, sz, bit_depth); + + if (sub < sz) { + eob = copy_subcoefs(subcoef0, coef, tx, txtp, + sz, sub, bit_depth); + } else { + eob = sz * sz; + memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF); + } - randomize_buffers(); - ftx(coef, tx, txtp, sz, BIT_DEPTH); - - if (sub < sz) { - eob = copy_subcoefs(subcoef0, coef, tx, txtp, - sz, sub, BIT_DEPTH); - } else { - eob = sz * sz; - memcpy(subcoef0, coef, sz * sz * SIZEOF_COEF); + memcpy(dst0, dst, sz * sz * SIZEOF_PIXEL); + memcpy(dst1, dst, sz * sz * SIZEOF_PIXEL); + memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF); + call_ref(dst0, sz * SIZEOF_PIXEL, subcoef0, eob); + call_new(dst1, sz * SIZEOF_PIXEL, subcoef1, eob); + if (memcmp(dst0, dst1, sz * sz * SIZEOF_PIXEL) || + !iszero(subcoef0, sz * sz * SIZEOF_COEF) || + !iszero(subcoef1, sz * sz * SIZEOF_COEF)) + fail(); + + bench_new(dst, sz * SIZEOF_PIXEL, coef, eob); } - - memcpy(dst0, dst, sz * sz * SIZEOF_PIXEL); - memcpy(dst1, dst, sz * sz * SIZEOF_PIXEL); - memcpy(subcoef1, subcoef0, sz * sz * SIZEOF_COEF); - call_ref(dst0, sz * SIZEOF_PIXEL, subcoef0, eob); - call_new(dst1, sz * SIZEOF_PIXEL, subcoef1, eob); - if (memcmp(dst0, dst1, sz * sz * SIZEOF_PIXEL) || - !iszero(subcoef0, sz * sz * SIZEOF_COEF) || - !iszero(subcoef1, sz * sz * SIZEOF_COEF)) - fail(); - - bench_new(dst, sz * SIZEOF_PIXEL, coef, eob); } } } @@ -318,19 +381,19 @@ static void check_itxfm(void) if (SIZEOF_PIXEL == 1) { \ buf0[(a) + (b) * jstride] = av_clip_uint8(c); \ } else { \ - ((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, BIT_DEPTH); \ + ((uint16_t *)buf0)[(a) + (b) * jstride] = av_clip_uintp2(c, bit_depth); \ } \ } while (0) -#define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1))) -#define setsx(a,b,c,d) setdx(a,b,c,(d) << (BIT_DEPTH - 8)) +// c can be an assignment and must not be put under () +#define setdx(a,b,c,d) setpx(a,b,c-(d)+(rnd()%((d)*2+1))) +#define setsx(a,b,c,d) setdx(a,b,c,(d) << (bit_depth - 8)) static void randomize_loopfilter_buffers(int bidx, int lineoff, int str, - int bit_depth, int dir, - const int *E, const int *F, - const int *H, const int *I, + int bit_depth, int dir, const int *E, + const int *F, const int *H, const int *I, uint8_t *buf0, uint8_t *buf1) { - uint32_t mask = (1 << BIT_DEPTH) - 1; + uint32_t mask = (1 << bit_depth) - 1; int off = dir ? lineoff : lineoff * 16; int istride = dir ? 1 : 16; int jstride = dir ? str : 1; @@ -380,84 +443,83 @@ static void randomize_loopfilter_buffers(int bidx, int lineoff, int str, } } } - -#define randomize_buffers(bidx, lineoff, str) \ - randomize_loopfilter_buffers(bidx, lineoff, str, BIT_DEPTH, dir, \ - E, F, H, I, buf0, buf1) +#define randomize_buffers(bidx, lineoff, str) \ + randomize_loopfilter_buffers(bidx, lineoff, str, bit_depth, dir, \ + E, F, H, I, buf0, buf1) static void check_loopfilter(void) { LOCAL_ALIGNED_32(uint8_t, base0, [32 + 16 * 16 * 2]); LOCAL_ALIGNED_32(uint8_t, base1, [32 + 16 * 16 * 2]); VP9DSPContext dsp; - int dir, wd, wd2; + int dir, wd, wd2, bit_depth; static const char *const dir_name[2] = { "h", "v" }; static const int E[2] = { 20, 28 }, I[2] = { 10, 16 }; - static const int H[2] = { 7, 11 }, F[2] = { 1, 1 }; - declare_func(void, uint8_t *dst, ptrdiff_t stride, int E, int I, int H); - - ff_vp9dsp_init(&dsp); - - for (dir = 0; dir < 2; dir++) { - uint8_t *buf0, *buf1; - int midoff = (dir ? 8 * 8 : 8) * SIZEOF_PIXEL; - int midoff_aligned = (dir ? 8 * 8 : 16) * SIZEOF_PIXEL; - - buf0 = base0 + midoff_aligned; - buf1 = base1 + midoff_aligned; - - for (wd = 0; wd < 3; wd++) { - // 4/8/16wd_8px - if (check_func(dsp.loop_filter_8[wd][dir], - "vp9_loop_filter_%s_%d_8", - dir_name[dir], 4 << wd)) { - randomize_buffers(0, 0, 8); - memcpy(buf1 - midoff, buf0 - midoff, - 16 * 8 * SIZEOF_PIXEL); - call_ref(buf0, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]); - call_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]); - if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 * SIZEOF_PIXEL)) - fail(); - bench_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]); + static const int H[2] = { 7, 11 }, F[2] = { 1, 1 }; + declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t stride, int E, int I, int H); + + for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) { + ff_vp9dsp_init(&dsp, bit_depth, 0); + + for (dir = 0; dir < 2; dir++) { + int midoff = (dir ? 8 * 8 : 8) * SIZEOF_PIXEL; + int midoff_aligned = (dir ? 8 * 8 : 16) * SIZEOF_PIXEL; + uint8_t *buf0 = base0 + midoff_aligned; + uint8_t *buf1 = base1 + midoff_aligned; + + for (wd = 0; wd < 3; wd++) { + // 4/8/16wd_8px + if (check_func(dsp.loop_filter_8[wd][dir], + "vp9_loop_filter_%s_%d_8_%dbpp", + dir_name[dir], 4 << wd, bit_depth)) { + randomize_buffers(0, 0, 8); + memcpy(buf1 - midoff, buf0 - midoff, + 16 * 8 * SIZEOF_PIXEL); + call_ref(buf0, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]); + call_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]); + if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 8 * SIZEOF_PIXEL)) + fail(); + bench_new(buf1, 16 * SIZEOF_PIXEL >> dir, E[0], I[0], H[0]); + } } - } - midoff = (dir ? 16 * 8 : 8) * SIZEOF_PIXEL; - midoff_aligned = (dir ? 16 * 8 : 16) * SIZEOF_PIXEL; - - buf0 = base0 + midoff_aligned; - buf1 = base1 + midoff_aligned; - - // 16wd_16px loopfilter - if (check_func(dsp.loop_filter_16[dir], - "vp9_loop_filter_%s_16_16", - dir_name[dir])) { - randomize_buffers(0, 0, 16); - randomize_buffers(0, 8, 16); - memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL); - call_ref(buf0, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]); - call_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]); - if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL)) - fail(); - bench_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]); - } + midoff = (dir ? 16 * 8 : 8) * SIZEOF_PIXEL; + midoff_aligned = (dir ? 16 * 8 : 16) * SIZEOF_PIXEL; + + buf0 = base0 + midoff_aligned; + buf1 = base1 + midoff_aligned; + + // 16wd_16px loopfilter + if (check_func(dsp.loop_filter_16[dir], + "vp9_loop_filter_%s_16_16_%dbpp", + dir_name[dir], bit_depth)) { + randomize_buffers(0, 0, 16); + randomize_buffers(0, 8, 16); + memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL); + call_ref(buf0, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]); + call_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]); + if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL)) + fail(); + bench_new(buf1, 16 * SIZEOF_PIXEL, E[0], I[0], H[0]); + } - for (wd = 0; wd < 2; wd++) { - for (wd2 = 0; wd2 < 2; wd2++) { - // mix2 loopfilter - if (check_func(dsp.loop_filter_mix2[wd][wd2][dir], - "vp9_loop_filter_mix2_%s_%d%d_16", - dir_name[dir], 4 << wd, 4 << wd2)) { - randomize_buffers(0, 0, 16); - randomize_buffers(1, 8, 16); - memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL); -#define M(a) ((a[1] << 8) | a[0]) - call_ref(buf0, 16 * SIZEOF_PIXEL, M(E), M(I), M(H)); - call_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H)); - if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL)) - fail(); - bench_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H)); + for (wd = 0; wd < 2; wd++) { + for (wd2 = 0; wd2 < 2; wd2++) { + // mix2 loopfilter + if (check_func(dsp.loop_filter_mix2[wd][wd2][dir], + "vp9_loop_filter_mix2_%s_%d%d_16_%dbpp", + dir_name[dir], 4 << wd, 4 << wd2, bit_depth)) { + randomize_buffers(0, 0, 16); + randomize_buffers(1, 8, 16); + memcpy(buf1 - midoff, buf0 - midoff, 16 * 16 * SIZEOF_PIXEL); +#define M(a) (((a)[1] << 8) | (a)[0]) + call_ref(buf0, 16 * SIZEOF_PIXEL, M(E), M(I), M(H)); + call_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H)); + if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16 * SIZEOF_PIXEL)) + fail(); + bench_new(buf1, 16 * SIZEOF_PIXEL, M(E), M(I), M(H)); #undef M + } } } } @@ -477,7 +539,7 @@ static void check_loopfilter(void) #define randomize_buffers() \ do { \ - uint32_t mask = pixel_mask[(BIT_DEPTH - 8) >> 1]; \ + uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \ int k; \ for (k = 0; k < SRC_BUF_SIZE; k += 4) { \ uint32_t r = rnd() & mask; \ @@ -494,60 +556,63 @@ static void check_loopfilter(void) static void check_mc(void) { + LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]); + VP9DSPContext dsp; + int op, hsize, bit_depth, filter, dx, dy; + declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, ptrdiff_t dst_stride, + const uint8_t *ref, ptrdiff_t ref_stride, + int h, int mx, int my); static const char *const filter_names[4] = { "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin" }; static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } }; static const char *const op_names[2] = { "put", "avg" }; - - LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]); - LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]); - LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]); char str[256]; - VP9DSPContext dsp; - int op, hsize, filter, dx, dy; - - declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, - void, uint8_t *dst, ptrdiff_t dst_stride, - const uint8_t *ref, ptrdiff_t ref_stride, - int h, int mx, int my); for (op = 0; op < 2; op++) { - ff_vp9dsp_init(&dsp); - for (hsize = 0; hsize < 5; hsize++) { - int size = 64 >> hsize; - - for (filter = 0; filter < 4; filter++) { - for (dx = 0; dx < 2; dx++) { - for (dy = 0; dy < 2; dy++) { - if (dx || dy) { - snprintf(str, sizeof(str), "%s_%s_%d%s", op_names[op], - filter_names[filter], size, - subpel_names[dy][dx]); - } else { - snprintf(str, sizeof(str), "%s%d", op_names[op], size); - } - if (check_func(dsp.mc[hsize][filter][op][dx][dy], - "vp9_%s", str)) { - int mx = dx ? 1 + (rnd() % 14) : 0; - int my = dy ? 1 + (rnd() % 14) : 0; - randomize_buffers(); - call_ref(dst0, size * SIZEOF_PIXEL, - src, SRC_BUF_STRIDE * SIZEOF_PIXEL, - size, mx, my); - call_new(dst1, size * SIZEOF_PIXEL, - src, SRC_BUF_STRIDE * SIZEOF_PIXEL, - size, mx, my); - if (memcmp(dst0, dst1, DST_BUF_SIZE)) - fail(); - - // SIMD implementations for each filter of subpel - // functions are identical - if (filter >= 1 && filter <= 2) continue; - - bench_new(dst1, size * SIZEOF_PIXEL, - src, SRC_BUF_STRIDE * SIZEOF_PIXEL, - size, mx, my); + for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) { + ff_vp9dsp_init(&dsp, bit_depth, 0); + for (hsize = 0; hsize < 5; hsize++) { + int size = 64 >> hsize; + + for (filter = 0; filter < 4; filter++) { + for (dx = 0; dx < 2; dx++) { + for (dy = 0; dy < 2; dy++) { + if (dx || dy) { + snprintf(str, sizeof(str), + "%s_%s_%d%s", op_names[op], + filter_names[filter], size, + subpel_names[dy][dx]); + } else { + snprintf(str, sizeof(str), + "%s%d", op_names[op], size); + } + if (check_func(dsp.mc[hsize][filter][op][dx][dy], + "vp9_%s_%dbpp", str, bit_depth)) { + int mx = dx ? 1 + (rnd() % 14) : 0; + int my = dy ? 1 + (rnd() % 14) : 0; + randomize_buffers(); + call_ref(dst0, size * SIZEOF_PIXEL, + src, SRC_BUF_STRIDE * SIZEOF_PIXEL, + size, mx, my); + call_new(dst1, size * SIZEOF_PIXEL, + src, SRC_BUF_STRIDE * SIZEOF_PIXEL, + size, mx, my); + if (memcmp(dst0, dst1, DST_BUF_SIZE)) + fail(); + + // simd implementations for each filter of subpel + // functions are identical + if (filter >= 1 && filter <= 2) continue; + // 10/12 bpp for bilin are identical + if (bit_depth == 12 && filter == 3) continue; + + bench_new(dst1, size * SIZEOF_PIXEL, + src, SRC_BUF_STRIDE * SIZEOF_PIXEL, + size, mx, my); + } } } } @@ -559,6 +624,7 @@ static void check_mc(void) void checkasm_check_vp9dsp(void) { + check_ipred(); check_itxfm(); check_loopfilter(); check_mc(); diff --git a/tests/checkasm/x86/checkasm.asm b/tests/checkasm/x86/checkasm.asm index 55212fc24b..683aae80e3 100644 --- a/tests/checkasm/x86/checkasm.asm +++ b/tests/checkasm/x86/checkasm.asm @@ -3,14 +3,14 @@ ;* Copyright (c) 2008 Loren Merritt ;* Copyright (c) 2012 Henrik Gramner ;* -;* This file is part of Libav. +;* This file is part of FFmpeg. ;* -;* Libav is free software; you can redistribute it and/or modify +;* 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. ;* -;* Libav is distributed in the hope that it will be useful, +;* 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. @@ -169,15 +169,15 @@ cglobal checked_call%1, 2,15,16,max_args*8+8 jz .clobber_ok report_fail error_message .clobber_ok: -%ifnid %1, _emms +%ifidn %1, _emms + emms +%elifnidn %1, _float fstenv [rsp] cmp word [rsp + 8], 0xffff je .emms_ok report_fail error_message_emms emms .emms_ok: -%else - emms %endif RET %endmacro @@ -223,15 +223,15 @@ cglobal checked_call%1, 1,7 jz .clobber_ok report_fail error_message .clobber_ok: -%ifnid %1, _emms +%ifidn %1, _emms + emms +%elifnidn %1, _float fstenv [esp] cmp word [esp + 8], 0xffff je .emms_ok report_fail error_message_emms emms .emms_ok: -%else - emms %endif add esp, max_args*4 REP_RET @@ -241,3 +241,4 @@ cglobal checked_call%1, 1,7 CHECKED_CALL CHECKED_CALL _emms +CHECKED_CALL _float |