1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 #ifndef _VLC_ENCODE_INLINE_H_
19 #define _VLC_ENCODE_INLINE_H_
20 
21 #if !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4)
22 
zero_run_search(UInt * bitmapzz,Short * dataBlock,RunLevelBlock * RLB,Int nc)23 __inline  Int zero_run_search(UInt *bitmapzz, Short *dataBlock, RunLevelBlock *RLB, Int nc)
24 {
25     Int idx, run, level, j;
26     UInt end, match;
27 
28     idx = 0;
29     j   = 0;
30     run = 0;
31     match = 1 << 31;
32     if (nc > 32)
33         end = 1;
34     else
35         end = 1 << (32 - nc);
36 
37     while (match >= end)
38     {
39         if ((match&bitmapzz[0]) == 0)
40         {
41             run++;
42             j++;
43             match >>= 1;
44         }
45         else
46         {
47             match >>= 1;
48             level = dataBlock[j];
49             dataBlock[j] = 0; /* reset output */
50             j++;
51             if (level < 0)
52             {
53                 RLB->level[idx] = -level;
54                 RLB->s[idx] = 1;
55                 RLB->run[idx] = run;
56                 run = 0;
57                 idx++;
58             }
59             else
60             {
61                 RLB->level[idx] = level;
62                 RLB->s[idx] = 0;
63                 RLB->run[idx] = run;
64                 run = 0;
65                 idx++;
66             }
67         }
68     }
69     nc -= 32;
70     if (nc > 0)
71     {
72         match = 1 << 31;
73         end = 1 << (32 - nc);
74         while (match >= end)
75         {
76             if ((match&bitmapzz[1]) == 0)
77             {
78                 run++;
79                 j++;
80                 match >>= 1;
81             }
82             else
83             {
84                 match >>= 1;
85                 level = dataBlock[j];
86                 dataBlock[j] = 0; /* reset output */
87                 j++;
88                 if (level < 0)
89                 {
90                     RLB->level[idx] = -level;
91                     RLB->s[idx] = 1;
92                     RLB->run[idx] = run;
93                     run = 0;
94                     idx++;
95                 }
96                 else
97                 {
98                     RLB->level[idx] = level;
99                     RLB->s[idx] = 0;
100                     RLB->run[idx] = run;
101                     run = 0;
102                     idx++;
103                 }
104             }
105         }
106     }
107 
108     return idx;
109 }
110 
111 #elif defined(__CC_ARM)  /* only work with arm v5 */
112 
zero_run_search(UInt * bitmapzz,Short * dataBlock,RunLevelBlock * RLB,Int nc)113 __inline  Int zero_run_search(UInt *bitmapzz, Short *dataBlock, RunLevelBlock *RLB, Int nc)
114 {
115     OSCL_UNUSED_ARG(nc);
116     Int idx, run, level, j;
117     UInt end, match;
118     Int  zzorder;
119 
120     idx = 0;
121     run = 0;
122     j   = -1;
123     __asm
124     {
125         ldr match, [bitmapzz]
126         clz run, match
127     }
128 
129     zzorder = 0;
130 
131     while (run < 32)
132     {
133         __asm
134         {
135             mov end, #0x80000000
136             mov end, end, lsr run   /* mask*/
137             bic match, match, end       /* remove it from bitmap */
138             mov run, run, lsl #1  /* 05/09/02 */
139             ldrsh level, [dataBlock, run] /*  load data */
140             strh zzorder, [dataBlock, run] /* reset output */
141             add j, j, #1
142             rsb run, j, run, lsr #1 /* delta run */
143             add j, j, run           /* current position */
144         }
145         if (level < 0)
146         {
147             RLB->level[idx] = -level;
148             RLB->s[idx] = 1;
149             RLB->run[idx] = run;
150             run = 0;
151             idx++;
152         }
153         else
154         {
155             RLB->level[idx] = level;
156             RLB->s[idx] = 0;
157             RLB->run[idx] = run;
158             run = 0;
159             idx++;
160         }
161         __asm
162         {
163             clz run, match
164         }
165     }
166     __asm
167     {
168         ldr match, [bitmapzz, #4]
169         clz run, match
170     }
171 
172     while (run < 32)
173     {
174         __asm
175         {
176             mov end, #0x80000000
177             mov end, end, lsr run   /* mask*/
178             bic match, match, end       /* remove it from bitmap */
179             add run, run, #32       /* current position */
180             mov run, run, lsl #1    /* 09/02/05 */
181             ldrsh level, [dataBlock, run] /*  load data */
182             strh  zzorder, [dataBlock, run] /* reset output */
183             add j, j, #1
184             rsb run, j, run, lsr #1     /* delta run */
185             add j, j, run           /* current position */
186         }
187         if (level < 0)
188         {
189             RLB->level[idx] = -level;
190             RLB->s[idx] = 1;
191             RLB->run[idx] = run;
192             run = 0;
193             idx++;
194         }
195         else
196         {
197             RLB->level[idx] = level;
198             RLB->s[idx] = 0;
199             RLB->run[idx] = run;
200             run = 0;
201             idx++;
202         }
203         __asm
204         {
205             clz run, match
206         }
207     }
208 
209     return idx;
210 }
211 
212 #elif ( defined(PV_ARM_GCC_V4) || defined(PV_ARM_GCC_V5) ) /* ARM GNU COMPILER  */
213 
m4v_enc_clz(UInt temp)214 __inline Int m4v_enc_clz(UInt temp)
215 {
216     register Int rb;
217     register UInt ra = (UInt)temp;
218 
219     asm volatile("clz   %0, %1"
220              : "=&r"(rb)
221                          : "r"(ra)
222                         );
223 
224     return (rb);
225 }
226 
zero_run_search(UInt * bitmapzz,Short * dataBlock,RunLevelBlock * RLB,Int nc)227 __inline  Int zero_run_search(UInt *bitmapzz, Short *dataBlock, RunLevelBlock *RLB, Int nc)
228 {
229     OSCL_UNUSED_ARG(nc);
230     Int idx, run, level = 0, j;
231     UInt end = 0, match;
232     Int  zzorder;
233 
234     idx = 0;
235     run = 0;
236     j   = -1;
237     match = *bitmapzz;
238     run = m4v_enc_clz(match);
239 
240     zzorder = 0;
241 
242     while (run < 32)
243     {
244         asm volatile("mov   %0, #0x80000000\n\t"
245                      "mov   %0, %0, lsr %1\n\t"
246                      "bic   %2, %2, %0\n\t"
247                      "mov   %1, %1, lsl #1\n\t"
248                      "ldrsh %3, [%6, %1]\n\t"
249                      "strh  %5, [%6, %1]\n\t"
250                      "add   %4, %4, #1\n\t"
251                      "rsb   %1, %4, %1, lsr #1\n\t"
252                      "add   %4, %4, %1"
253              : "+r"(end), "+r"(run), "+r"(match), "=r"(level), "+r"(j)
254                              : "r"(zzorder), "r"(dataBlock));
255         if (level < 0)
256         {
257             RLB->level[idx] = -level;
258             RLB->s[idx] = 1;
259             RLB->run[idx] = run;
260             run = 0;
261             idx++;
262         }
263         else
264         {
265             RLB->level[idx] = level;
266             RLB->s[idx] = 0;
267             RLB->run[idx] = run;
268             run = 0;
269             idx++;
270         }
271         run = m4v_enc_clz(match);
272     }
273     match = bitmapzz[1];
274     run = m4v_enc_clz(match);
275 
276     while (run < 32)
277     {
278         asm volatile("mov   %0, #0x80000000\n\t"
279                      "mov   %0, %0, lsr %1\n\t"
280                      "bic   %2, %2, %0\n\t"
281                      "add   %1, %1, #32\n\t"
282                      "mov   %1, %1, lsl #1\n\t"
283                      "ldrsh %3, [%6, %1]\n\t"
284                      "strh  %5, [%6, %1]\n\t"
285                      "add   %4, %4, #1\n\t"
286                      "rsb   %1, %4, %1, lsr #1\n\t"
287                      "add   %4, %4, %1"
288              : "+r"(end), "+r"(run), "+r"(match), "+r"(level), "+r"(j)
289                              : "r"(zzorder), "r"(dataBlock));
290         if (level < 0)
291         {
292             RLB->level[idx] = -level;
293             RLB->s[idx] = 1;
294             RLB->run[idx] = run;
295             run = 0;
296             idx++;
297         }
298         else
299         {
300             RLB->level[idx] = level;
301             RLB->s[idx] = 0;
302             RLB->run[idx] = run;
303             run = 0;
304             idx++;
305         }
306         run = m4v_enc_clz(match);
307     }
308 
309     return idx;
310 }
311 
312 #endif
313 
314 #endif // _VLC_ENCODE_INLINE_H_
315 
316 
317