1bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 2bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 3bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// File Name: armCOMM_BitDec_s.h 4bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// OpenMAX DL: v1.0.2 5bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// Revision: 12290 6bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// Date: Wednesday, April 9, 2008 7bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 8bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved. 9bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 10bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 11bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 12bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// OpenMAX optimized bitstream decode module 13bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 14bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// You must include armCOMM_s.h before including this file 15bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 16bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// This module provides macros to perform assembly optimized fixed and 17bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// variable length decoding from a read-only bitstream. The variable 18bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// length decode modules take as input a pointer to a table of 16-bit 19bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// entries of the following format. 20bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 21bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// VLD Table Entry format 22bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 23bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 24bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// +------------------------------------------------+ 25bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// | Len | Symbol | 1 | 26bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// +------------------------------------------------+ 27bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// | Offset | 0 | 28bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// +------------------------------------------------+ 29bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 30bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// If the table entry is a leaf entry then bit 0 set: 31bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// Len = Number of bits overread (0 to 7) 32bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// Symbol = Symbol payload (unsigned 12 bits) 33bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 34bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// If the table entry is an internal node then bit 0 is clear: 35bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// Offset = Number of (16-bit) half words from the table 36bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// start to the next table node 37bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 38bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// The table is accessed by successive lookup up on the 39bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// next Step bits of the input bitstream until a leaf node 40bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// is obtained. The Step sizes are supplied to the VLD macro. 41bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 42bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// USAGE: 43bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 44bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// To use any of the macros in this package, first call: 45bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 46bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_INIT ppBitStream, pBitOffset, pBitStream, RBitBuffer, RBitCount, Tmp 47bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 48bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// This caches the current bitstream position and next available 49bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// bits in registers pBitStream, RBitBuffer, RBitCount. These registers 50bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// are reserved for use by the bitstream decode package until you 51bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// call M_BD_FINI. 52bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 53bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// Next call the following macro(s) as many times as you need: 54bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 55bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_LOOK8 - Look ahead constant 1<=N<=8 bits into the bitstream 56bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_LOOK16 - Look ahead constant 1<=N<=16 bits into the bitstream 57bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_READ8 - Read constant 1<=N<=8 bits from the bitstream 58bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_READ16 - Read constant 1<=N<=16 bits from the bitstream 59bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_VREAD8 - Read variable 1<=N<=8 bits from the bitstream 60bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_VREAD16 - Read variable 1<=N<=16 bits from the bitstream 61bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_VLD - Perform variable length decode using lookup table 62bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 63bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// Finally call the macro: 64bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 65bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// M_BD_FINI ppBitStream, pBitOffset 66bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 67bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// This writes the bitstream state back to memory. 68bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 69bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// The three bitstream cache register names are assigned to the following global 70bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// variables: 71bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 72bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 73bebc99d6fa433c04139294a5057f8439d772dbd9James Dong GBLS pBitStream ;// Register name for pBitStream 74bebc99d6fa433c04139294a5057f8439d772dbd9James Dong GBLS BitBuffer ;// Register name for BitBuffer 75bebc99d6fa433c04139294a5057f8439d772dbd9James Dong GBLS BitCount ;// Register name for BitCount 76bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 77bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 78bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// These register variables must have a certain defined state on entry to every bitstream 79bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// macro (except M_BD_INIT) and on exit from every bitstream macro (except M_BD_FINI). 80bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// The state may depend on implementation. 81bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 82bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// For the default (ARM11) implementation the following hold: 83bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// pBitStream - points to the first byte not held in the BitBuffer 84bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// BitBuffer - is a cache of (4 bytes) 32 bits, bit 31 the first bit 85bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// BitCount - is offset (from the top bit) to the next unused bitstream bit 86bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 0<=BitCount<=15 (so BitBuffer holds at least 17 unused bits) 87bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 88bebc99d6fa433c04139294a5057f8439d772dbd9James Dong;// 89bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 90bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Bitstream Decode initialise 91bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 92bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Initialises the bitstream decode global registers from 93bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// bitstream pointers. This macro is split into 3 parts to enable 94bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// scheduling. 95bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 96bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 97bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 98bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $ppBitStream - pointer to pointer to the next bitstream byte 99bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitOffset - pointer to the number of bits used in the current byte (0..7) 100bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $RBitStream - register to use for pBitStream (can be $ppBitStream) 101bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $RBitBuffer - register to use for BitBuffer 102bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $RBitCount - register to use for BitCount (can be $pBitOffset) 103bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 104bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 105bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 106bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1,$T2,$T3 - registers that must be preserved between calls to 107bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// M_BD_INIT1 and M_BD_INIT2 108bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 109bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 110bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 111bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 112bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 113bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_INIT0 $ppBitStream, $pBitOffset, $RBitStream, $RBitBuffer, $RBitCount 114bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 115bebc99d6fa433c04139294a5057f8439d772dbd9James DongpBitStream SETS "$RBitStream" 116bebc99d6fa433c04139294a5057f8439d772dbd9James DongBitBuffer SETS "$RBitBuffer" 117bebc99d6fa433c04139294a5057f8439d772dbd9James DongBitCount SETS "$RBitCount" 118bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 119bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// load inputs 120bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDR $pBitStream, [$ppBitStream] 121bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDR $BitCount, [$pBitOffset] 122bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 123bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 124bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 125bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_INIT1 $T1, $T2, $T3 126bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRB $T2, [$pBitStream, #2] 127bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRB $T1, [$pBitStream, #1] 128bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRB $BitBuffer, [$pBitStream], #3 129bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, #8 130bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 131bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 132bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 133bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_INIT2 $T1, $T2, $T3 134bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORR $T2, $T2, $T1, LSL #8 135bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORR $BitBuffer, $T2, $BitBuffer, LSL #16 136bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 137bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 138bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 139bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Look ahead fixed 1<=N<=8 bits without consuming any bits 140bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// The next bits will be placed at bit 31..24 of destination register 141bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 142bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 143bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 144bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits to look 145bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 146bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 147bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 148bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 149bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 150bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 151bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the next N bits of the bitstream 152bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 153bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 154bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 155bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 156bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 157bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 158bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_LOOK8 $Symbol, $N 159bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT ($N>=1):LAND:($N<=8) 160bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $BitBuffer, LSL $BitCount 161bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 162bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 163bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 164bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Look ahead fixed 1<=N<=16 bits without consuming any bits 165bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// The next bits will be placed at bit 31..16 of destination register 166bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 167bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 168bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 169bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits to look 170bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 171bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 172bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 173bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 174bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 175bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 176bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the next N bits of the bitstream 177bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 178bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 179bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 180bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 181bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 182bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 183bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_LOOK16 $Symbol, $N, $T1 184bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT ($N >= 1):LAND:($N <= 16) 185bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $BitBuffer, LSL $BitCount 186bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 187bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 188bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 189bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Skips fixed 1<=N<=8 bits from the bitstream, advancing the bitstream pointer 190bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 191bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 192bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 193bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits 194bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 195bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 196bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 197bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 198bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 199bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 200bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 201bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 202bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 203bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 204bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 205bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 206bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_SKIP8 $N, $T1 207bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT ($N>=1):LAND:($N<=8) 208bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #(8-$N) 209bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 210bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 211bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 212bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 213bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 214bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 215bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 216bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Read fixed 1<=N<=8 bits from the bitstream, advancing the bitstream pointer 217bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 218bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 219bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 220bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits to read 221bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 222bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 223bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 224bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 225bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 226bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 227bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the next N bits of the bitstream 228bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 229bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 230bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 231bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 232bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 233bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 234bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_READ8 $Symbol, $N, $T1 235bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT ($N>=1):LAND:($N<=8) 236bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOVS $Symbol, $BitBuffer, LSL $BitCount 237bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #(8-$N) 238bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 239bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 240bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $Symbol, LSR #(32-$N) 241bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 242bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 243bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 244bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 245bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Read fixed 1<=N<=16 bits from the bitstream, advancing the bitstream pointer 246bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 247bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 248bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 249bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits to read 250bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 251bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 252bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 253bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 254bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 255bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 256bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the next N bits of the bitstream 257bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 258bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 259bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 260bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 261bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 262bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 263bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 264bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_READ16 $Symbol, $N, $T1, $T2 265bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT ($N>=1):LAND:($N<=16) 266bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT $Symbol<>$T1 267bebc99d6fa433c04139294a5057f8439d772dbd9James Dong IF ($N<=8) 268bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_READ8 $Symbol, $N, $T1 269bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ELSE 270bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// N>8 so we will be able to refill at least one byte 271bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRB $T1, [$pBitStream], #1 272bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOVS $Symbol, $BitBuffer, LSL $BitCount 273bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORR $BitBuffer, $T1, $BitBuffer, LSL #8 274bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #(16-$N) 275bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 276bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $Symbol, LSR #(32-$N) 277bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 278bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 279bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ENDIF 280bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 281bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 282bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 283bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Skip variable 1<=N<=8 bits from the bitstream, advancing the bitstream pointer. 284bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 285bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 286bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 287bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits. 1<=N<=8 288bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 289bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 290bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 291bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 292bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 293bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 294bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 295bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 296bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 297bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 298bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 299bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 300bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 301bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_VSKIP8 $N, $T1 302bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, $N 303bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #8 304bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 305bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 306bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 307bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 308bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 309bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 310bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Skip variable 1<=N<=16 bits from the bitstream, advancing the bitstream pointer. 311bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 312bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 313bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 314bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits. 1<=N<=16 315bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 316bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 317bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 318bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 319bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 320bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 321bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 322bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 323bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 324bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 325bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 326bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 327bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 328bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_VSKIP16 $N, $T1, $T2 329bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, $N 330bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #8 331bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 332bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 333bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBCSS $BitCount, $BitCount, #8 334bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 335bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 336bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 337bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 338bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 339bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 340bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Read variable 1<=N<=8 bits from the bitstream, advancing the bitstream pointer. 341bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 342bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 343bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 344bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits to read. 1<=N<=8 345bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 346bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 347bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 348bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 349bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 350bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 351bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the next N bits of the bitstream 352bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 353bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 354bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 355bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 356bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 357bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 358bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 359bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_VREAD8 $Symbol, $N, $T1, $T2 360bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $BitBuffer, LSL $BitCount 361bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, $N 362bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #8 363bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 364bebc99d6fa433c04139294a5057f8439d772dbd9James Dong RSB $T2, $N, #32 365bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 366bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $Symbol, LSR $T2 367bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 368bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 369bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 370bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 371bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 372bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Read variable 1<=N<=16 bits from the bitstream, advancing the bitstream pointer. 373bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 374bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 375bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 376bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $N - number of bits to read. 1<=N<=16 377bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 378bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 379bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 380bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 381bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 382bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 383bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the next N bits of the bitstream 384bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 385bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 386bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 387bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 388bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 389bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 390bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 391bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_VREAD16 $Symbol, $N, $T1, $T2 392bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $BitBuffer, LSL $BitCount 393bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, $N 394bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #8 395bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 396bebc99d6fa433c04139294a5057f8439d772dbd9James Dong RSB $T2, $N, #32 397bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 398bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBCSS $BitCount, $BitCount, #8 399bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 400bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 401bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $Symbol, LSR $T2 402bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 403bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 404bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 405bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 406bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 407bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Decode a code of the form 0000...001 where there 408bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// are N zeros before the 1 and N<=15 (code length<=16) 409bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 410bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 411bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 412bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 413bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 414bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 415bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 416bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 417bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 418bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the number of zeros before the next 1 419bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// >=16 is an illegal code 420bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 421bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 422bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 423bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 424bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 425bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 426bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 427bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_CLZ16 $Symbol, $T1, $T2 428bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOVS $Symbol, $BitBuffer, LSL $BitCount 429bebc99d6fa433c04139294a5057f8439d772dbd9James Dong CLZ $Symbol, $Symbol 430bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, $Symbol 431bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #7 ;// length is Symbol+1 432bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 433bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 434bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBCSS $BitCount, $BitCount, #8 435bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 436bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 437bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 438bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 439bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 440bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 441bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Decode a code of the form 1111...110 where there 442bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// are N ones before the 0 and N<=15 (code length<=16) 443bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 444bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 445bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 446bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 447bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 448bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 449bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 450bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 451bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 452bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - the number of zeros before the next 1 453bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// >=16 is an illegal code 454bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 455bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 456bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 457bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 458bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 459bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 460bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 461bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_CLO16 $Symbol, $T1, $T2 462bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $Symbol, $BitBuffer, LSL $BitCount 463bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MVN $Symbol, $Symbol 464bebc99d6fa433c04139294a5057f8439d772dbd9James Dong CLZ $Symbol, $Symbol 465bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, $Symbol 466bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #7 ;// length is Symbol+1 467bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 468bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 469bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBCSS $BitCount, $BitCount, #8 470bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 471bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 472bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 473bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 474bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 475bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 476bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 477bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Variable Length Decode module 478bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 479bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Decodes one VLD Symbol from a bitstream and refill the bitstream 480bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// buffer. 481bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 482bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 483bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 484bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pVLDTable - pointer to VLD decode table of 16-bit entries. 485bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// The format is described above at the start of 486bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// this file. 487bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $S0 - The number of bits to look up for the first step 488bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 1<=$S0<=8 489bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $S1 - The number of bits to look up for each subsequent 490bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// step 1<=$S1<=$S0. 491bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 492bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 493bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 494bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 495bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 496bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 497bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 498bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Symbol - decoded VLD symbol value 499bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 500bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T2 - corrupted temp/scratch register 501bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 502bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 503bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 504bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 505bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 506bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_VLD $Symbol, $T1, $T2, $pVLDTable, $S0, $S1 507bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT (1<=$S0):LAND:($S0<=8) 508bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ASSERT (1<=$S1):LAND:($S1<=$S0) 509bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 510bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Note 0<=BitCount<=15 on entry and exit 511bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 512bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOVS $T1, $BitBuffer, LSL $BitCount ;// left align next bits 513bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOVS $Symbol, #(2<<$S0)-2 ;// create mask 514bebc99d6fa433c04139294a5057f8439d772dbd9James Dong AND $Symbol, $Symbol, $T1, LSR #(31-$S0) ;// 2*(next $S0 bits) 515bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #8 ;// CS if buffer can be filled 516bebc99d6fa433c04139294a5057f8439d772dbd9James Dong01 517bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRCSB $T1, [$pBitStream], #1 ;// load refill byte 518bebc99d6fa433c04139294a5057f8439d772dbd9James Dong LDRH $Symbol, [$pVLDTable, $Symbol] ;// load table entry 519bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADDCC $BitCount, $BitCount, #8 ;// refill not possible 520bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $BitCount, $BitCount, #$S0 ;// assume $S0 bits used 521bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ORRCS $BitBuffer, $T1, $BitBuffer, LSL #8 ;// merge in refill byte 522bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOVS $T1, $Symbol, LSR #1 ;// CS=leaf entry 523bebc99d6fa433c04139294a5057f8439d772dbd9James Dong BCS %FT02 524bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 525bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOVS $T1, $BitBuffer, LSL $BitCount ;// left align next bit 526bebc99d6fa433c04139294a5057f8439d772dbd9James Dong IF (2*$S0-$S1<=8) 527bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Can combine refill check and -S0+S1 and keep $BitCount<=15 528bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #8+($S0-$S1) 529bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ELSE 530bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Separate refill check and -S0+S1 offset 531bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUBS $BitCount, $BitCount, #8 532bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUB $BitCount, $BitCount, #($S0-$S1) 533bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ENDIF 534bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $Symbol, $Symbol, $T1, LSR #(31-$S1) ;// add 2*(next $S1 bits) to 535bebc99d6fa433c04139294a5057f8439d772dbd9James Dong BIC $Symbol, $Symbol, #1 ;// table offset 536bebc99d6fa433c04139294a5057f8439d772dbd9James Dong B %BT01 ;// load next table entry 537bebc99d6fa433c04139294a5057f8439d772dbd9James Dong02 538bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// BitCount range now depend on the route here 539bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// if (first step) S0 <= BitCount <= 7+S0 <=15 540bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// else if (2*S0-S1<=8) S0 <= BitCount <= 7+(2*S0-S1) <=15 541bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// else S1 <= BitCount <= 7+S1 <=15 542bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 543bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUB $BitCount, $BitCount, $Symbol, LSR#13 544bebc99d6fa433c04139294a5057f8439d772dbd9James Dong BIC $Symbol, $T1, #0xF000 545bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 546bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 547bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 548bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Add an offset number of bits 549bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 550bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Outputs destination byte and bit index values which corresponds to an offset number of bits 551bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// from the current location. This is used to compare bitstream positions using. M_BD_CMP. 552bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 553bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 554bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 555bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $Offset - Offset to be added in bits. 556bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 557bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 558bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 559bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 560bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 561bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 562bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $ByteIndex - Destination pBitStream pointer after adding the Offset. 563bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// This value will be 4 byte ahead and needs to subtract by 4 to get exact 564bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// pointer (as in M_BD_FINI). But for using with M_BD_CMP subtract is not needed. 565bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitIndex - Destination BitCount after the addition of Offset number of bits 566bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 567bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 568bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_ADD $ByteIndex, $BitIndex, $Offset 569bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 570bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// ($ByteIndex,$BitIndex) = Current position + $Offset bits 571bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $Offset, $Offset, $BitCount 572bebc99d6fa433c04139294a5057f8439d772dbd9James Dong AND $BitIndex, $Offset, #7 573bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $ByteIndex, $pBitStream, $Offset, ASR #3 574bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 575bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 576bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Move bitstream pointers to the location given 577bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 578bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Outputs destination byte and bit index values which corresponds to 579bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// the current location given (calculated using M_BD_ADD). 580bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 581bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 582bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 583bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 584bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 585bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 586bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $ByteIndex - Destination pBitStream pointer after move. 587bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// This value will be 4 byte ahead and needs to subtract by 4 to get exact 588bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// pointer (as in M_BD_FINI). 589bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitIndex - Destination BitCount after the move 590bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 591bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 592bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 593bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 594bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// } See description above. 595bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 596bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 597bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 598bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_MOV $ByteIndex, $BitIndex 599bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 600bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// ($pBitStream, $Offset) = ($ByteIndex,$BitIndex) 601bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $BitCount, $BitIndex 602bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MOV $pBitStream, $ByteIndex 603bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 604bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 605bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Bitstream Compare 606bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 607bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Compares bitstream position with that of a destination position. Destination position 608bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// is held in two input registers which are calculated using M_BD_ADD macro 609bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 610bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 611bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 612bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $ByteIndex - Destination pBitStream pointer, (4 byte ahead as described in M_BD_ADD) 613bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitIndex - Destination BitCount 614bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 615bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 616bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 617bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 618bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 619bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 620bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// FLAGS - GE if destination is reached, LT = is destination is ahead 621bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $T1 - corrupted temp/scratch register 622bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 623bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 624bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_CMP $ByteIndex, $BitIndex, $T1 625bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 626bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Return flags set by (current positon)-($ByteIndex,$BitIndex) 627bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// so GE means that we have reached the indicated position 628bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 629bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $T1, $pBitStream, $BitCount, LSR #3 630bebc99d6fa433c04139294a5057f8439d772dbd9James Dong CMP $T1, $ByteIndex 631bebc99d6fa433c04139294a5057f8439d772dbd9James Dong AND $T1, $BitCount, #7 632bebc99d6fa433c04139294a5057f8439d772dbd9James Dong CMPEQ $T1, $BitIndex 633bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 634bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 635bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 636bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Bitstream Decode finalise 637bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 638bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Writes back the bitstream state to the bitstream pointers 639bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 640bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Input Registers: 641bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 642bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 643bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } See description above. 644bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 645bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 646bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Output Registers: 647bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 648bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $ppBitStream - pointer to pointer to the next bitstream byte 649bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitOffset - pointer to the number of bits used in the current byte (0..7) 650bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $pBitStream \ 651bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitBuffer } these register are corrupted 652bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// $BitCount / 653bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// 654bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MACRO 655bebc99d6fa433c04139294a5057f8439d772dbd9James Dong M_BD_FINI $ppBitStream, $pBitOffset 656bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 657bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Advance pointer by the number of free bits in the buffer 658bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ADD $pBitStream, $pBitStream, $BitCount, LSR#3 659bebc99d6fa433c04139294a5057f8439d772dbd9James Dong AND $BitCount, $BitCount, #7 660bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 661bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Now move back 32 bits to reach the first usued bit 662bebc99d6fa433c04139294a5057f8439d772dbd9James Dong SUB $pBitStream, $pBitStream, #4 663bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 664bebc99d6fa433c04139294a5057f8439d772dbd9James Dong ;// Store out bitstream state 665bebc99d6fa433c04139294a5057f8439d772dbd9James Dong STR $BitCount, [$pBitOffset] 666bebc99d6fa433c04139294a5057f8439d772dbd9James Dong STR $pBitStream, [$ppBitStream] 667bebc99d6fa433c04139294a5057f8439d772dbd9James Dong MEND 668bebc99d6fa433c04139294a5057f8439d772dbd9James Dong 669bebc99d6fa433c04139294a5057f8439d772dbd9James Dong END 670bebc99d6fa433c04139294a5057f8439d772dbd9James Dong