armVCM4P10_DecodeCoeffsToPair_s.s revision 0c1bc742181ded4930842b46e9507372f0b1b963
1;//
2;//
3;// File Name:  armVCM4P10_DecodeCoeffsToPair_s.s
4;// OpenMAX DL: v1.0.2
5;// Revision:   12290
6;// Date:       Wednesday, April 9, 2008
7;//
8;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
9;//
10;//
11;//
12
13        INCLUDE omxtypes_s.h
14        INCLUDE armCOMM_s.h
15        INCLUDE armCOMM_BitDec_s.h
16
17        IMPORT armVCM4P10_CAVLCCoeffTokenTables
18        IMPORT armVCM4P10_CAVLCTotalZeroTables
19        IMPORT armVCM4P10_CAVLCTotalZeros2x2Tables
20        IMPORT armVCM4P10_CAVLCRunBeforeTables
21        IMPORT armVCM4P10_SuffixToLevel
22        IMPORT armVCM4P10_ZigZag_4x4
23        IMPORT armVCM4P10_ZigZag_2x2
24
25        M_VARIANTS ARM1136JS
26
27;//DEBUG_ON    SETL {TRUE}
28
29LAST_COEFF               EQU 0x20        ;// End of block flag
30TWO_BYTE_COEFF           EQU 0x10
31
32;// Declare input registers
33
34ppBitStream     RN 0
35pOffset         RN 1
36pNumCoeff       RN 2
37ppPosCoefbuf    RN 3
38nC              RN 4 ;// number of coeffs or 17 for chroma
39sMaxNumCoeff    RN 5
40
41;// Declare inner loop registers
42
43;// Level loop
44Count           RN 0
45TrailingOnes    RN 1
46pLevel          RN 2
47LevelSuffix     RN 3
48SuffixLength    RN 4
49TotalCoeff      RN 5
50
51pVLDTable       RN 6
52Symbol          RN 7
53T1              RN 8
54T2              RN 9
55RBitStream      RN 10
56RBitBuffer      RN 11
57RBitCount       RN 12
58lr              RN 14
59
60;// Run loop
61Count           RN 0
62ZerosLeft       RN 1
63pLevel          RN 2
64ppRunTable      RN 3
65pRun            RN 4
66TotalCoeff      RN 5
67
68pVLDTable       RN 6
69Symbol          RN 7
70T1              RN 8
71T2              RN 9
72RBitStream      RN 10
73RBitBuffer      RN 11
74RBitCount       RN 12
75lr              RN 14
76
77;// Fill in coefficients loop
78pPosCoefbuf     RN 0
79temp            RN 1
80pLevel          RN 2
81ppPosCoefbuf    RN 3
82pRun            RN 4
83TotalCoeff      RN 5
84pZigZag         RN 6
85
86T1              RN 8
87T2              RN 9
88RBitStream      RN 10
89RBitBuffer      RN 11
90RBitCount       RN 12
91CoeffNum        RN 14
92
93
94
95    IF ARM1136JS
96
97        ;// Allocate stack memory required by the function
98        M_ALLOC4 pppBitStream, 4
99        M_ALLOC4 ppOffset, 4
100        M_ALLOC4 pppPosCoefbuf, 4
101        M_ALLOC4 ppLevel, 16*2
102        M_ALLOC4 ppRun, 16
103
104        ;// Write function header
105        M_START armVCM4P10_DecodeCoeffsToPair, r11
106
107        ;// Define stack arguments
108        M_ARG   pNC, 4
109        M_ARG   pSMaxNumCoeff,4
110
111        ;// Code start
112        M_BD_INIT0 ppBitStream, pOffset, RBitStream, RBitBuffer, RBitCount
113        LDR        pVLDTable, =armVCM4P10_CAVLCCoeffTokenTables
114        M_LDR      nC, pNC
115
116        M_BD_INIT1 T1, T2, lr
117        LDR     pVLDTable, [pVLDTable, nC, LSL #2]  ;// Find VLD table
118
119        M_BD_INIT2 T1, T2, lr
120
121        ;// Decode Symbol = TotalCoeff*4 + TrailingOnes
122        M_BD_VLD  Symbol, T1, T2, pVLDTable, 4, 2
123
124        MOVS    TotalCoeff, Symbol, LSR #2
125        STRB    TotalCoeff, [pNumCoeff]
126        M_PRINTF "TotalCoeff=%d\n", TotalCoeff
127        BEQ.W   EndNoError                  ;// Finished if no coefficients
128
129        CMP     Symbol, #17*4
130        BGE.W   EndBadSymbol                ;// Error if bad symbol
131
132        ;// Save bitstream pointers
133        M_STR   ppBitStream,  pppBitStream
134        M_STR   pOffset,      ppOffset
135        M_STR   ppPosCoefbuf, pppPosCoefbuf
136
137        ;// Decode Trailing Ones
138        ANDS    TrailingOnes, Symbol, #3
139        M_ADR   pLevel, ppLevel
140        M_PRINTF "TrailingOnes=%d\n", TrailingOnes
141        BEQ     TrailingOnesDone
142        MOV     Count, TrailingOnes
143TrailingOnesLoop
144        M_BD_READ8 Symbol, 1, T1
145        SUBS    Count, Count, #1
146        MOV     T1, #1
147        SUB     T1, T1, Symbol, LSL #1
148        M_PRINTF "Level=%d\n", T1
149        STRH    T1, [pLevel], #2
150        BGT     TrailingOnesLoop
151TrailingOnesDone
152
153        ;// Decode level values
154        SUBS    Count, TotalCoeff, TrailingOnes     ;// Number of levels to read
155        BEQ     DecodeRuns                          ;// None left
156
157        MOV     SuffixLength, #1
158        CMP     TotalCoeff, #10
159        MOVLE   SuffixLength, #0
160        CMP     TrailingOnes, #3    ;// if (TrailingOnes<3)
161        MOVLT   TrailingOnes, #4    ;// then TrailingOnes = +4
162        MOVGE   TrailingOnes, #2    ;// else TrailingOnes = +2
163        MOVGE   SuffixLength, #0    ;//      SuffixLength = 0
164
165LevelLoop
166        M_BD_CLZ16 Symbol, T1, T2   ;// Symbol=LevelPrefix
167        CMP     Symbol,#16
168        BGE     EndBadSymbol
169
170        MOVS    lr, SuffixLength    ;// if LevelSuffixSize==0
171        TEQEQ   Symbol, #14         ;//   and  LevelPrefix==14
172        MOVEQ   lr, #4              ;//   then LevelSuffixSize=4
173        TEQ     Symbol, #15         ;// if LevelSuffixSize==15
174        MOVEQ   lr, #12             ;//   then LevelSuffixSize=12
175
176        TEQEQ   SuffixLength,#0
177        ADDEQ   Symbol,Symbol,#15
178
179        TEQ     lr, #0              ;// if LevelSuffixSize==0
180        BEQ     LevelCodeRead       ;// LevelCode = LevelPrefix
181
182        M_BD_VREAD16 LevelSuffix, lr, T1, T2  ;// Read Level Suffix
183
184        MOV     Symbol, Symbol, LSL SuffixLength
185        ADD     Symbol, LevelSuffix, Symbol
186
187LevelCodeRead
188        ;// Symbol = LevelCode
189        ADD     Symbol, Symbol, TrailingOnes ;// +4 if level cannot be +/-1, +2 o/w
190        MOV     TrailingOnes, #2
191        MOVS    T1, Symbol, LSR #1
192        RSBCS   T1, T1, #0                  ;// If Symbol odd then negate
193        M_PRINTF "Level=%d\n", T1
194        STRH    T1, [pLevel], #2            ;// Store level.
195
196        LDR     T2, =armVCM4P10_SuffixToLevel
197        LDRSB   T1, [T2, SuffixLength]      ;// Find increment level
198        TEQ     SuffixLength, #0
199        MOVEQ   SuffixLength, #1
200        CMP     Symbol, T1
201        ADDCS   SuffixLength, SuffixLength, #1
202        SUBS    Count, Count, #1
203        BGT     LevelLoop
204
205DecodeRuns
206        ;// Find number of zeros
207        M_LDR   T1, pSMaxNumCoeff           ;// sMaxNumCoeff
208        SUB     Count, TotalCoeff, #1       ;// Number of runs excluding last
209        SUBS    ZerosLeft, T1, TotalCoeff   ;// Maximum number of zeros there could be
210        M_ADR   pRun, ppRun
211        MOV     CoeffNum,TotalCoeff
212        SUB     CoeffNum,CoeffNum,#1
213        BEQ     NoZerosLeft
214
215        ;// Unpack number of zeros from bitstream
216        TEQ     T1, #4
217        LDREQ   pVLDTable, =(armVCM4P10_CAVLCTotalZeros2x2Tables-4)
218        LDRNE   pVLDTable, =(armVCM4P10_CAVLCTotalZeroTables-4)
219        LDR     pVLDTable, [pVLDTable, TotalCoeff, LSL #2]
220
221        M_BD_VLD  Symbol, T1, T2, pVLDTable, 4, 2 ;// Symbol = ZerosLeft
222        CMP     Symbol,#16
223        BGE     EndBadSymbol
224
225        LDR     ppRunTable, =(armVCM4P10_CAVLCRunBeforeTables-4)
226        M_ADR   pRun, ppRun
227        MOVS    ZerosLeft, Symbol
228
229        ADD     CoeffNum,CoeffNum,ZerosLeft
230
231        BEQ     NoZerosLeft
232
233        ;// Decode runs while zeros are left and more than one coefficient
234RunLoop
235        SUBS    Count, Count, #1
236        LDR     pVLDTable, [ppRunTable, ZerosLeft, LSL#2]
237        BLT     LastRun
238        M_BD_VLD  Symbol, T1, T2, pVLDTable, 3, 2 ;// Symbol = Run
239        CMP     Symbol,#15
240        BGE     EndBadSymbol
241
242        SUBS    ZerosLeft, ZerosLeft, Symbol
243        M_PRINTF "Run=%d\n", Symbol
244        STRB    Symbol, [pRun], #1
245        BGT     RunLoop
246
247        ;// Decode runs while no zeros are left
248NoZerosLeft
249        SUBS    Count, Count, #1
250        M_PRINTF "Run=%d\n", ZerosLeft
251        STRGEB  ZerosLeft, [pRun], #1
252        BGT     NoZerosLeft
253
254LastRun
255        ;// Final run length is remaining zeros
256        M_PRINTF "LastRun=%d\n", ZerosLeft
257        STRB    ZerosLeft, [pRun], #1
258
259        ;// Write coefficients to output array
260        M_LDR   T1, pSMaxNumCoeff                    ;// sMaxNumCoeff
261        TEQ     T1, #15
262        ADDEQ   CoeffNum,CoeffNum,#1
263
264
265        SUB     pRun,pRun,TotalCoeff
266        SUB     pLevel,pLevel,TotalCoeff
267        SUB     pLevel,pLevel,TotalCoeff
268
269        M_LDR   ppPosCoefbuf, pppPosCoefbuf
270        LDR     pPosCoefbuf, [ppPosCoefbuf]
271        TEQ     T1, #4
272        LDREQ   pZigZag, =armVCM4P10_ZigZag_2x2
273        LDRNE   pZigZag, =armVCM4P10_ZigZag_4x4
274
275
276
277OutputLoop
278
279        LDRB    T2, [pRun],#1
280        LDRB    T1, [pZigZag, CoeffNum]
281        SUB     CoeffNum, CoeffNum, #1      ;// Skip Non zero
282        SUB     CoeffNum, CoeffNum, T2      ;// Skip Zero run
283
284        LDRSH   T2, [pLevel],#2
285
286        SUBS    TotalCoeff, TotalCoeff, #1
287        ORREQ   T1, T1, #LAST_COEFF
288
289        ADD     temp, T2, #128
290        CMP     temp, #256
291        ORRCS   T1, T1, #TWO_BYTE_COEFF
292
293
294        TEQ     TotalCoeff, #0              ;// Preserves carry
295
296        M_PRINTF "Output=%02x %04x\n", T1, T2
297        STRB    T1, [pPosCoefbuf], #1
298        STRB    T2, [pPosCoefbuf], #1
299        MOV     T2, T2, LSR #8
300        STRCSB  T2, [pPosCoefbuf], #1
301        BNE     OutputLoop
302
303        ;// Finished
304        STR     pPosCoefbuf, [ppPosCoefbuf]
305        M_LDR   ppBitStream, pppBitStream
306        M_LDR   pOffset, ppOffset
307        B       EndNoError
308
309EndBadSymbol
310        MOV     r0, #OMX_Sts_Err
311        B       End
312
313EndNoError
314        ;// Finished reading from the bitstream
315        M_BD_FINI ppBitStream, pOffset
316
317        ;// Set return value
318        MOV     r0, #OMX_Sts_NoErr
319End
320        M_END
321
322    ENDIF
323
324    END
325
326