1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * Copyright (c) 2015 Tiancheng "Timothy" Gu 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * This file is part of FFmpeg. 5cabdff1aSopenharmony_ci * 6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or modify 7cabdff1aSopenharmony_ci * it under the terms of the GNU General Public License as published by 8cabdff1aSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 9cabdff1aSopenharmony_ci * (at your option) any later version. 10cabdff1aSopenharmony_ci * 11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14cabdff1aSopenharmony_ci * GNU General Public License for more details. 15cabdff1aSopenharmony_ci * 16cabdff1aSopenharmony_ci * You should have received a copy of the GNU General Public License along 17cabdff1aSopenharmony_ci * with FFmpeg; if not, write to the Free Software Foundation, Inc., 18cabdff1aSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19cabdff1aSopenharmony_ci */ 20cabdff1aSopenharmony_ci 21cabdff1aSopenharmony_ci#include <string.h> 22cabdff1aSopenharmony_ci#include "checkasm.h" 23cabdff1aSopenharmony_ci#include "libavcodec/pixblockdsp.h" 24cabdff1aSopenharmony_ci#include "libavutil/common.h" 25cabdff1aSopenharmony_ci#include "libavutil/internal.h" 26cabdff1aSopenharmony_ci#include "libavutil/intreadwrite.h" 27cabdff1aSopenharmony_ci#include "libavutil/mem_internal.h" 28cabdff1aSopenharmony_ci 29cabdff1aSopenharmony_ci#define BUF_UNITS 8 30cabdff1aSopenharmony_ci#define BUF_SIZE (BUF_UNITS * 128 + 8 * BUF_UNITS) 31cabdff1aSopenharmony_ci 32cabdff1aSopenharmony_ci#define randomize_buffers() \ 33cabdff1aSopenharmony_ci do { \ 34cabdff1aSopenharmony_ci int i; \ 35cabdff1aSopenharmony_ci for (i = 0; i < BUF_SIZE; i += 4) { \ 36cabdff1aSopenharmony_ci uint32_t r = rnd(); \ 37cabdff1aSopenharmony_ci AV_WN32A(src10 + i, r); \ 38cabdff1aSopenharmony_ci AV_WN32A(src11 + i, r); \ 39cabdff1aSopenharmony_ci r = rnd(); \ 40cabdff1aSopenharmony_ci AV_WN32A(src20 + i, r); \ 41cabdff1aSopenharmony_ci AV_WN32A(src21 + i, r); \ 42cabdff1aSopenharmony_ci r = rnd(); \ 43cabdff1aSopenharmony_ci AV_WN32A(dst0_ + i, r); \ 44cabdff1aSopenharmony_ci AV_WN32A(dst1_ + i, r); \ 45cabdff1aSopenharmony_ci } \ 46cabdff1aSopenharmony_ci } while (0) 47cabdff1aSopenharmony_ci 48cabdff1aSopenharmony_ci#define check_get_pixels(type, aligned) \ 49cabdff1aSopenharmony_ci do { \ 50cabdff1aSopenharmony_ci int i; \ 51cabdff1aSopenharmony_ci declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t *block, const uint8_t *pixels, ptrdiff_t line_size); \ 52cabdff1aSopenharmony_ci \ 53cabdff1aSopenharmony_ci for (i = 0; i < BUF_UNITS; i++) { \ 54cabdff1aSopenharmony_ci int src_offset = i * 64 * sizeof(type) + (aligned ? 8 : 1) * i; \ 55cabdff1aSopenharmony_ci int dst_offset = i * 64; /* dst must be aligned */ \ 56cabdff1aSopenharmony_ci randomize_buffers(); \ 57cabdff1aSopenharmony_ci call_ref(dst0 + dst_offset, src10 + src_offset, 8); \ 58cabdff1aSopenharmony_ci call_new(dst1 + dst_offset, src11 + src_offset, 8); \ 59cabdff1aSopenharmony_ci if (memcmp(src10, src11, BUF_SIZE)|| memcmp(dst0, dst1, BUF_SIZE)) \ 60cabdff1aSopenharmony_ci fail(); \ 61cabdff1aSopenharmony_ci bench_new(dst1 + dst_offset, src11 + src_offset, 8); \ 62cabdff1aSopenharmony_ci } \ 63cabdff1aSopenharmony_ci } while (0) 64cabdff1aSopenharmony_ci 65cabdff1aSopenharmony_ci#define check_diff_pixels(type, aligned) \ 66cabdff1aSopenharmony_ci do { \ 67cabdff1aSopenharmony_ci int i; \ 68cabdff1aSopenharmony_ci declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t *av_restrict block, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride); \ 69cabdff1aSopenharmony_ci \ 70cabdff1aSopenharmony_ci for (i = 0; i < BUF_UNITS; i++) { \ 71cabdff1aSopenharmony_ci int src_offset = i * 64 * sizeof(type) + (aligned ? 8 : 1) * i; \ 72cabdff1aSopenharmony_ci int dst_offset = i * 64; /* dst must be aligned */ \ 73cabdff1aSopenharmony_ci randomize_buffers(); \ 74cabdff1aSopenharmony_ci call_ref(dst0 + dst_offset, src10 + src_offset, src20 + src_offset, 8); \ 75cabdff1aSopenharmony_ci call_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \ 76cabdff1aSopenharmony_ci if (memcmp(src10, src11, BUF_SIZE) || memcmp(src20, src21, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE)) \ 77cabdff1aSopenharmony_ci fail(); \ 78cabdff1aSopenharmony_ci bench_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \ 79cabdff1aSopenharmony_ci } \ 80cabdff1aSopenharmony_ci } while (0) 81cabdff1aSopenharmony_ci 82cabdff1aSopenharmony_civoid checkasm_check_pixblockdsp(void) 83cabdff1aSopenharmony_ci{ 84cabdff1aSopenharmony_ci LOCAL_ALIGNED_16(uint8_t, src10, [BUF_SIZE]); 85cabdff1aSopenharmony_ci LOCAL_ALIGNED_16(uint8_t, src11, [BUF_SIZE]); 86cabdff1aSopenharmony_ci LOCAL_ALIGNED_16(uint8_t, src20, [BUF_SIZE]); 87cabdff1aSopenharmony_ci LOCAL_ALIGNED_16(uint8_t, src21, [BUF_SIZE]); 88cabdff1aSopenharmony_ci LOCAL_ALIGNED_16(uint8_t, dst0_, [BUF_SIZE]); 89cabdff1aSopenharmony_ci LOCAL_ALIGNED_16(uint8_t, dst1_, [BUF_SIZE]); 90cabdff1aSopenharmony_ci uint16_t *dst0 = (uint16_t *)dst0_; 91cabdff1aSopenharmony_ci uint16_t *dst1 = (uint16_t *)dst1_; 92cabdff1aSopenharmony_ci PixblockDSPContext h; 93cabdff1aSopenharmony_ci AVCodecContext avctx = { 94cabdff1aSopenharmony_ci .bits_per_raw_sample = 8, 95cabdff1aSopenharmony_ci }; 96cabdff1aSopenharmony_ci 97cabdff1aSopenharmony_ci ff_pixblockdsp_init(&h, &avctx); 98cabdff1aSopenharmony_ci 99cabdff1aSopenharmony_ci if (check_func(h.get_pixels, "get_pixels")) 100cabdff1aSopenharmony_ci check_get_pixels(uint8_t, 1); 101cabdff1aSopenharmony_ci if (check_func(h.get_pixels_unaligned, "get_pixels_unaligned")) 102cabdff1aSopenharmony_ci check_get_pixels(uint8_t, 0); 103cabdff1aSopenharmony_ci 104cabdff1aSopenharmony_ci report("get_pixels"); 105cabdff1aSopenharmony_ci 106cabdff1aSopenharmony_ci if (check_func(h.diff_pixels, "diff_pixels")) 107cabdff1aSopenharmony_ci check_diff_pixels(uint8_t, 1); 108cabdff1aSopenharmony_ci if (check_func(h.diff_pixels_unaligned, "diff_pixels_unaligned")) 109cabdff1aSopenharmony_ci check_diff_pixels(uint8_t, 0); 110cabdff1aSopenharmony_ci 111cabdff1aSopenharmony_ci report("diff_pixels"); 112cabdff1aSopenharmony_ci} 113