MCSDK 3.0: workaround to fix compilation issue for device specific CSL
[keystone-rtos/tcp3d-lld.git] / src / tcp3d_betaState.c
1 /** \r
2  *  \file   tcp3d_betaState.c\r
3  *\r
4  *  \brief  Beta State calculations functions from the tail bits for TCP3D pre-process.\r
5  *\r
6  *  Copyright (c) Texas Instruments Incorporated 2008\r
7  * \r
8  *  Redistribution and use in source and binary forms, with or without \r
9  *  modification, are permitted provided that the following conditions \r
10  *  are met:\r
11  *\r
12  *    Redistributions of source code must retain the above copyright \r
13  *    notice, this list of conditions and the following disclaimer.\r
14  *\r
15  *    Redistributions in binary form must reproduce the above copyright\r
16  *    notice, this list of conditions and the following disclaimer in the \r
17  *    documentation and/or other materials provided with the   \r
18  *    distribution.\r
19  *\r
20  *    Neither the name of Texas Instruments Incorporated nor the names of\r
21  *    its contributors may be used to endorse or promote products derived\r
22  *    from this software without specific prior written permission.\r
23  *\r
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
25  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
26  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
27  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
28  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
29  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
30  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
31  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
32  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
33  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
34  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
35  *\r
36 */\r
37 #include <tcp3d_drv_types.h>\r
38 \r
39 /** \r
40  *  \brief  Calculates initial beta states using the tail bits for use with the\r
41  *          TCP3D input configuration registers.\r
42  */\r
43 void Tcp3d_betaStates(\r
44                     IN  int8_t    * const RESTRICT tailBits,\r
45                     IN  int32_t   signChange,\r
46                     IN  int32_t   Kt,\r
47                     OUT int8_t    * const RESTRICT beta0Ptr,\r
48                     OUT int8_t    * const RESTRICT beta1Ptr)\r
49 {\r
50     int32_t Tmp0,Tmp1,Tmp2;\r
51     int64_t llRes, llFin;\r
52     int32_t bit10, bit32, bit54, bit76, bit98, bitba;\r
53 \r
54     int32_t scale;\r
55     int32_t beta0,beta1,beta2,beta3,beta4,beta5,beta6,beta7,betaMax;\r
56 \r
57     if(signChange)\r
58     {\r
59         scale = 0x00800080;   //+128\r
60     }\r
61     else\r
62     {\r
63         scale = 0xff80ff80;  //-128\r
64     }\r
65 \r
66     //Load 12 tail samples\r
67     Tmp0   = _mem4(&tailBits[0]);\r
68     Tmp1   = _mem4(&tailBits[4]);\r
69     Tmp2   = _mem4(&tailBits[8]);\r
70 \r
71 #ifdef _BIG_ENDIAN\r
72     Tmp0 = _rotl(_swap4(Tmp0), 16);\r
73     Tmp1 = _rotl(_swap4(Tmp1), 16);\r
74     Tmp2 = _rotl(_swap4(Tmp2), 16);\r
75 #endif\r
76 \r
77     //***************************************************\r
78     //Initial Beta States Calculation for MAP 0 and MAP1\r
79     //***************************************************\r
80     //Process 4 samples\r
81     llRes = _mpysu4ll(Tmp0, 0x01010101);\r
82     llFin = _smpy2ll(_loll(llRes), scale);\r
83     bit10 = _shr2(_spack2(_hill(llFin),_loll(llFin)), 8);\r
84     llFin = _smpy2ll(_hill(llRes), scale);\r
85     bit32 = _shr2(_spack2(_hill(llFin),_loll(llFin)), 8);\r
86 \r
87     //Process 4 samples\r
88     //llRes = _mpysu4ll(_hill(llTmp), 0x01010101);\r
89     llRes = _mpysu4ll(Tmp1, 0x01010101);\r
90     llFin = _smpy2ll(_loll(llRes), scale);\r
91     bit54 = _shr2(_spack2(_hill(llFin),_loll(llFin)), 8);\r
92     llFin = _smpy2ll(_hill(llRes), scale);\r
93     bit76 = _shr2(_spack2(_hill(llFin),_loll(llFin)), 8);\r
94 \r
95     //Process 4 samples\r
96     llRes = _mpysu4ll(Tmp2, 0x01010101);\r
97     llFin = _smpy2ll(_loll(llRes), scale);\r
98     bit98 = _shr2(_spack2(_hill(llFin),_loll(llFin)), 8);\r
99     llFin = _smpy2ll(_hill(llRes), scale);\r
100     bitba = _shr2(_spack2(_hill(llFin),_loll(llFin)), 8);\r
101 \r
102     //Compute beta state values based on the Kt (# of trellis stages)\r
103     if(Kt==3)\r
104     {\r
105         //Beta MAP0\r
106         beta0 = 0;\r
107         beta1 = _ext(bit10,16,16) + _ext(bit10,0,16); //xt0[0] + xt0[1];\r
108         beta2 = _ext(bit10,16,16) + _ext(bit32,16,16) + _ext(bit32,0,16); //xt0[0] + xt0[2] + xt0[3];\r
109         beta3 = _ext(bit10,0,16) + _ext(bit32,16,16) + _ext(bit32,0,16);  //xt0[1] + xt0[2] + xt0[3];\r
110         beta4 = _ext(bit10,0,16) + _ext(bit32,16,16) + _ext(bit54,16,16) + _ext(bit54,0,16); //xt0[1] + xt0[2]+ xt0[4] + xt0[5];\r
111         beta5 = _ext(bit10,16,16) + _ext(bit32,16,16) + _ext(bit54,16,16) + _ext(bit54,0,16);//xt0[0]+ xt0[2]+ xt0[4] + xt0[5];\r
112         beta6 = _ext(bit10,16,16) + _ext(bit10,0,16) + _ext(bit32,0,16) + _ext(bit54,16,16) + _ext(bit54,0,16); //xt0[0] + xt0[1]+ xt0[3] + xt0[4] + xt0[5];\r
113         beta7 = _ext(bit32,0,16) + _ext(bit54,16,16) + _ext(bit54,0,16);// xt0[3] + xt0[4] + xt0[5];\r
114 \r
115         betaMax = _max2(beta0,beta1);\r
116         betaMax = _max2(betaMax,beta2);\r
117         betaMax = _max2(betaMax,beta3);\r
118         betaMax = _max2(betaMax,beta4);\r
119         betaMax = _max2(betaMax,beta5);\r
120         betaMax = _max2(betaMax,beta6);\r
121         betaMax = _max2(betaMax,beta7);\r
122         betaMax = _ext(betaMax,16,16);\r
123         betaMax = 127 - betaMax;\r
124 \r
125         beta0 = beta0 + betaMax;\r
126         beta1 = beta1 + betaMax;\r
127         beta2 = beta2 + betaMax;\r
128         beta3 = beta3 + betaMax;\r
129         beta4 = beta4 + betaMax;\r
130         beta5 = beta5 + betaMax;\r
131         beta6 = beta6 + betaMax;\r
132         beta7 = beta7 + betaMax;\r
133 \r
134         beta0 = _max2(0x8000ff81, beta0);\r
135         beta1 = _max2(0x8000ff81, beta1);\r
136         beta2 = _max2(0x8000ff81, beta2);\r
137         beta3 = _max2(0x8000ff81, beta3);\r
138         beta4 = _max2(0x8000ff81, beta4);\r
139         beta5 = _max2(0x8000ff81, beta5);\r
140         beta6 = _max2(0x8000ff81, beta6);\r
141         beta7 = _max2(0x8000ff81, beta7);\r
142 \r
143 #ifdef _BIG_ENDIAN\r
144         _mem4(&beta0Ptr[0]) = _packl4(_pack2(beta0,beta1),_pack2(beta2,beta3));\r
145         _mem4(&beta0Ptr[4]) = _packl4(_pack2(beta4,beta5),_pack2(beta6,beta7));\r
146 #else\r
147         _mem4(&beta0Ptr[0]) = _packl4(_pack2(beta3,beta2),_pack2(beta1,beta0));\r
148         _mem4(&beta0Ptr[4]) = _packl4(_pack2(beta7,beta6),_pack2(beta5,beta4));\r
149 #endif\r
150 \r
151         //Beta MAP1\r
152         beta0 = 0;\r
153         beta1 = _ext(bit76,16,16) + _ext(bit76,0,16); //xt1[0] + xt1[1];\r
154         beta2 = _ext(bit76,16,16) + _ext(bit98,16,16) + _ext(bit98,0,16); //xt1[0] + xt1[2] + xt1[3];\r
155         beta3 = _ext(bit76,0,16) + _ext(bit98,16,16) + _ext(bit98,0,16);  //xt1[1] + xt1[2] + xt1[3];\r
156         beta4 = _ext(bit76,0,16) + _ext(bit98,16,16) + _ext(bitba,16,16) + _ext(bitba,0,16); //xt1[1] + xt1[2]+ xt1[4] + xt1[5];\r
157         beta5 = _ext(bit76,16,16) + _ext(bit98,16,16) + _ext(bitba,16,16) + _ext(bitba,0,16);//xt1[0]+ xt1[2]+ xt1[4] + xt1[5];\r
158         beta6 = _ext(bit76,16,16) + _ext(bit76,0,16) + _ext(bit98,0,16) + _ext(bitba,16,16) + _ext(bitba,0,16); //xt1[0] + xt1[1]+ xt1[3] + xt1[4] + xt1[5];\r
159         beta7 = _ext(bit98,0,16) + _ext(bitba,16,16) + _ext(bitba,0,16);// xt1[3] + xt1[4] + xt1[5];\r
160 \r
161         betaMax = _max2(beta0,beta1);\r
162         betaMax = _max2(betaMax,beta2);\r
163         betaMax = _max2(betaMax,beta3);\r
164         betaMax = _max2(betaMax,beta4);\r
165         betaMax = _max2(betaMax,beta5);\r
166         betaMax = _max2(betaMax,beta6);\r
167         betaMax = _max2(betaMax,beta7);\r
168         betaMax = _ext(betaMax,16,16);\r
169         betaMax = 127 - betaMax;\r
170 \r
171         beta0 = beta0 + betaMax;\r
172         beta1 = beta1 + betaMax;\r
173         beta2 = beta2 + betaMax;\r
174         beta3 = beta3 + betaMax;\r
175         beta4 = beta4 + betaMax;\r
176         beta5 = beta5 + betaMax;\r
177         beta6 = beta6 + betaMax;\r
178         beta7 = beta7 + betaMax;\r
179 \r
180         beta0 = _max2(0x8000ff81, beta0);\r
181         beta1 = _max2(0x8000ff81, beta1);\r
182         beta2 = _max2(0x8000ff81, beta2);\r
183         beta3 = _max2(0x8000ff81, beta3);\r
184         beta4 = _max2(0x8000ff81, beta4);\r
185         beta5 = _max2(0x8000ff81, beta5);\r
186         beta6 = _max2(0x8000ff81, beta6);\r
187         beta7 = _max2(0x8000ff81, beta7);\r
188 \r
189 #ifdef _BIG_ENDIAN\r
190         _mem4(&beta1Ptr[0]) = _packl4(_pack2(beta0,beta1),_pack2(beta2,beta3));\r
191         _mem4(&beta1Ptr[4]) = _packl4(_pack2(beta4,beta5),_pack2(beta6,beta7));\r
192 #else\r
193         _mem4(&beta1Ptr[0]) = _packl4(_pack2(beta3,beta2),_pack2(beta1,beta0));\r
194         _mem4(&beta1Ptr[4]) = _packl4(_pack2(beta7,beta6),_pack2(beta5,beta4));\r
195 #endif\r
196     }\r
197     else if(Kt==2)\r
198     {\r
199         //Beta MAP0\r
200         beta0 = 0;\r
201         beta1 = _ext(bit32,16,16) + _ext(bit32,0,16); //xt0[0] + xt0[1];\r
202         beta2 = _ext(bit32,16,16) + _ext(bit54,16,16) + _ext(bit54,0,16); //xt0[0] + xt0[2] + xt0[3];\r
203         beta3 = _ext(bit32,0,16) + _ext(bit54,16,16) + _ext(bit54,0,16);  //xt0[1] + xt0[2] + xt0[3];\r
204 \r
205         betaMax = _max2(beta0,beta1);\r
206         betaMax = _max2(betaMax,beta2);\r
207         betaMax = _max2(betaMax,beta3);\r
208         betaMax = _ext(betaMax,16,16);\r
209         betaMax = 127 - betaMax;\r
210 \r
211         beta0 = beta0 + betaMax;\r
212         beta1 = beta1 + betaMax;\r
213         beta2 = beta2 + betaMax;\r
214         beta3 = beta3 + betaMax;\r
215 \r
216         beta0 = _max2(0x8000ff81, beta0);\r
217         beta1 = _max2(0x8000ff81, beta1);\r
218         beta2 = _max2(0x8000ff81, beta2);\r
219         beta3 = _max2(0x8000ff81, beta3);\r
220 \r
221 #ifdef _BIG_ENDIAN\r
222         _mem4(&beta0Ptr[0]) = _packl4(_pack2(beta0,beta1),_pack2(beta2,beta3));\r
223 #else\r
224         _mem4(&beta0Ptr[0]) = _packl4(_pack2(beta3,beta2),_pack2(beta1,beta0));\r
225 #endif\r
226         _mem4(&beta0Ptr[4]) = 0x81818181;\r
227 \r
228         //Beta MAP1\r
229         //temp\r
230         beta0 = _ext(bit98,16,16);\r
231         beta0 = _ext(bit98,0,16);\r
232         beta0 = _ext(bitba,16,16);\r
233         beta0 = _ext(bitba,0,16);\r
234 \r
235         //temp\r
236         beta0 = 0;\r
237         beta1 = _ext(bit98,16,16) + _ext(bit98,0,16); //xt1[0] + xt1[1];\r
238         beta2 = _ext(bit98,16,16) + _ext(bitba,16,16) + _ext(bitba,0,16); //xt1[0] + xt1[2] + xt1[3];\r
239         beta3 = _ext(bit98,0,16) + _ext(bitba,16,16) + _ext(bitba,0,16);  //xt1[1] + xt1[2] + xt1[3];\r
240 \r
241         betaMax = _max2(beta0,beta1);\r
242         betaMax = _max2(betaMax,beta2);\r
243         betaMax = _max2(betaMax,beta3);\r
244         betaMax = _ext(betaMax,16,16);\r
245         betaMax = 127 - betaMax;\r
246 \r
247         beta0 = beta0 + betaMax;\r
248         beta1 = beta1 + betaMax;\r
249         beta2 = beta2 + betaMax;\r
250         beta3 = beta3 + betaMax;\r
251 \r
252         beta0 = _max2(0x8000ff81, beta0);\r
253         beta1 = _max2(0x8000ff81, beta1);\r
254         beta2 = _max2(0x8000ff81, beta2);\r
255         beta3 = _max2(0x8000ff81, beta3);\r
256 \r
257 #ifdef _BIG_ENDIAN\r
258         _mem4(&beta1Ptr[0]) = _packl4(_pack2(beta0,beta1),_pack2(beta2,beta3));\r
259 #else\r
260         _mem4(&beta1Ptr[0]) = _packl4(_pack2(beta3,beta2),_pack2(beta1,beta0));\r
261 #endif\r
262         _mem4(&beta1Ptr[4]) = 0x81818181;\r
263     }\r
264     else if(Kt==1)\r
265     {\r
266         //Beta MAP0\r
267         beta0 = 0;\r
268         beta1 = _ext(bit54,16,16) + _ext(bit54,0,16); //xt0[0] + xt0[1];\r
269 \r
270         betaMax = _max2(beta0,beta1);\r
271         betaMax = _ext(betaMax,16,16);\r
272         betaMax = 127 - betaMax;\r
273 \r
274         beta0 = beta0 + betaMax;\r
275         beta1 = beta1 + betaMax;\r
276 \r
277         beta0 = _max2(0x8000ff81, beta0);\r
278         beta1 = _max2(0x8000ff81, beta1);\r
279 \r
280 #ifdef _BIG_ENDIAN\r
281         _mem4(&beta0Ptr[0]) = _packl4(_pack2(beta0,beta1),0x81818181);\r
282 #else\r
283         _mem4(&beta0Ptr[0]) = _packl4(0x81818181,_pack2(beta1,beta0));\r
284 #endif\r
285         _mem4(&beta0Ptr[4]) = 0x81818181;\r
286 \r
287         //Beta MAP1\r
288         beta0 = 0;\r
289         beta1 = _ext(bitba,16,16) + _ext(bitba,0,16); //xt1[0] + xt1[1];\r
290 \r
291         betaMax = _max2(beta0,beta1);\r
292         betaMax = _ext(betaMax,16,16);\r
293         betaMax = 127 - betaMax;\r
294 \r
295         beta0 = beta0 + betaMax;\r
296         beta1 = beta1 + betaMax;\r
297 \r
298         beta0 = _max2(0x8000ff81, beta0);\r
299         beta1 = _max2(0x8000ff81, beta1);\r
300 \r
301 #ifdef _BIG_ENDIAN\r
302         _mem4(&beta1Ptr[0]) = _packl4(_pack2(beta0,beta1),0x81818181);\r
303 #else\r
304         _mem4(&beta1Ptr[0]) = _packl4(0x81818181,_pack2(beta1,beta0));\r
305 #endif\r
306         _mem4(&beta1Ptr[4]) = 0x81818181;\r
307 \r
308     }\r
309     else if(Kt==0)\r
310     {\r
311 #ifdef _BIG_ENDIAN\r
312         _mem4(&beta0Ptr[0]) = 0x7f818181;\r
313         _mem4(&beta1Ptr[0]) = 0x7f818181;\r
314 #else\r
315         _mem4(&beta0Ptr[0]) = 0x8181817f;\r
316         _mem4(&beta1Ptr[0]) = 0x8181817f;\r
317 #endif\r
318         _mem4(&beta0Ptr[4]) = 0x81818181;\r
319         _mem4(&beta1Ptr[4]) = 0x81818181;\r
320     }\r
321 }\r
322 \r
323 /* nothing past this line */\r