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