armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s revision 78e52bfac041d71ce53b5b13c2abf78af742b09d
1;//
2;// Copyright (C) 2007-2008 ARM Limited
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 express or implied.
13;// See the License for the specific language governing permissions and
14;// limitations under the License.
15;//
16;/**
17; *
18; * File Name:  armVCM4P2_DecodeVLCZigzag_AC_unsafe_s.s
19; * OpenMAX DL: v1.0.2
20; * Revision:   9641
21; * Date:       Thursday, February 7, 2008
22; *
23; *
24; *
25; *
26; * Description:
27; * Contains modules for zigzag scanning and VLC decoding
28; * for inter, intra block.
29; *
30; *
31; *
32; * Function: omxVCM4P2_DecodeVLCZigzag_AC_unsafe
33; *
34; * Description:
35; * Performs VLC decoding and inverse zigzag scan
36; *
37; *
38; *
39; *
40; */
41
42
43      INCLUDE omxtypes_s.h
44      INCLUDE armCOMM_s.h
45      INCLUDE armCOMM_BitDec_s.h
46
47
48      M_VARIANTS ARM1136JS
49
50
51
52
53
54     IF ARM1136JS
55
56
57
58
59
60;//Input Arguments
61
62ppBitStream          RN 0
63pBitOffset           RN 1
64pDst                 RN 2
65shortVideoHeader     RN 3
66
67
68;//Local Variables
69
70Return               RN 0
71
72pVlcTableL0L1        RN 4
73pLMAXTableL0L1       RN 4
74pRMAXTableL0L1       RN 4
75pZigzagTable         RN 4
76
77ftype                RN 0
78temp3                RN 4
79temp                 RN 5
80Count                RN 6
81Escape               RN 5
82
83;// armVCM4P2_FillVLDBuffer
84zigzag               RN 0
85storeLevel           RN 1
86temp2                RN 4
87temp1                RN 5
88sign                 RN 5
89Last                 RN 7
90storeRun             RN 14
91
92
93packRetIndex         RN 5
94
95
96markerbit            RN 5
97
98;// Scratch Registers
99
100RBitStream           RN 8
101RBitBuffer           RN 9
102RBitCount            RN 10
103
104T1                   RN 11
105T2                   RN 12
106LR                   RN 14
107
108
109
110        M_ALLOC4        pppBitStream,4
111        M_ALLOC4        ppOffset,4
112        M_ALLOC4        pLinkRegister,4
113
114        M_START armVCM4P2_DecodeVLCZigzag_AC_unsafe
115
116        ;// get the table addresses from stack
117        M_ARG           ppVlcTableL0L1,4
118        M_ARG           ppLMAXTableL0L1,4
119        M_ARG           ppRMAXTableL0L1,4
120        M_ARG           ppZigzagTable,4
121
122        ;// Store ALL zeros at pDst
123
124        MOV             temp1,#0                                        ;// Initialize Count to zero
125        MOV             Last,#0
126        M_STR           LR,pLinkRegister                                ;// Store Link Register on Stack
127        MOV             temp2,#0
128        MOV             LR,#0
129
130        ;// Initialize the Macro and Store all zeros to pDst
131
132        STM             pDst!,{temp2,temp1,Last,LR}
133        M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount
134        STM             pDst!,{temp2,temp1,Last,LR}
135        M_BD_INIT1      T1, T2, T2
136        STM             pDst!,{temp2,temp1,Last,LR}
137        M_BD_INIT2      T1, T2, T2
138        STM             pDst!,{temp2,temp1,Last,LR}
139        M_STR           ppBitStream,pppBitStream                        ;// Store ppBitstream on stack
140        STM             pDst!,{temp2,temp1,Last,LR}
141        M_STR           pBitOffset,ppOffset                             ;// Store pBitOffset on stack
142        STM             pDst!,{temp2,temp1,Last,LR}
143
144        STM             pDst!,{temp2,temp1,Last,LR}
145        STM             pDst!,{temp2,temp1,Last,LR}
146
147
148        SUB             pDst,pDst,#128                                  ;// Restore pDst
149
150        ;// The armVCM4P2_GetVLCBits begins
151
152getVLCbits
153
154        M_BD_LOOK8      Escape,7                                        ;// Load Escape Value
155        LSR             Escape,Escape,#25
156        CMP             Escape,#3                                       ;// check for escape mode
157        MOVNE           ftype,#0
158        BNE             notEscapemode                                   ;// Branch if not in Escape mode 3
159
160        M_BD_VSKIP8     #7,T1
161        CMP             shortVideoHeader,#0                             ;// Check shortVideoHeader flag to know the type of Escape mode
162        BEQ             endFillVLD
163
164        ;// Escape Mode 4
165
166        M_BD_READ8      Last,1,T1
167        M_BD_READ8      storeRun,6,T1
168        M_BD_READ8      storeLevel,8,T1
169
170
171        ;// Check whether the Reserved values for Level are used and Exit with an Error Message if it is so
172
173        TEQ             storeLevel,#0
174        TEQNE           storeLevel,#128
175        BEQ             ExitError
176
177        ADD             temp2,storeRun,Count
178        CMP             temp2,#64
179        BGE             ExitError                                       ;// error if Count+storeRun >= 64
180
181
182        ;// Load address of zigzagTable
183
184        M_LDR           pZigzagTable,ppZigzagTable                      ;// Loading the Address of Zigzag table
185
186
187        ;// armVCM4P2_FillVLDBuffer
188
189        SXTB            storeLevel,storeLevel                           ;// Sign Extend storeLevel to 32 bits
190
191
192        ;// To Reflect Runlength
193
194        ADD             Count,Count,storeRun
195        LDRB            zigzag,[pZigzagTable,Count]
196        ADD             Count,Count,#1
197        STRH            storeLevel,[pDst,zigzag]                        ;// store Level
198
199        B               ExitOk
200
201
202
203endFillVLD
204
205
206        ;// Load Ftype( Escape Mode) value based on the two successive bits in the bitstream
207
208        M_BD_READ8      temp1,1,T1
209        CMP             temp1,#0
210        MOVEQ           ftype,#1
211        BEQ             notEscapemode
212        M_BD_READ8      temp1,1,T1
213        CMP             temp1,#1
214        MOVEQ           ftype,#3
215        MOVNE           ftype,#2
216
217
218notEscapemode
219
220        ;// Load optimized packed VLC table with last=0 and Last=1
221
222        M_LDR           pVlcTableL0L1,ppVlcTableL0L1                    ;// Load Combined VLC Table
223
224
225        CMP             ftype,#3                                        ;// If ftype >=3 get perform Fixed Length Decoding (Escape Mode 3)
226        BGE             EscapeMode3                                     ;// Else continue normal VLC Decoding
227
228        ;// Variable lengh decoding, "armUnPackVLC32"
229
230
231        M_BD_VLD        packRetIndex,T1,T2,pVlcTableL0L1,4,2
232
233
234        LDR             temp3,=0xFFF
235
236        CMP             packRetIndex,temp3                              ;// Check for invalid symbol
237        BEQ             ExitError                                       ;// if invalid symbol occurs exit with an error message
238
239        AND             Last,packRetIndex,#2                            ;// Get Last from packed Index
240
241
242
243
244        LSR             storeRun,packRetIndex,#7                        ;// Get Run Value from Packed index
245        AND             storeLevel,packRetIndex,#0x7c                   ;// storeLevel=packRetIndex[2-6],storeLevel[0-1]=0
246
247
248        M_LDR           pLMAXTableL0L1,ppLMAXTableL0L1                  ;// Load LMAX table
249
250
251        LSR             storeLevel,storeLevel,#2                        ;// Level value
252
253        CMP             ftype,#1
254        BNE             ftype2
255
256        ;// ftype==1; Escape mode =1
257
258
259        ADD            temp1, pLMAXTableL0L1, Last, LSL#4              ;// If the Last=1 add 32 to table address
260        LDRB            temp1,[temp1,storeRun]
261
262
263        ADD             storeLevel,temp1,storeLevel
264
265ftype2
266
267        ;// ftype =2; Escape mode =2
268
269        M_LDR           pRMAXTableL0L1,ppRMAXTableL0L1                  ;// Load RMAX Table
270
271        CMP             ftype,#2
272        BNE             FillVLDL1
273
274        ADD            temp1, pRMAXTableL0L1, Last, LSL#4               ;// If Last=1 add 32 to table address
275        SUB             temp2,storeLevel,#1
276        LDRB            temp1,[temp1,temp2]
277
278
279        ADD             storeRun,storeRun,#1
280        ADD             storeRun,temp1
281
282FillVLDL1
283
284
285        ;// armVCM4P2_FillVLDBuffer
286
287        M_LDR           pZigzagTable,ppZigzagTable                     ;// Load address of zigzagTable
288
289        M_BD_READ8      sign,1,T1
290
291        CMP             sign,#1
292        RSBEQ           storeLevel,storeLevel,#0
293
294        ADD             temp1,storeRun,Count                           ;// Exit with an error message if Run + Count exceeds 63
295        CMP             temp1,#64
296        BGE             ExitError
297
298
299
300
301
302
303        ;// To Reflect Runlenght
304
305        ADD             Count,Count,storeRun
306
307storeLevelL1
308
309        LDRB            zigzag,[pZigzagTable,Count]
310        CMP             Last,#2                                         ;// Check if the Level val is Last non zero val
311        ADD             Count,Count,#1
312        LSR             Last,Last,#1
313        STRH            storeLevel,[pDst,zigzag]
314
315        BNE             end
316
317        B               ExitOk
318
319
320
321        ;// Fixed Lengh Decoding Escape Mode 3
322
323EscapeMode3
324
325        M_BD_READ8      Last,1,T1
326        M_BD_READ8      storeRun,6,T1
327
328        ADD             temp2,storeRun,Count                            ;// Exit with an error message if Run + Count exceeds 63
329        CMP             temp2,#64
330        BGE             ExitError
331
332        M_BD_READ8      markerbit,1,T1
333        TEQ             markerbit,#0                                    ;// Exit with an error message if marker bit is zero
334        BEQ             ExitError
335
336        M_BD_READ16     storeLevel,12,T1
337
338        TST             storeLevel,#0x800                               ;// test if the level is negative
339        SUBNE           storeLevel,storeLevel,#4096
340        CMP             storeLevel,#0
341        CMPNE           storeLevel,#-2048
342        BEQ             ExitError                                       ;// Exit with an error message if Level==0 or  -2048
343
344        M_LDR           pZigzagTable,ppZigzagTable                      ;// Load address of zigzagTable
345
346        M_BD_READ8      markerbit,1,T1
347
348
349        ;// armVCM4P2_FillVLDBuffer ( Sign not used as storeLevel is preprocessed)
350
351
352
353        ;// To Reflect Run Length
354
355        ADD             Count,Count,storeRun
356
357
358
359storeLevelLast
360
361        LDRB            zigzag,[pZigzagTable,Count]
362        CMP             Last,#1
363        ADD             Count,Count,#1
364        STRH            storeLevel,[pDst,zigzag]
365
366        BNE             end
367
368        B               ExitOk
369
370end
371
372        CMP             Count,#64                                       ;//Run the Loop untill Count reaches 64
373
374        BLT             getVLCbits
375
376
377ExitOk
378        ;// Exit When VLC Decoding is done Successfully
379
380        ;// Loading ppBitStream and pBitOffset from stack
381
382        CMP             Last,#1
383        M_LDR           ppBitStream,pppBitStream
384        M_LDR           pBitOffset,ppOffset
385
386        ;//Ending the macro
387
388        M_BD_FINI       ppBitStream,pBitOffset
389
390        MOVEQ           Return,#OMX_Sts_NoErr
391        MOVNE           Return,#OMX_Sts_Err
392        M_LDR           LR,pLinkRegister                               ;// Load the Link Register Back
393        B               exit2
394
395ExitError
396        ;// Exit When an Error occurs
397
398        M_LDR           ppBitStream,pppBitStream
399        M_LDR           pBitOffset,ppOffset
400        ;//Ending the macro
401
402        M_BD_FINI       ppBitStream,pBitOffset
403        M_LDR           LR,pLinkRegister
404        MOV             Return,#OMX_Sts_Err
405
406exit2
407
408
409        M_END
410        ENDIF
411
412        END
413