1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * Format Conversion Utils for MIPS 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * Copyright (c) 2012 5cabdff1aSopenharmony_ci * MIPS Technologies, Inc., California. 6cabdff1aSopenharmony_ci * 7cabdff1aSopenharmony_ci * Redistribution and use in source and binary forms, with or without 8cabdff1aSopenharmony_ci * modification, are permitted provided that the following conditions 9cabdff1aSopenharmony_ci * are met: 10cabdff1aSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 11cabdff1aSopenharmony_ci * notice, this list of conditions and the following disclaimer. 12cabdff1aSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 13cabdff1aSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 14cabdff1aSopenharmony_ci * documentation and/or other materials provided with the distribution. 15cabdff1aSopenharmony_ci * 3. Neither the name of the MIPS Technologies, Inc., nor the names of is 16cabdff1aSopenharmony_ci * contributors may be used to endorse or promote products derived from 17cabdff1aSopenharmony_ci * this software without specific prior written permission. 18cabdff1aSopenharmony_ci * 19cabdff1aSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND 20cabdff1aSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21cabdff1aSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22cabdff1aSopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE 23cabdff1aSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24cabdff1aSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25cabdff1aSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26cabdff1aSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27cabdff1aSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28cabdff1aSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29cabdff1aSopenharmony_ci * SUCH DAMAGE. 30cabdff1aSopenharmony_ci * 31cabdff1aSopenharmony_ci * Author: Zoran Lukic (zoranl@mips.com) 32cabdff1aSopenharmony_ci * Author: Nedeljko Babic (nbabic@mips.com) 33cabdff1aSopenharmony_ci * 34cabdff1aSopenharmony_ci * This file is part of FFmpeg. 35cabdff1aSopenharmony_ci * 36cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 37cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 38cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 39cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 40cabdff1aSopenharmony_ci * 41cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 42cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 43cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 44cabdff1aSopenharmony_ci * Lesser General Public License for more details. 45cabdff1aSopenharmony_ci * 46cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 47cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 48cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 49cabdff1aSopenharmony_ci */ 50cabdff1aSopenharmony_ci#include "config.h" 51cabdff1aSopenharmony_ci#include "libavutil/attributes.h" 52cabdff1aSopenharmony_ci#include "libavcodec/avcodec.h" 53cabdff1aSopenharmony_ci#include "libavcodec/fmtconvert.h" 54cabdff1aSopenharmony_ci#include "libavutil/mips/asmdefs.h" 55cabdff1aSopenharmony_ci 56cabdff1aSopenharmony_ci#if HAVE_INLINE_ASM 57cabdff1aSopenharmony_cistatic void int32_to_float_fmul_scalar_mips(float *dst, const int *src, 58cabdff1aSopenharmony_ci float mul, int len) 59cabdff1aSopenharmony_ci{ 60cabdff1aSopenharmony_ci /* 61cabdff1aSopenharmony_ci * variables used in inline assembler 62cabdff1aSopenharmony_ci */ 63cabdff1aSopenharmony_ci float temp1, temp3, temp5, temp7, temp9, temp11, temp13, temp15; 64cabdff1aSopenharmony_ci 65cabdff1aSopenharmony_ci int rpom1, rpom2, rpom11, rpom21, rpom12, rpom22, rpom13, rpom23; 66cabdff1aSopenharmony_ci const int *src_end = src + len; 67cabdff1aSopenharmony_ci /* 68cabdff1aSopenharmony_ci * loop is 8 times unrolled in assembler in order to achieve better performance 69cabdff1aSopenharmony_ci */ 70cabdff1aSopenharmony_ci __asm__ volatile ( 71cabdff1aSopenharmony_ci "i32tf_lp%=: \n\t" 72cabdff1aSopenharmony_ci "lw %[rpom11], 0(%[src]) \n\t" 73cabdff1aSopenharmony_ci "lw %[rpom21], 4(%[src]) \n\t" 74cabdff1aSopenharmony_ci "lw %[rpom1], 8(%[src]) \n\t" 75cabdff1aSopenharmony_ci "lw %[rpom2], 12(%[src]) \n\t" 76cabdff1aSopenharmony_ci "mtc1 %[rpom11], %[temp1] \n\t" 77cabdff1aSopenharmony_ci "mtc1 %[rpom21], %[temp3] \n\t" 78cabdff1aSopenharmony_ci "mtc1 %[rpom1], %[temp5] \n\t" 79cabdff1aSopenharmony_ci "mtc1 %[rpom2], %[temp7] \n\t" 80cabdff1aSopenharmony_ci 81cabdff1aSopenharmony_ci "lw %[rpom13], 16(%[src]) \n\t" 82cabdff1aSopenharmony_ci "lw %[rpom23], 20(%[src]) \n\t" 83cabdff1aSopenharmony_ci "lw %[rpom12], 24(%[src]) \n\t" 84cabdff1aSopenharmony_ci "lw %[rpom22], 28(%[src]) \n\t" 85cabdff1aSopenharmony_ci "mtc1 %[rpom13], %[temp9] \n\t" 86cabdff1aSopenharmony_ci "mtc1 %[rpom23], %[temp11] \n\t" 87cabdff1aSopenharmony_ci "mtc1 %[rpom12], %[temp13] \n\t" 88cabdff1aSopenharmony_ci "mtc1 %[rpom22], %[temp15] \n\t" 89cabdff1aSopenharmony_ci 90cabdff1aSopenharmony_ci PTR_ADDIU "%[src], 32 \n\t" 91cabdff1aSopenharmony_ci "cvt.s.w %[temp1], %[temp1] \n\t" 92cabdff1aSopenharmony_ci "cvt.s.w %[temp3], %[temp3] \n\t" 93cabdff1aSopenharmony_ci "cvt.s.w %[temp5], %[temp5] \n\t" 94cabdff1aSopenharmony_ci "cvt.s.w %[temp7], %[temp7] \n\t" 95cabdff1aSopenharmony_ci 96cabdff1aSopenharmony_ci "cvt.s.w %[temp9], %[temp9] \n\t" 97cabdff1aSopenharmony_ci "cvt.s.w %[temp11], %[temp11] \n\t" 98cabdff1aSopenharmony_ci "cvt.s.w %[temp13], %[temp13] \n\t" 99cabdff1aSopenharmony_ci "cvt.s.w %[temp15], %[temp15] \n\t" 100cabdff1aSopenharmony_ci 101cabdff1aSopenharmony_ci "mul.s %[temp1], %[temp1], %[mul] \n\t" 102cabdff1aSopenharmony_ci "mul.s %[temp3], %[temp3], %[mul] \n\t" 103cabdff1aSopenharmony_ci "mul.s %[temp5], %[temp5], %[mul] \n\t" 104cabdff1aSopenharmony_ci "mul.s %[temp7], %[temp7], %[mul] \n\t" 105cabdff1aSopenharmony_ci 106cabdff1aSopenharmony_ci "mul.s %[temp9], %[temp9], %[mul] \n\t" 107cabdff1aSopenharmony_ci "mul.s %[temp11], %[temp11], %[mul] \n\t" 108cabdff1aSopenharmony_ci "mul.s %[temp13], %[temp13], %[mul] \n\t" 109cabdff1aSopenharmony_ci "mul.s %[temp15], %[temp15], %[mul] \n\t" 110cabdff1aSopenharmony_ci 111cabdff1aSopenharmony_ci "swc1 %[temp1], 0(%[dst]) \n\t" /*dst[i] = src[i] * mul; */ 112cabdff1aSopenharmony_ci "swc1 %[temp3], 4(%[dst]) \n\t" /*dst[i+1] = src[i+1] * mul;*/ 113cabdff1aSopenharmony_ci "swc1 %[temp5], 8(%[dst]) \n\t" /*dst[i+2] = src[i+2] * mul;*/ 114cabdff1aSopenharmony_ci "swc1 %[temp7], 12(%[dst]) \n\t" /*dst[i+3] = src[i+3] * mul;*/ 115cabdff1aSopenharmony_ci 116cabdff1aSopenharmony_ci "swc1 %[temp9], 16(%[dst]) \n\t" /*dst[i+4] = src[i+4] * mul;*/ 117cabdff1aSopenharmony_ci "swc1 %[temp11], 20(%[dst]) \n\t" /*dst[i+5] = src[i+5] * mul;*/ 118cabdff1aSopenharmony_ci "swc1 %[temp13], 24(%[dst]) \n\t" /*dst[i+6] = src[i+6] * mul;*/ 119cabdff1aSopenharmony_ci "swc1 %[temp15], 28(%[dst]) \n\t" /*dst[i+7] = src[i+7] * mul;*/ 120cabdff1aSopenharmony_ci PTR_ADDIU "%[dst], 32 \n\t" 121cabdff1aSopenharmony_ci "bne %[src], %[src_end], i32tf_lp%= \n\t" 122cabdff1aSopenharmony_ci : [temp1]"=&f"(temp1), [temp11]"=&f"(temp11), 123cabdff1aSopenharmony_ci [temp13]"=&f"(temp13), [temp15]"=&f"(temp15), 124cabdff1aSopenharmony_ci [temp3]"=&f"(temp3), [temp5]"=&f"(temp5), 125cabdff1aSopenharmony_ci [temp7]"=&f"(temp7), [temp9]"=&f"(temp9), 126cabdff1aSopenharmony_ci [rpom1]"=&r"(rpom1), [rpom2]"=&r"(rpom2), 127cabdff1aSopenharmony_ci [rpom11]"=&r"(rpom11), [rpom21]"=&r"(rpom21), 128cabdff1aSopenharmony_ci [rpom12]"=&r"(rpom12), [rpom22]"=&r"(rpom22), 129cabdff1aSopenharmony_ci [rpom13]"=&r"(rpom13), [rpom23]"=&r"(rpom23), 130cabdff1aSopenharmony_ci [dst]"+r"(dst), [src]"+r"(src) 131cabdff1aSopenharmony_ci : [mul]"f"(mul), [src_end]"r"(src_end) 132cabdff1aSopenharmony_ci : "memory" 133cabdff1aSopenharmony_ci ); 134cabdff1aSopenharmony_ci} 135cabdff1aSopenharmony_ci#endif /* HAVE_INLINE_ASM */ 136cabdff1aSopenharmony_ci 137cabdff1aSopenharmony_ciav_cold void ff_fmt_convert_init_mips(FmtConvertContext *c) 138cabdff1aSopenharmony_ci{ 139cabdff1aSopenharmony_ci#if HAVE_INLINE_ASM 140cabdff1aSopenharmony_ci c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_mips; 141cabdff1aSopenharmony_ci#endif 142cabdff1aSopenharmony_ci} 143