1 /* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2009 Xiph.Org Foundation
3 Written by Jean-Marc Valin */
4 /**
5 @file pitch.h
6 @brief Pitch analysis
7 */
8
9 /*
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
13
14 - Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16
17 - Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef PITCH_MIPSR1_H
35 #define PITCH_MIPSR1_H
36
37 #define OVERRIDE_DUAL_INNER_PROD
dual_inner_prod(const opus_val16 * x,const opus_val16 * y01,const opus_val16 * y02,int N,opus_val32 * xy1,opus_val32 * xy2,int arch)38 static inline void dual_inner_prod(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
39 int N, opus_val32 *xy1, opus_val32 *xy2, int arch)
40 {
41 int j;
42 opus_val32 xy01=0;
43 opus_val32 xy02=0;
44
45 (void)arch;
46
47 asm volatile("MULT $ac1, $0, $0");
48 asm volatile("MULT $ac2, $0, $0");
49 /* Compute the norm of X+Y and X-Y as |X|^2 + |Y|^2 +/- sum(xy) */
50 for (j=0;j<N;j++)
51 {
52 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)x[j]), "r" ((int)y01[j]));
53 asm volatile("MADD $ac2, %0, %1" : : "r" ((int)x[j]), "r" ((int)y02[j]));
54 ++j;
55 asm volatile("MADD $ac1, %0, %1" : : "r" ((int)x[j]), "r" ((int)y01[j]));
56 asm volatile("MADD $ac2, %0, %1" : : "r" ((int)x[j]), "r" ((int)y02[j]));
57 }
58 asm volatile ("mflo %0, $ac1": "=r"(xy01));
59 asm volatile ("mflo %0, $ac2": "=r"(xy02));
60 *xy1 = xy01;
61 *xy2 = xy02;
62 }
63
xcorr_kernel_mips(const opus_val16 * x,const opus_val16 * y,opus_val32 sum[4],int len)64 static inline void xcorr_kernel_mips(const opus_val16 * x,
65 const opus_val16 * y, opus_val32 sum[4], int len)
66 {
67 int j;
68 opus_val16 y_0, y_1, y_2, y_3;
69
70 opus_int64 sum_0, sum_1, sum_2, sum_3;
71 sum_0 = (opus_int64)sum[0];
72 sum_1 = (opus_int64)sum[1];
73 sum_2 = (opus_int64)sum[2];
74 sum_3 = (opus_int64)sum[3];
75
76 y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
77 y_0=*y++;
78 y_1=*y++;
79 y_2=*y++;
80 for (j=0;j<len-3;j+=4)
81 {
82 opus_val16 tmp;
83 tmp = *x++;
84 y_3=*y++;
85
86 sum_0 = __builtin_mips_madd( sum_0, tmp, y_0);
87 sum_1 = __builtin_mips_madd( sum_1, tmp, y_1);
88 sum_2 = __builtin_mips_madd( sum_2, tmp, y_2);
89 sum_3 = __builtin_mips_madd( sum_3, tmp, y_3);
90
91 tmp=*x++;
92 y_0=*y++;
93
94 sum_0 = __builtin_mips_madd( sum_0, tmp, y_1 );
95 sum_1 = __builtin_mips_madd( sum_1, tmp, y_2 );
96 sum_2 = __builtin_mips_madd( sum_2, tmp, y_3);
97 sum_3 = __builtin_mips_madd( sum_3, tmp, y_0);
98
99 tmp=*x++;
100 y_1=*y++;
101
102 sum_0 = __builtin_mips_madd( sum_0, tmp, y_2 );
103 sum_1 = __builtin_mips_madd( sum_1, tmp, y_3 );
104 sum_2 = __builtin_mips_madd( sum_2, tmp, y_0);
105 sum_3 = __builtin_mips_madd( sum_3, tmp, y_1);
106
107
108 tmp=*x++;
109 y_2=*y++;
110
111 sum_0 = __builtin_mips_madd( sum_0, tmp, y_3 );
112 sum_1 = __builtin_mips_madd( sum_1, tmp, y_0 );
113 sum_2 = __builtin_mips_madd( sum_2, tmp, y_1);
114 sum_3 = __builtin_mips_madd( sum_3, tmp, y_2);
115
116 }
117 if (j++<len)
118 {
119 opus_val16 tmp = *x++;
120 y_3=*y++;
121
122 sum_0 = __builtin_mips_madd( sum_0, tmp, y_0 );
123 sum_1 = __builtin_mips_madd( sum_1, tmp, y_1 );
124 sum_2 = __builtin_mips_madd( sum_2, tmp, y_2);
125 sum_3 = __builtin_mips_madd( sum_3, tmp, y_3);
126 }
127
128 if (j++<len)
129 {
130 opus_val16 tmp=*x++;
131 y_0=*y++;
132
133 sum_0 = __builtin_mips_madd( sum_0, tmp, y_1 );
134 sum_1 = __builtin_mips_madd( sum_1, tmp, y_2 );
135 sum_2 = __builtin_mips_madd( sum_2, tmp, y_3);
136 sum_3 = __builtin_mips_madd( sum_3, tmp, y_0);
137 }
138
139 if (j<len)
140 {
141 opus_val16 tmp=*x++;
142 y_1=*y++;
143
144 sum_0 = __builtin_mips_madd( sum_0, tmp, y_2 );
145 sum_1 = __builtin_mips_madd( sum_1, tmp, y_3 );
146 sum_2 = __builtin_mips_madd( sum_2, tmp, y_0);
147 sum_3 = __builtin_mips_madd( sum_3, tmp, y_1);
148
149 }
150
151 sum[0] = (opus_val32)sum_0;
152 sum[1] = (opus_val32)sum_1;
153 sum[2] = (opus_val32)sum_2;
154 sum[3] = (opus_val32)sum_3;
155 }
156
157 #define OVERRIDE_XCORR_KERNEL
158 #define xcorr_kernel(x, y, sum, len, arch) \
159 ((void)(arch), xcorr_kernel_mips(x, y, sum, len))
160
161 #endif /* PITCH_MIPSR1_H */
162