Chris@69
|
1 /* Copyright (c) 2007-2008 CSIRO
|
Chris@69
|
2 Copyright (c) 2007-2009 Xiph.Org Foundation
|
Chris@69
|
3 Written by Jean-Marc Valin */
|
Chris@69
|
4 /*
|
Chris@69
|
5 Redistribution and use in source and binary forms, with or without
|
Chris@69
|
6 modification, are permitted provided that the following conditions
|
Chris@69
|
7 are met:
|
Chris@69
|
8
|
Chris@69
|
9 - Redistributions of source code must retain the above copyright
|
Chris@69
|
10 notice, this list of conditions and the following disclaimer.
|
Chris@69
|
11
|
Chris@69
|
12 - Redistributions in binary form must reproduce the above copyright
|
Chris@69
|
13 notice, this list of conditions and the following disclaimer in the
|
Chris@69
|
14 documentation and/or other materials provided with the distribution.
|
Chris@69
|
15
|
Chris@69
|
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Chris@69
|
17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Chris@69
|
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Chris@69
|
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
Chris@69
|
20 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
Chris@69
|
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
Chris@69
|
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
Chris@69
|
23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
Chris@69
|
24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
Chris@69
|
25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
Chris@69
|
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Chris@69
|
27 */
|
Chris@69
|
28
|
Chris@69
|
29 #ifndef __VQ_MIPSR1_H__
|
Chris@69
|
30 #define __VQ_MIPSR1_H__
|
Chris@69
|
31
|
Chris@69
|
32 #ifdef HAVE_CONFIG_H
|
Chris@69
|
33 #include "config.h"
|
Chris@69
|
34 #endif
|
Chris@69
|
35
|
Chris@69
|
36 #include "mathops.h"
|
Chris@69
|
37 #include "arch.h"
|
Chris@69
|
38
|
Chris@69
|
39 static void renormalise_vector_mips(celt_norm *X, int N, opus_val16 gain, int arch);
|
Chris@69
|
40
|
Chris@69
|
41 #define OVERRIDE_vq_exp_rotation1
|
Chris@69
|
42 static void exp_rotation1(celt_norm *X, int len, int stride, opus_val16 c, opus_val16 s)
|
Chris@69
|
43 {
|
Chris@69
|
44 int i;
|
Chris@69
|
45 opus_val16 ms;
|
Chris@69
|
46 celt_norm *Xptr;
|
Chris@69
|
47 Xptr = X;
|
Chris@69
|
48 ms = NEG16(s);
|
Chris@69
|
49 for (i=0;i<len-stride;i++)
|
Chris@69
|
50 {
|
Chris@69
|
51 celt_norm x1, x2;
|
Chris@69
|
52 x1 = Xptr[0];
|
Chris@69
|
53 x2 = Xptr[stride];
|
Chris@69
|
54 Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15));
|
Chris@69
|
55 *Xptr++ = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15));
|
Chris@69
|
56 }
|
Chris@69
|
57 Xptr = &X[len-2*stride-1];
|
Chris@69
|
58 for (i=len-2*stride-1;i>=0;i--)
|
Chris@69
|
59 {
|
Chris@69
|
60 celt_norm x1, x2;
|
Chris@69
|
61 x1 = Xptr[0];
|
Chris@69
|
62 x2 = Xptr[stride];
|
Chris@69
|
63 Xptr[stride] = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x2), s, x1), 15));
|
Chris@69
|
64 *Xptr-- = EXTRACT16(PSHR32(MAC16_16(MULT16_16(c, x1), ms, x2), 15));
|
Chris@69
|
65 }
|
Chris@69
|
66 }
|
Chris@69
|
67
|
Chris@69
|
68 #define OVERRIDE_renormalise_vector
|
Chris@69
|
69
|
Chris@69
|
70 #define renormalise_vector(X, N, gain, arch) \
|
Chris@69
|
71 (renormalise_vector_mips(X, N, gain, arch))
|
Chris@69
|
72
|
Chris@69
|
73 void renormalise_vector_mips(celt_norm *X, int N, opus_val16 gain, int arch)
|
Chris@69
|
74 {
|
Chris@69
|
75 int i;
|
Chris@69
|
76 #ifdef FIXED_POINT
|
Chris@69
|
77 int k;
|
Chris@69
|
78 #endif
|
Chris@69
|
79 opus_val32 E = EPSILON;
|
Chris@69
|
80 opus_val16 g;
|
Chris@69
|
81 opus_val32 t;
|
Chris@69
|
82 celt_norm *xptr = X;
|
Chris@69
|
83 int X0, X1;
|
Chris@69
|
84
|
Chris@69
|
85 (void)arch;
|
Chris@69
|
86
|
Chris@69
|
87 asm volatile("mult $ac1, $0, $0");
|
Chris@69
|
88 asm volatile("MTLO %0, $ac1" : :"r" (E));
|
Chris@69
|
89 /*if(N %4)
|
Chris@69
|
90 printf("error");*/
|
Chris@69
|
91 for (i=0;i<N-2;i+=2)
|
Chris@69
|
92 {
|
Chris@69
|
93 X0 = (int)*xptr++;
|
Chris@69
|
94 asm volatile("MADD $ac1, %0, %1" : : "r" (X0), "r" (X0));
|
Chris@69
|
95
|
Chris@69
|
96 X1 = (int)*xptr++;
|
Chris@69
|
97 asm volatile("MADD $ac1, %0, %1" : : "r" (X1), "r" (X1));
|
Chris@69
|
98 }
|
Chris@69
|
99
|
Chris@69
|
100 for (;i<N;i++)
|
Chris@69
|
101 {
|
Chris@69
|
102 X0 = (int)*xptr++;
|
Chris@69
|
103 asm volatile("MADD $ac1, %0, %1" : : "r" (X0), "r" (X0));
|
Chris@69
|
104 }
|
Chris@69
|
105
|
Chris@69
|
106 asm volatile("MFLO %0, $ac1" : "=r" (E));
|
Chris@69
|
107 #ifdef FIXED_POINT
|
Chris@69
|
108 k = celt_ilog2(E)>>1;
|
Chris@69
|
109 #endif
|
Chris@69
|
110 t = VSHR32(E, 2*(k-7));
|
Chris@69
|
111 g = MULT16_16_P15(celt_rsqrt_norm(t),gain);
|
Chris@69
|
112
|
Chris@69
|
113 xptr = X;
|
Chris@69
|
114 for (i=0;i<N;i++)
|
Chris@69
|
115 {
|
Chris@69
|
116 *xptr = EXTRACT16(PSHR32(MULT16_16(g, *xptr), k+1));
|
Chris@69
|
117 xptr++;
|
Chris@69
|
118 }
|
Chris@69
|
119 /*return celt_sqrt(E);*/
|
Chris@69
|
120 }
|
Chris@69
|
121
|
Chris@69
|
122 #endif /* __VQ_MIPSR1_H__ */
|