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