1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * Copyright (c) 2015 Manojkumar Bhosale (Manojkumar.Bhosale@imgtec.com) 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * This file is part of FFmpeg. 5cabdff1aSopenharmony_ci * 6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 9cabdff1aSopenharmony_ci * version 2.1 of the License, or (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 GNU 14cabdff1aSopenharmony_ci * Lesser General Public License for more details. 15cabdff1aSopenharmony_ci * 16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19cabdff1aSopenharmony_ci */ 20cabdff1aSopenharmony_ci 21cabdff1aSopenharmony_ci#include <string.h> 22cabdff1aSopenharmony_ci#include "libavcodec/vp8dsp.h" 23cabdff1aSopenharmony_ci#include "libavutil/mips/generic_macros_msa.h" 24cabdff1aSopenharmony_ci#include "vp8dsp_mips.h" 25cabdff1aSopenharmony_ci 26cabdff1aSopenharmony_cistatic const int cospi8sqrt2minus1 = 20091; 27cabdff1aSopenharmony_cistatic const int sinpi8sqrt2 = 35468; 28cabdff1aSopenharmony_ci 29cabdff1aSopenharmony_ci#define VP8_IDCT_1D_W(in0, in1, in2, in3, out0, out1, out2, out3) \ 30cabdff1aSopenharmony_ci{ \ 31cabdff1aSopenharmony_ci v4i32 a1_m, b1_m, c1_m, d1_m; \ 32cabdff1aSopenharmony_ci v4i32 c_tmp1_m, c_tmp2_m, d_tmp1_m, d_tmp2_m; \ 33cabdff1aSopenharmony_ci v4i32 const_cospi8sqrt2minus1_m, sinpi8_sqrt2_m; \ 34cabdff1aSopenharmony_ci \ 35cabdff1aSopenharmony_ci const_cospi8sqrt2minus1_m = __msa_fill_w(cospi8sqrt2minus1); \ 36cabdff1aSopenharmony_ci sinpi8_sqrt2_m = __msa_fill_w(sinpi8sqrt2); \ 37cabdff1aSopenharmony_ci a1_m = in0 + in2; \ 38cabdff1aSopenharmony_ci b1_m = in0 - in2; \ 39cabdff1aSopenharmony_ci c_tmp1_m = ((in1) * sinpi8_sqrt2_m) >> 16; \ 40cabdff1aSopenharmony_ci c_tmp2_m = in3 + (((in3) * const_cospi8sqrt2minus1_m) >> 16); \ 41cabdff1aSopenharmony_ci c1_m = c_tmp1_m - c_tmp2_m; \ 42cabdff1aSopenharmony_ci d_tmp1_m = (in1) + (((in1) * const_cospi8sqrt2minus1_m) >> 16); \ 43cabdff1aSopenharmony_ci d_tmp2_m = ((in3) * sinpi8_sqrt2_m) >> 16; \ 44cabdff1aSopenharmony_ci d1_m = d_tmp1_m + d_tmp2_m; \ 45cabdff1aSopenharmony_ci BUTTERFLY_4(a1_m, b1_m, c1_m, d1_m, out0, out1, out2, out3); \ 46cabdff1aSopenharmony_ci} 47cabdff1aSopenharmony_ci 48cabdff1aSopenharmony_civoid ff_vp8_idct_add_msa(uint8_t *dst, int16_t input[16], ptrdiff_t stride) 49cabdff1aSopenharmony_ci{ 50cabdff1aSopenharmony_ci v8i16 input0, input1; 51cabdff1aSopenharmony_ci v4i32 in0, in1, in2, in3, hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3; 52cabdff1aSopenharmony_ci v4i32 res0, res1, res2, res3; 53cabdff1aSopenharmony_ci v16i8 zero = { 0 }; 54cabdff1aSopenharmony_ci v16i8 pred0, pred1, pred2, pred3, dest0, dest1; 55cabdff1aSopenharmony_ci v16i8 mask = { 0, 4, 8, 12, 16, 20, 24, 28, 0, 0, 0, 0, 0, 0, 0, 0 }; 56cabdff1aSopenharmony_ci 57cabdff1aSopenharmony_ci /* load short vector elements of 4x4 block */ 58cabdff1aSopenharmony_ci LD_SH2(input, 8, input0, input1); 59cabdff1aSopenharmony_ci UNPCK_SH_SW(input0, in0, in1); 60cabdff1aSopenharmony_ci UNPCK_SH_SW(input1, in2, in3); 61cabdff1aSopenharmony_ci VP8_IDCT_1D_W(in0, in1, in2, in3, hz0, hz1, hz2, hz3); 62cabdff1aSopenharmony_ci /* transpose the block */ 63cabdff1aSopenharmony_ci TRANSPOSE4x4_SW_SW(hz0, hz1, hz2, hz3, hz0, hz1, hz2, hz3); 64cabdff1aSopenharmony_ci VP8_IDCT_1D_W(hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3); 65cabdff1aSopenharmony_ci SRARI_W4_SW(vt0, vt1, vt2, vt3, 3); 66cabdff1aSopenharmony_ci /* transpose the block */ 67cabdff1aSopenharmony_ci TRANSPOSE4x4_SW_SW(vt0, vt1, vt2, vt3, vt0, vt1, vt2, vt3); 68cabdff1aSopenharmony_ci LD_SB4(dst, stride, pred0, pred1, pred2, pred3); 69cabdff1aSopenharmony_ci ILVR_B4_SW(zero, pred0, zero, pred1, zero, pred2, zero, pred3, 70cabdff1aSopenharmony_ci res0, res1, res2, res3); 71cabdff1aSopenharmony_ci ILVR_H4_SW(zero, res0, zero, res1, zero, res2, zero, res3, 72cabdff1aSopenharmony_ci res0, res1, res2, res3); 73cabdff1aSopenharmony_ci ADD4(res0, vt0, res1, vt1, res2, vt2, res3, vt3, res0, res1, res2, res3); 74cabdff1aSopenharmony_ci CLIP_SW4_0_255(res0, res1, res2, res3); 75cabdff1aSopenharmony_ci VSHF_B2_SB(res0, res1, res2, res3, mask, mask, dest0, dest1); 76cabdff1aSopenharmony_ci ST_W2(dest0, 0, 1, dst, stride); 77cabdff1aSopenharmony_ci ST_W2(dest1, 0, 1, dst + 2 * stride, stride); 78cabdff1aSopenharmony_ci 79cabdff1aSopenharmony_ci memset(input, 0, 4 * 4 * sizeof(*input)); 80cabdff1aSopenharmony_ci} 81cabdff1aSopenharmony_ci 82cabdff1aSopenharmony_civoid ff_vp8_idct_dc_add_msa(uint8_t *dst, int16_t in_dc[16], ptrdiff_t stride) 83cabdff1aSopenharmony_ci{ 84cabdff1aSopenharmony_ci v8i16 vec; 85cabdff1aSopenharmony_ci v8i16 res0, res1, res2, res3; 86cabdff1aSopenharmony_ci v16i8 zero = { 0 }; 87cabdff1aSopenharmony_ci v16i8 pred0, pred1, pred2, pred3, dest0, dest1; 88cabdff1aSopenharmony_ci v16i8 mask = { 0, 2, 4, 6, 16, 18, 20, 22, 0, 0, 0, 0, 0, 0, 0, 0 }; 89cabdff1aSopenharmony_ci 90cabdff1aSopenharmony_ci vec = __msa_fill_h(in_dc[0]); 91cabdff1aSopenharmony_ci vec = __msa_srari_h(vec, 3); 92cabdff1aSopenharmony_ci LD_SB4(dst, stride, pred0, pred1, pred2, pred3); 93cabdff1aSopenharmony_ci ILVR_B4_SH(zero, pred0, zero, pred1, zero, pred2, zero, pred3, 94cabdff1aSopenharmony_ci res0, res1, res2, res3); 95cabdff1aSopenharmony_ci ADD4(res0, vec, res1, vec, res2, vec, res3, vec, res0, res1, res2, res3); 96cabdff1aSopenharmony_ci CLIP_SH4_0_255(res0, res1, res2, res3); 97cabdff1aSopenharmony_ci VSHF_B2_SB(res0, res1, res2, res3, mask, mask, dest0, dest1); 98cabdff1aSopenharmony_ci ST_W2(dest0, 0, 1, dst, stride); 99cabdff1aSopenharmony_ci ST_W2(dest1, 0, 1, dst + 2 * stride, stride); 100cabdff1aSopenharmony_ci 101cabdff1aSopenharmony_ci in_dc[0] = 0; 102cabdff1aSopenharmony_ci} 103cabdff1aSopenharmony_ci 104cabdff1aSopenharmony_civoid ff_vp8_luma_dc_wht_msa(int16_t block[4][4][16], int16_t input[16]) 105cabdff1aSopenharmony_ci{ 106cabdff1aSopenharmony_ci int16_t *mb_dq_coeff = &block[0][0][0]; 107cabdff1aSopenharmony_ci v8i16 input0, input1; 108cabdff1aSopenharmony_ci v4i32 in0, in1, in2, in3, a1, b1, c1, d1; 109cabdff1aSopenharmony_ci v4i32 hz0, hz1, hz2, hz3, vt0, vt1, vt2, vt3; 110cabdff1aSopenharmony_ci 111cabdff1aSopenharmony_ci /* load short vector elements of 4x4 block */ 112cabdff1aSopenharmony_ci LD_SH2(input, 8, input0, input1); 113cabdff1aSopenharmony_ci UNPCK_SH_SW(input0, in0, in1); 114cabdff1aSopenharmony_ci UNPCK_SH_SW(input1, in2, in3); 115cabdff1aSopenharmony_ci BUTTERFLY_4(in0, in1, in2, in3, a1, b1, c1, d1); 116cabdff1aSopenharmony_ci BUTTERFLY_4(a1, d1, c1, b1, hz0, hz1, hz3, hz2); 117cabdff1aSopenharmony_ci /* transpose the block */ 118cabdff1aSopenharmony_ci TRANSPOSE4x4_SW_SW(hz0, hz1, hz2, hz3, hz0, hz1, hz2, hz3); 119cabdff1aSopenharmony_ci BUTTERFLY_4(hz0, hz1, hz2, hz3, a1, b1, c1, d1); 120cabdff1aSopenharmony_ci BUTTERFLY_4(a1, d1, c1, b1, vt0, vt1, vt3, vt2); 121cabdff1aSopenharmony_ci ADD4(vt0, 3, vt1, 3, vt2, 3, vt3, 3, vt0, vt1, vt2, vt3); 122cabdff1aSopenharmony_ci SRA_4V(vt0, vt1, vt2, vt3, 3); 123cabdff1aSopenharmony_ci mb_dq_coeff[0] = __msa_copy_s_h((v8i16) vt0, 0); 124cabdff1aSopenharmony_ci mb_dq_coeff[16] = __msa_copy_s_h((v8i16) vt1, 0); 125cabdff1aSopenharmony_ci mb_dq_coeff[32] = __msa_copy_s_h((v8i16) vt2, 0); 126cabdff1aSopenharmony_ci mb_dq_coeff[48] = __msa_copy_s_h((v8i16) vt3, 0); 127cabdff1aSopenharmony_ci mb_dq_coeff[64] = __msa_copy_s_h((v8i16) vt0, 2); 128cabdff1aSopenharmony_ci mb_dq_coeff[80] = __msa_copy_s_h((v8i16) vt1, 2); 129cabdff1aSopenharmony_ci mb_dq_coeff[96] = __msa_copy_s_h((v8i16) vt2, 2); 130cabdff1aSopenharmony_ci mb_dq_coeff[112] = __msa_copy_s_h((v8i16) vt3, 2); 131cabdff1aSopenharmony_ci mb_dq_coeff[128] = __msa_copy_s_h((v8i16) vt0, 4); 132cabdff1aSopenharmony_ci mb_dq_coeff[144] = __msa_copy_s_h((v8i16) vt1, 4); 133cabdff1aSopenharmony_ci mb_dq_coeff[160] = __msa_copy_s_h((v8i16) vt2, 4); 134cabdff1aSopenharmony_ci mb_dq_coeff[176] = __msa_copy_s_h((v8i16) vt3, 4); 135cabdff1aSopenharmony_ci mb_dq_coeff[192] = __msa_copy_s_h((v8i16) vt0, 6); 136cabdff1aSopenharmony_ci mb_dq_coeff[208] = __msa_copy_s_h((v8i16) vt1, 6); 137cabdff1aSopenharmony_ci mb_dq_coeff[224] = __msa_copy_s_h((v8i16) vt2, 6); 138cabdff1aSopenharmony_ci mb_dq_coeff[240] = __msa_copy_s_h((v8i16) vt3, 6); 139cabdff1aSopenharmony_ci 140cabdff1aSopenharmony_ci memset(input, 0, 4 * 4 * sizeof(int16_t)); 141cabdff1aSopenharmony_ci} 142cabdff1aSopenharmony_ci 143cabdff1aSopenharmony_civoid ff_vp8_idct_dc_add4y_msa(uint8_t *dst, int16_t block[4][16], 144cabdff1aSopenharmony_ci ptrdiff_t stride) 145cabdff1aSopenharmony_ci{ 146cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst, &block[0][0], stride); 147cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst + 4, &block[1][0], stride); 148cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst + 8, &block[2][0], stride); 149cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst + 12, &block[3][0], stride); 150cabdff1aSopenharmony_ci} 151cabdff1aSopenharmony_ci 152cabdff1aSopenharmony_civoid ff_vp8_idct_dc_add4uv_msa(uint8_t *dst, int16_t block[4][16], 153cabdff1aSopenharmony_ci ptrdiff_t stride) 154cabdff1aSopenharmony_ci{ 155cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst, &block[0][0], stride); 156cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst + 4, &block[1][0], stride); 157cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst + stride * 4, &block[2][0], stride); 158cabdff1aSopenharmony_ci ff_vp8_idct_dc_add_msa(dst + stride * 4 + 4, &block[3][0], stride); 159cabdff1aSopenharmony_ci} 160