10c1bc742181ded4930842b46e9507372f0b1b963James Dong;/**
20c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
30c1bc742181ded4930842b46e9507372f0b1b963James Dong; * File Name:  omxVCM4P2_DecodeVLCZigzag_IntraDCVLC_s.s
40c1bc742181ded4930842b46e9507372f0b1b963James Dong; * OpenMAX DL: v1.0.2
50c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Revision:   9641
60c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Date:       Thursday, February 7, 2008
70c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong; * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
90c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
110c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
120c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Description:
130c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Contains modules for zigzag scanning and VLC decoding
140c1bc742181ded4930842b46e9507372f0b1b963James Dong; * for inter block.
150c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
160c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
170c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
180c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Function: omxVCM4P2_DecodeVLCZigzag_Inter
190c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
200c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Description:
210c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Performs VLC decoding and inverse zigzag scan for one intra coded block.
220c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
230c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Remarks:
240c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
250c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Parameters:
260c1bc742181ded4930842b46e9507372f0b1b963James Dong; * [in]    ppBitStream        pointer to the pointer to the current byte in
270c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                    the bitstream buffer
280c1bc742181ded4930842b46e9507372f0b1b963James Dong; * [in]    pBitOffset        pointer to the bit position in the byte pointed
290c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                    to by *ppBitStream. *pBitOffset is valid within    [0-7].
300c1bc742181ded4930842b46e9507372f0b1b963James Dong; * [in] shortVideoHeader     binary flag indicating presence of short_video_header;
310c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                           escape modes 0-3 are used if shortVideoHeader==0,
320c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                           and escape mode 4 is used when shortVideoHeader==1.
330c1bc742181ded4930842b46e9507372f0b1b963James Dong; * [out]    ppBitStream        *ppBitStream is updated after the block is
340c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                    decoded, so that it points to the current byte
350c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                    in the bit stream buffer
360c1bc742181ded4930842b46e9507372f0b1b963James Dong; * [out]    pBitOffset        *pBitOffset is updated so that it points to the
370c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                    current bit position in the byte pointed by
380c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                    *ppBitStream
390c1bc742181ded4930842b46e9507372f0b1b963James Dong; * [out]    pDst            pointer to the coefficient buffer of current
400c1bc742181ded4930842b46e9507372f0b1b963James Dong; *                    block. Must be 16-byte aligned
410c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
420c1bc742181ded4930842b46e9507372f0b1b963James Dong; * Return Value:
430c1bc742181ded4930842b46e9507372f0b1b963James Dong; * OMX_Sts_BadArgErr - bad arguments
440c1bc742181ded4930842b46e9507372f0b1b963James Dong; *   -At least one of the following pointers is NULL: ppBitStream, *ppBitStream, pBitOffset, pDst, or
450c1bc742181ded4930842b46e9507372f0b1b963James Dong; *   -pDst is not 16-byte aligned, or
460c1bc742181ded4930842b46e9507372f0b1b963James Dong; *   -*pBitOffset exceeds [0,7].
470c1bc742181ded4930842b46e9507372f0b1b963James Dong; * OMX_Sts_Err - status error
480c1bc742181ded4930842b46e9507372f0b1b963James Dong; *   -At least one mark bit is equal to zero
490c1bc742181ded4930842b46e9507372f0b1b963James Dong; *   -Encountered an illegal stream code that cannot be found in the VLC table
500c1bc742181ded4930842b46e9507372f0b1b963James Dong; *   -Encountered and illegal code in the VLC FLC table
510c1bc742181ded4930842b46e9507372f0b1b963James Dong; *   -The number of coefficients is greater than 64
520c1bc742181ded4930842b46e9507372f0b1b963James Dong; *
530c1bc742181ded4930842b46e9507372f0b1b963James Dong; */
540c1bc742181ded4930842b46e9507372f0b1b963James Dong
550c1bc742181ded4930842b46e9507372f0b1b963James Dong
560c1bc742181ded4930842b46e9507372f0b1b963James Dong      INCLUDE omxtypes_s.h
570c1bc742181ded4930842b46e9507372f0b1b963James Dong      INCLUDE armCOMM_s.h
580c1bc742181ded4930842b46e9507372f0b1b963James Dong      INCLUDE armCOMM_BitDec_s.h
590c1bc742181ded4930842b46e9507372f0b1b963James Dong
600c1bc742181ded4930842b46e9507372f0b1b963James Dong
610c1bc742181ded4930842b46e9507372f0b1b963James Dong      M_VARIANTS ARM1136JS
620c1bc742181ded4930842b46e9507372f0b1b963James Dong
630c1bc742181ded4930842b46e9507372f0b1b963James Dong
640c1bc742181ded4930842b46e9507372f0b1b963James Dong
650c1bc742181ded4930842b46e9507372f0b1b963James Dong
660c1bc742181ded4930842b46e9507372f0b1b963James Dong
670c1bc742181ded4930842b46e9507372f0b1b963James Dong      IF ARM1136JS :LOR: CortexA8
680c1bc742181ded4930842b46e9507372f0b1b963James Dong
690c1bc742181ded4930842b46e9507372f0b1b963James Dong
700c1bc742181ded4930842b46e9507372f0b1b963James Dong        ;// Import various tables needed for the function
710c1bc742181ded4930842b46e9507372f0b1b963James Dong
720c1bc742181ded4930842b46e9507372f0b1b963James Dong
730c1bc742181ded4930842b46e9507372f0b1b963James Dong        IMPORT          armVCM4P2_IntraVlcL0L1             ;// Contains optimized and packed VLC Tables for both Last =1 and last=0
740c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                               ;// Packed in Run:Level:Last format
750c1bc742181ded4930842b46e9507372f0b1b963James Dong        IMPORT          armVCM4P2_IntraL0L1LMAX            ;// Contains LMAX table entries with both Last=0 and Last=1
760c1bc742181ded4930842b46e9507372f0b1b963James Dong        IMPORT          armVCM4P2_IntraL0L1RMAX            ;// Contains RMAX table entries with both Last=0 and Last=1
770c1bc742181ded4930842b46e9507372f0b1b963James Dong        IMPORT          armVCM4P2_aClassicalZigzagScan     ;// contains CLassical, Horizontal, Vertical Zigzag table entries with double the original values
780c1bc742181ded4930842b46e9507372f0b1b963James Dong        IMPORT          armVCM4P2_aIntraDCLumaChromaIndex  ;// Contains Optimized DCLuma and DCChroma Index table Entries
790c1bc742181ded4930842b46e9507372f0b1b963James Dong
800c1bc742181ded4930842b46e9507372f0b1b963James Dong
810c1bc742181ded4930842b46e9507372f0b1b963James Dong        IMPORT          armVCM4P2_DecodeVLCZigzag_AC_unsafe
820c1bc742181ded4930842b46e9507372f0b1b963James Dong
830c1bc742181ded4930842b46e9507372f0b1b963James Dong;//Input Arguments
840c1bc742181ded4930842b46e9507372f0b1b963James Dong
850c1bc742181ded4930842b46e9507372f0b1b963James DongppBitStream          RN 0
860c1bc742181ded4930842b46e9507372f0b1b963James DongpBitOffset           RN 1
870c1bc742181ded4930842b46e9507372f0b1b963James DongpDst                 RN 2
880c1bc742181ded4930842b46e9507372f0b1b963James DongPredDir              RN 3
890c1bc742181ded4930842b46e9507372f0b1b963James DongshortVideoHeader     RN 3
900c1bc742181ded4930842b46e9507372f0b1b963James DongvideoComp            RN 5
910c1bc742181ded4930842b46e9507372f0b1b963James Dong;//Local Variables
920c1bc742181ded4930842b46e9507372f0b1b963James Dong
930c1bc742181ded4930842b46e9507372f0b1b963James DongReturn               RN 0
940c1bc742181ded4930842b46e9507372f0b1b963James Dong
950c1bc742181ded4930842b46e9507372f0b1b963James DongpDCLumaChromaIndex   RN 4
960c1bc742181ded4930842b46e9507372f0b1b963James DongpDCChromaIndex       RN 7
970c1bc742181ded4930842b46e9507372f0b1b963James DongpVlcTableL0L1        RN 4
980c1bc742181ded4930842b46e9507372f0b1b963James DongpLMAXTableL0L1       RN 4
990c1bc742181ded4930842b46e9507372f0b1b963James DongpRMAXTableL0L1       RN 4
1000c1bc742181ded4930842b46e9507372f0b1b963James DongpZigzagTable         RN 4
1010c1bc742181ded4930842b46e9507372f0b1b963James DongCount                RN 6
1020c1bc742181ded4930842b46e9507372f0b1b963James DongDCValueSize          RN 6
1030c1bc742181ded4930842b46e9507372f0b1b963James DongpowOfSize            RN 7
1040c1bc742181ded4930842b46e9507372f0b1b963James Dongtemp1                RN 5
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong;// Scratch Registers
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong
1090c1bc742181ded4930842b46e9507372f0b1b963James DongRBitStream           RN 8
1100c1bc742181ded4930842b46e9507372f0b1b963James DongRBitBuffer           RN 9
1110c1bc742181ded4930842b46e9507372f0b1b963James DongRBitCount            RN 10
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong
1130c1bc742181ded4930842b46e9507372f0b1b963James DongT1                   RN 11
1140c1bc742181ded4930842b46e9507372f0b1b963James DongT2                   RN 12
1150c1bc742181ded4930842b46e9507372f0b1b963James DongDCVal                RN 14
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong        ;// Allocate stack memory to store optimized VLC,Zigzag, RMAX, LMAX Table Addresses
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_ALLOC4        ppVlcTableL0L1,4
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_ALLOC4        ppLMAXTableL0L1,4
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_ALLOC4        ppRMAXTableL0L1,4
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_ALLOC4        ppZigzagTable,4
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_ALLOC4        pDCCoeff,4
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_START omxVCM4P2_DecodeVLCZigzag_IntraDCVLC,r12
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_ARG           shortVideoHeaderonStack,4                                  ;// Pointer to argument on stack
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_ARG           videoComponstack,4                                         ;// Pointer to argument on stack
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong        ;// Decode DC Coefficient
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong        LDR             pDCLumaChromaIndex, =armVCM4P2_aIntraDCLumaChromaIndex ;// Load Optimized VLC Table for Luminance and Chrominance
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong        ;// Initializing the Bitstream Macro
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_INIT0      ppBitStream, pBitOffset, RBitStream, RBitBuffer, RBitCount
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_LDR           videoComp,videoComponstack
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_INIT1      T1, T2, T2
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong        ADD             pDCLumaChromaIndex,pDCLumaChromaIndex,videoComp, LSL #6
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_INIT2      T1, T2, T2
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_VLD        DCValueSize,T1,T2,pDCLumaChromaIndex,4,2                    ;// VLC Decode using optimized Luminance and Chrominance VLC Table
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong
1530c1bc742181ded4930842b46e9507372f0b1b963James DongDecodeDC
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong        CMP             DCValueSize,#12
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong        BGT             ExitError
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong        CMP             DCValueSize,#0
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong        MOVEQ           DCVal,#0                                                    ;// If DCValueSize is zero then DC coeff =0
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong        BEQ             ACDecode                                                    ;// Branch to perform AC Coeff Decoding
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_VREAD16    DCVal,DCValueSize,T1,T2                                     ;// Get DC Value From Bit stream
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong        MOV             powOfSize,#1
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong        LSL             powOfSize,DCValueSize                                       ;// powOfSize=pow(2,DCValueSize)
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong        CMP             DCVal,powOfSize,LSR #1                                      ;// Compare DCVal with powOfSize/2
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong        ADDLT           DCVal,DCVal,#1
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong        SUBLT           DCVal,DCVal,powOfSize                                       ;// If Lessthan powOfSize/2 DCVal=DCVal-powOfSize+1
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                                                    ;// Else DCVal= fetchbits from bit stream
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong
1720c1bc742181ded4930842b46e9507372f0b1b963James DongCheckDCValueSize
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong        CMP             DCValueSize,#8                                              ;// If DCValueSize greater than 8 check marker bit
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong        BLE             ACDecode
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_READ8      temp1,1,T1
1790c1bc742181ded4930842b46e9507372f0b1b963James Dong        TEQ             temp1,#0                                                    ;// If Marker bit is zero Exit with an Error Message
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong        BEQ             ExitError
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong        ;// Decode AC Coefficient
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong
1860c1bc742181ded4930842b46e9507372f0b1b963James DongACDecode
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_STR           DCVal,pDCCoeff                                             ;// Store Decoded DC Coeff on Stack
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_FINI       ppBitStream,pBitOffset                                     ;// Terminating the Bit stream Macro
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong        LDR             pZigzagTable, =armVCM4P2_aClassicalZigzagScan          ;// Load Zigzag talbe address
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong        ADD             pZigzagTable, pZigzagTable, PredDir, LSL #6                ;// Modify the Zigzag table adress based on PredDir
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_STR           pZigzagTable,ppZigzagTable                                 ;// Store zigzag table on stack
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong        LDR             pVlcTableL0L1, =armVCM4P2_IntraVlcL0L1                 ;// Load Optimized VLC Table With both Last=0 and Last=1 Entries
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_STR           pVlcTableL0L1,ppVlcTableL0L1                               ;// Store Optimized VLC Table on stack
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong        LDR             pLMAXTableL0L1, =armVCM4P2_IntraL0L1LMAX               ;// Load LMAX Table
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_STR           pLMAXTableL0L1,ppLMAXTableL0L1                             ;// Store LMAX table on stack
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong        LDR             pRMAXTableL0L1, =armVCM4P2_IntraL0L1RMAX               ;// Load RMAX Table
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong        MOV             Count,#1                                                   ;// Set Start =1
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_STR           pRMAXTableL0L1,ppRMAXTableL0L1                             ;// Store RMAX Table on Stack
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_LDR           shortVideoHeader,shortVideoHeaderonStack                   ;// Load the Input Argument From Stack
2060c1bc742181ded4930842b46e9507372f0b1b963James Dong
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong        BL              armVCM4P2_DecodeVLCZigzag_AC_unsafe                    ;// Call the Unsafe Function
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_LDR           DCVal,pDCCoeff                                             ;// Get the Decoded DC Value From Stack
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong        STRH            DCVal,[pDst]                                               ;// Store the DC Value
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong        B               ExitOK
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong
2150c1bc742181ded4930842b46e9507372f0b1b963James DongExitError
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_BD_FINI       ppBitStream,pBitOffset                                     ;// Terminating the Bit Stream Macro in case of an Error
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong        MOV             Return,#OMX_Sts_Err                                        ;// Exit with an Error Message
2190c1bc742181ded4930842b46e9507372f0b1b963James DongExitOK
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong        M_END
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong        ENDIF
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong        END
225