FFmpeg
acelp_filters_mips.c
Go to the documentation of this file.
1  /*
2  * Copyright (c) 2012
3  * MIPS Technologies, Inc., California.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * Author: Nedeljko Babic (nbabic@mips.com)
30  *
31  * various filters for ACELP-based codecs optimized for MIPS
32  *
33  * This file is part of FFmpeg.
34  *
35  * FFmpeg is free software; you can redistribute it and/or
36  * modify it under the terms of the GNU Lesser General Public
37  * License as published by the Free Software Foundation; either
38  * version 2.1 of the License, or (at your option) any later version.
39  *
40  * FFmpeg is distributed in the hope that it will be useful,
41  * but WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43  * Lesser General Public License for more details.
44  *
45  * You should have received a copy of the GNU Lesser General Public
46  * License along with FFmpeg; if not, write to the Free Software
47  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
48  */
49 
50 /**
51  * @file
52  * Reference: libavcodec/acelp_filters.c
53  */
54 #include "config.h"
55 #include "libavutil/attributes.h"
57 #include "libavutil/mips/asmdefs.h"
58 
59 #if HAVE_INLINE_ASM
60 #if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
61 static void ff_acelp_interpolatef_mips(float *out, const float *in,
62  const float *filter_coeffs, int precision,
63  int frac_pos, int filter_length, int length)
64 {
65  int n, i;
66  int prec = precision * 4;
67  int fc_offset = precision - frac_pos;
68  float in_val_p, in_val_m, fc_val_p, fc_val_m;
69 
70  for (n = 0; n < length; n++) {
71  /**
72  * four pointers are defined in order to minimize number of
73  * computations done in inner loop
74  */
75  const float *p_in_p = &in[n];
76  const float *p_in_m = &in[n-1];
77  const float *p_filter_coeffs_p = &filter_coeffs[frac_pos];
78  const float *p_filter_coeffs_m = filter_coeffs + fc_offset;
79  float v = 0;
80 
81  for (i = 0; i < filter_length;i++) {
82  __asm__ volatile (
83  "lwc1 %[in_val_p], 0(%[p_in_p]) \n\t"
84  "lwc1 %[fc_val_p], 0(%[p_filter_coeffs_p]) \n\t"
85  "lwc1 %[in_val_m], 0(%[p_in_m]) \n\t"
86  "lwc1 %[fc_val_m], 0(%[p_filter_coeffs_m]) \n\t"
87  PTR_ADDIU "%[p_in_p], %[p_in_p], 4 \n\t"
88  "madd.s %[v],%[v], %[in_val_p],%[fc_val_p] \n\t"
89  PTR_ADDIU "%[p_in_m], %[p_in_m], -4 \n\t"
90  PTR_ADDU "%[p_filter_coeffs_p],%[p_filter_coeffs_p], %[prec] \n\t"
91  PTR_ADDU "%[p_filter_coeffs_m],%[p_filter_coeffs_m], %[prec] \n\t"
92  "madd.s %[v],%[v],%[in_val_m], %[fc_val_m] \n\t"
93 
94  : [v] "+&f" (v),[p_in_p] "+r" (p_in_p), [p_in_m] "+r" (p_in_m),
95  [p_filter_coeffs_p] "+r" (p_filter_coeffs_p),
96  [in_val_p] "=&f" (in_val_p), [in_val_m] "=&f" (in_val_m),
97  [fc_val_p] "=&f" (fc_val_p), [fc_val_m] "=&f" (fc_val_m),
98  [p_filter_coeffs_m] "+r" (p_filter_coeffs_m)
99  : [prec] "r" (prec)
100  : "memory"
101  );
102  }
103  out[n] = v;
104  }
105 }
106 
107 static void ff_acelp_apply_order_2_transfer_function_mips(float *out, const float *in,
108  const float zero_coeffs[2],
109  const float pole_coeffs[2],
110  float gain, float mem[2], int n)
111 {
112  /**
113  * loop is unrolled eight times
114  */
115 
116  __asm__ volatile (
117  "lwc1 $f0, 0(%[mem]) \n\t"
118  "blez %[n], ff_acelp_apply_order_2_transfer_function_end%= \n\t"
119  "lwc1 $f1, 4(%[mem]) \n\t"
120  "lwc1 $f2, 0(%[pole_coeffs]) \n\t"
121  "lwc1 $f3, 4(%[pole_coeffs]) \n\t"
122  "lwc1 $f4, 0(%[zero_coeffs]) \n\t"
123  "lwc1 $f5, 4(%[zero_coeffs]) \n\t"
124 
125  "ff_acelp_apply_order_2_transfer_function_madd%=: \n\t"
126 
127  "lwc1 $f6, 0(%[in]) \n\t"
128  "mul.s $f9, $f3, $f1 \n\t"
129  "mul.s $f7, $f2, $f0 \n\t"
130  "msub.s $f7, $f7, %[gain], $f6 \n\t"
131  "sub.s $f7, $f7, $f9 \n\t"
132  "madd.s $f8, $f7, $f4, $f0 \n\t"
133  "madd.s $f8, $f8, $f5, $f1 \n\t"
134  "lwc1 $f11, 4(%[in]) \n\t"
135  "mul.s $f12, $f3, $f0 \n\t"
136  "mul.s $f13, $f2, $f7 \n\t"
137  "msub.s $f13, $f13, %[gain], $f11 \n\t"
138  "sub.s $f13, $f13, $f12 \n\t"
139  "madd.s $f14, $f13, $f4, $f7 \n\t"
140  "madd.s $f14, $f14, $f5, $f0 \n\t"
141  "swc1 $f8, 0(%[out]) \n\t"
142  "lwc1 $f6, 8(%[in]) \n\t"
143  "mul.s $f9, $f3, $f7 \n\t"
144  "mul.s $f15, $f2, $f13 \n\t"
145  "msub.s $f15, $f15, %[gain], $f6 \n\t"
146  "sub.s $f15, $f15, $f9 \n\t"
147  "madd.s $f8, $f15, $f4, $f13 \n\t"
148  "madd.s $f8, $f8, $f5, $f7 \n\t"
149  "swc1 $f14, 4(%[out]) \n\t"
150  "lwc1 $f11, 12(%[in]) \n\t"
151  "mul.s $f12, $f3, $f13 \n\t"
152  "mul.s $f16, $f2, $f15 \n\t"
153  "msub.s $f16, $f16, %[gain], $f11 \n\t"
154  "sub.s $f16, $f16, $f12 \n\t"
155  "madd.s $f14, $f16, $f4, $f15 \n\t"
156  "madd.s $f14, $f14, $f5, $f13 \n\t"
157  "swc1 $f8, 8(%[out]) \n\t"
158  "lwc1 $f6, 16(%[in]) \n\t"
159  "mul.s $f9, $f3, $f15 \n\t"
160  "mul.s $f7, $f2, $f16 \n\t"
161  "msub.s $f7, $f7, %[gain], $f6 \n\t"
162  "sub.s $f7, $f7, $f9 \n\t"
163  "madd.s $f8, $f7, $f4, $f16 \n\t"
164  "madd.s $f8, $f8, $f5, $f15 \n\t"
165  "swc1 $f14, 12(%[out]) \n\t"
166  "lwc1 $f11, 20(%[in]) \n\t"
167  "mul.s $f12, $f3, $f16 \n\t"
168  "mul.s $f13, $f2, $f7 \n\t"
169  "msub.s $f13, $f13, %[gain], $f11 \n\t"
170  "sub.s $f13, $f13, $f12 \n\t"
171  "madd.s $f14, $f13, $f4, $f7 \n\t"
172  "madd.s $f14, $f14, $f5, $f16 \n\t"
173  "swc1 $f8, 16(%[out]) \n\t"
174  "lwc1 $f6, 24(%[in]) \n\t"
175  "mul.s $f9, $f3, $f7 \n\t"
176  "mul.s $f15, $f2, $f13 \n\t"
177  "msub.s $f15, $f15, %[gain], $f6 \n\t"
178  "sub.s $f1, $f15, $f9 \n\t"
179  "madd.s $f8, $f1, $f4, $f13 \n\t"
180  "madd.s $f8, $f8, $f5, $f7 \n\t"
181  "swc1 $f14, 20(%[out]) \n\t"
182  "lwc1 $f11, 28(%[in]) \n\t"
183  "mul.s $f12, $f3, $f13 \n\t"
184  "mul.s $f16, $f2, $f1 \n\t"
185  "msub.s $f16, $f16, %[gain], $f11 \n\t"
186  "sub.s $f0, $f16, $f12 \n\t"
187  "madd.s $f14, $f0, $f4, $f1 \n\t"
188  "madd.s $f14, $f14, $f5, $f13 \n\t"
189  "swc1 $f8, 24(%[out]) \n\t"
190  PTR_ADDIU "%[out], 32 \n\t"
191  PTR_ADDIU "%[in], 32 \n\t"
192  "addiu %[n], -8 \n\t"
193  "swc1 $f14, -4(%[out]) \n\t"
194  "bnez %[n], ff_acelp_apply_order_2_transfer_function_madd%= \n\t"
195  "swc1 $f1, 4(%[mem]) \n\t"
196  "swc1 $f0, 0(%[mem]) \n\t"
197 
198  "ff_acelp_apply_order_2_transfer_function_end%=: \n\t"
199 
200  : [out] "+r" (out),
201  [in] "+r" (in), [gain] "+f" (gain),
202  [n] "+r" (n), [mem] "+r" (mem)
203  : [zero_coeffs] "r" (zero_coeffs),
204  [pole_coeffs] "r" (pole_coeffs)
205  : "$f0", "$f1", "$f2", "$f3", "$f4", "$f5",
206  "$f6", "$f7", "$f8", "$f9", "$f10", "$f11",
207  "$f12", "$f13", "$f14", "$f15", "$f16", "memory"
208  );
209 }
210 #endif /* !HAVE_MIPS32R6 && !HAVE_MIPS64R6 */
211 #endif /* HAVE_INLINE_ASM */
212 
214 {
215 #if HAVE_INLINE_ASM
216 #if !HAVE_MIPS32R6 && !HAVE_MIPS64R6
217  c->acelp_interpolatef = ff_acelp_interpolatef_mips;
218  c->acelp_apply_order_2_transfer_function = ff_acelp_apply_order_2_transfer_function_mips;
219 #endif
220 #endif
221 }
out
FILE * out
Definition: movenc.c:54
asmdefs.h
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
ACELPFContext
Definition: acelp_filters.h:28
attributes.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
acelp_filters.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_ADDU
#define PTR_ADDU
Definition: asmdefs.h:49
PTR_ADDIU
#define PTR_ADDIU
Definition: asmdefs.h:50
ff_acelp_filter_init_mips
void ff_acelp_filter_init_mips(ACELPFContext *c)
Definition: acelp_filters_mips.c:213