michael@0: ; michael@0: ; Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: ; michael@0: ; Use of this source code is governed by a BSD-style license michael@0: ; that can be found in the LICENSE file in the root of the source michael@0: ; tree. An additional intellectual property rights grant can be found michael@0: ; in the file PATENTS. All contributing project authors may michael@0: ; be found in the AUTHORS file in the root of the source tree. michael@0: ; michael@0: michael@0: michael@0: EXPORT |vp8cx_pack_mb_row_tokens_armv5| michael@0: IMPORT |vp8_validate_buffer_arm| michael@0: michael@0: INCLUDE vp8_asm_enc_offsets.asm michael@0: michael@0: ARM michael@0: REQUIRE8 michael@0: PRESERVE8 michael@0: michael@0: AREA |.text|, CODE, READONLY michael@0: michael@0: michael@0: ; macro for validating write buffer position michael@0: ; needs vp8_writer in r0 michael@0: ; start shall not be in r1 michael@0: MACRO michael@0: VALIDATE_POS $start, $pos michael@0: push {r0-r3, r12, lr} ; rest of regs are preserved by subroutine call michael@0: ldr r2, [r0, #vp8_writer_buffer_end] michael@0: ldr r3, [r0, #vp8_writer_error] michael@0: mov r1, $pos michael@0: mov r0, $start michael@0: bl vp8_validate_buffer_arm michael@0: pop {r0-r3, r12, lr} michael@0: MEND michael@0: michael@0: ; r0 VP8_COMP *cpi michael@0: ; r1 vp8_writer *w michael@0: ; r2 vp8_coef_encodings michael@0: ; r3 vp8_extra_bits michael@0: ; s0 vp8_coef_tree michael@0: michael@0: |vp8cx_pack_mb_row_tokens_armv5| PROC michael@0: push {r4-r12, lr} michael@0: sub sp, sp, #24 michael@0: michael@0: ; Compute address of cpi->common.mb_rows michael@0: ldr r4, _VP8_COMP_common_ michael@0: ldr r6, _VP8_COMMON_MBrows_ michael@0: add r4, r0, r4 michael@0: michael@0: ldr r5, [r4, r6] ; load up mb_rows michael@0: michael@0: str r2, [sp, #20] ; save vp8_coef_encodings michael@0: str r5, [sp, #12] ; save mb_rows michael@0: str r3, [sp, #8] ; save vp8_extra_bits michael@0: michael@0: ldr r4, _VP8_COMP_tplist_ michael@0: add r4, r0, r4 michael@0: ldr r7, [r4, #0] ; dereference cpi->tp_list michael@0: michael@0: mov r0, r1 ; keep same as other loops michael@0: michael@0: ldr r2, [r0, #vp8_writer_lowvalue] michael@0: ldr r5, [r0, #vp8_writer_range] michael@0: ldr r3, [r0, #vp8_writer_count] michael@0: michael@0: mb_row_loop michael@0: michael@0: ldr r1, [r7, #tokenlist_start] michael@0: ldr r9, [r7, #tokenlist_stop] michael@0: str r9, [sp, #0] ; save stop for later comparison michael@0: str r7, [sp, #16] ; tokenlist address for next time michael@0: michael@0: b check_p_lt_stop michael@0: michael@0: ; actuall work gets done here! michael@0: michael@0: while_p_lt_stop michael@0: ldrb r6, [r1, #tokenextra_token] ; t michael@0: ldr r4, [sp, #20] ; vp8_coef_encodings michael@0: mov lr, #0 michael@0: add r4, r4, r6, lsl #3 ; a = vp8_coef_encodings + t michael@0: ldr r9, [r1, #tokenextra_context_tree] ; pp michael@0: michael@0: ldrb r7, [r1, #tokenextra_skip_eob_node] michael@0: michael@0: ldr r6, [r4, #vp8_token_value] ; v michael@0: ldr r8, [r4, #vp8_token_len] ; n michael@0: michael@0: ; vp8 specific skip_eob_node michael@0: cmp r7, #0 michael@0: movne lr, #2 ; i = 2 michael@0: subne r8, r8, #1 ; --n michael@0: michael@0: rsb r4, r8, #32 ; 32-n michael@0: ldr r10, [sp, #64] ; vp8_coef_tree michael@0: michael@0: ; v is kept in r12 during the token pack loop michael@0: lsl r12, r6, r4 ; r12 = v << 32 - n michael@0: michael@0: ; loop start michael@0: token_loop michael@0: ldrb r4, [r9, lr, asr #1] ; pp [i>>1] michael@0: sub r7, r5, #1 ; range-1 michael@0: michael@0: ; Decisions are made based on the bit value shifted michael@0: ; off of v, so set a flag here based on this. michael@0: ; This value is refered to as "bb" michael@0: lsls r12, r12, #1 ; bb = v >> n michael@0: mul r6, r4, r7 ; ((range-1) * pp[i>>1])) michael@0: michael@0: ; bb can only be 0 or 1. So only execute this statement michael@0: ; if bb == 1, otherwise it will act like i + 0 michael@0: addcs lr, lr, #1 ; i + bb michael@0: michael@0: mov r7, #1 michael@0: ldrsb lr, [r10, lr] ; i = vp8_coef_tree[i+bb] michael@0: add r4, r7, r6, lsr #8 ; 1 + (((range-1) * pp[i>>1]) >> 8) michael@0: michael@0: addcs r2, r2, r4 ; if (bb) lowvalue += split michael@0: subcs r4, r5, r4 ; if (bb) range = range-split michael@0: michael@0: ; Counting the leading zeros is used to normalize range. michael@0: clz r6, r4 michael@0: sub r6, r6, #24 ; shift michael@0: michael@0: ; Flag is set on the sum of count. This flag is used later michael@0: ; to determine if count >= 0 michael@0: adds r3, r3, r6 ; count += shift michael@0: lsl r5, r4, r6 ; range <<= shift michael@0: bmi token_count_lt_zero ; if(count >= 0) michael@0: michael@0: sub r6, r6, r3 ; offset = shift - count michael@0: sub r4, r6, #1 ; offset-1 michael@0: lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) michael@0: bpl token_high_bit_not_set michael@0: michael@0: ldr r4, [r0, #vp8_writer_pos] ; x michael@0: sub r4, r4, #1 ; x = w->pos-1 michael@0: b token_zero_while_start michael@0: token_zero_while_loop michael@0: mov r10, #0 michael@0: strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 michael@0: sub r4, r4, #1 ; x-- michael@0: token_zero_while_start michael@0: cmp r4, #0 michael@0: ldrge r7, [r0, #vp8_writer_buffer] michael@0: ldrb r11, [r7, r4] michael@0: cmpge r11, #0xff michael@0: beq token_zero_while_loop michael@0: michael@0: ldr r7, [r0, #vp8_writer_buffer] michael@0: ldrb r10, [r7, r4] ; w->buffer[x] michael@0: add r10, r10, #1 michael@0: strb r10, [r7, r4] ; w->buffer[x] + 1 michael@0: token_high_bit_not_set michael@0: rsb r4, r6, #24 ; 24-offset michael@0: ldr r10, [r0, #vp8_writer_buffer] michael@0: lsr r7, r2, r4 ; lowvalue >> (24-offset) michael@0: ldr r4, [r0, #vp8_writer_pos] ; w->pos michael@0: lsl r2, r2, r6 ; lowvalue <<= offset michael@0: mov r6, r3 ; shift = count michael@0: add r11, r4, #1 ; w->pos++ michael@0: bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff michael@0: str r11, [r0, #vp8_writer_pos] michael@0: sub r3, r3, #8 ; count -= 8 michael@0: michael@0: VALIDATE_POS r10, r11 ; validate_buffer at pos michael@0: michael@0: strb r7, [r10, r4] ; w->buffer[w->pos++] michael@0: michael@0: ; r10 is used earlier in the loop, but r10 is used as michael@0: ; temp variable here. So after r10 is used, reload michael@0: ; vp8_coef_tree_dcd into r10 michael@0: ldr r10, [sp, #64] ; vp8_coef_tree michael@0: michael@0: token_count_lt_zero michael@0: lsl r2, r2, r6 ; lowvalue <<= shift michael@0: michael@0: subs r8, r8, #1 ; --n michael@0: bne token_loop michael@0: michael@0: ldrb r6, [r1, #tokenextra_token] ; t michael@0: ldr r7, [sp, #8] ; vp8_extra_bits michael@0: ; Add t * sizeof (vp8_extra_bit_struct) to get the desired michael@0: ; element. Here vp8_extra_bit_struct == 16 michael@0: add r12, r7, r6, lsl #4 ; b = vp8_extra_bits + t michael@0: michael@0: ldr r4, [r12, #vp8_extra_bit_struct_base_val] michael@0: cmp r4, #0 michael@0: beq skip_extra_bits michael@0: michael@0: ; if( b->base_val) michael@0: ldr r8, [r12, #vp8_extra_bit_struct_len] ; L michael@0: ldrsh lr, [r1, #tokenextra_extra] ; e = p->Extra michael@0: cmp r8, #0 ; if( L) michael@0: beq no_extra_bits michael@0: michael@0: ldr r9, [r12, #vp8_extra_bit_struct_prob] michael@0: asr r7, lr, #1 ; v=e>>1 michael@0: michael@0: ldr r10, [r12, #vp8_extra_bit_struct_tree] michael@0: str r10, [sp, #4] ; b->tree michael@0: michael@0: rsb r4, r8, #32 michael@0: lsl r12, r7, r4 michael@0: michael@0: mov lr, #0 ; i = 0 michael@0: michael@0: extra_bits_loop michael@0: ldrb r4, [r9, lr, asr #1] ; pp[i>>1] michael@0: sub r7, r5, #1 ; range-1 michael@0: lsls r12, r12, #1 ; v >> n michael@0: mul r6, r4, r7 ; (range-1) * pp[i>>1] michael@0: addcs lr, lr, #1 ; i + bb michael@0: michael@0: mov r7, #1 michael@0: ldrsb lr, [r10, lr] ; i = b->tree[i+bb] michael@0: add r4, r7, r6, lsr #8 ; split = 1 + (((range-1) * pp[i>>1]) >> 8) michael@0: michael@0: addcs r2, r2, r4 ; if (bb) lowvalue += split michael@0: subcs r4, r5, r4 ; if (bb) range = range-split michael@0: michael@0: clz r6, r4 michael@0: sub r6, r6, #24 michael@0: michael@0: adds r3, r3, r6 ; count += shift michael@0: lsl r5, r4, r6 ; range <<= shift michael@0: bmi extra_count_lt_zero ; if(count >= 0) michael@0: michael@0: sub r6, r6, r3 ; offset= shift - count michael@0: sub r4, r6, #1 ; offset-1 michael@0: lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) michael@0: bpl extra_high_bit_not_set michael@0: michael@0: ldr r4, [r0, #vp8_writer_pos] ; x michael@0: sub r4, r4, #1 ; x = w->pos - 1 michael@0: b extra_zero_while_start michael@0: extra_zero_while_loop michael@0: mov r10, #0 michael@0: strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 michael@0: sub r4, r4, #1 ; x-- michael@0: extra_zero_while_start michael@0: cmp r4, #0 michael@0: ldrge r7, [r0, #vp8_writer_buffer] michael@0: ldrb r11, [r7, r4] michael@0: cmpge r11, #0xff michael@0: beq extra_zero_while_loop michael@0: michael@0: ldr r7, [r0, #vp8_writer_buffer] michael@0: ldrb r10, [r7, r4] michael@0: add r10, r10, #1 michael@0: strb r10, [r7, r4] michael@0: extra_high_bit_not_set michael@0: rsb r4, r6, #24 ; 24-offset michael@0: ldr r10, [r0, #vp8_writer_buffer] michael@0: lsr r7, r2, r4 ; lowvalue >> (24-offset) michael@0: ldr r4, [r0, #vp8_writer_pos] michael@0: lsl r2, r2, r6 ; lowvalue <<= offset michael@0: mov r6, r3 ; shift = count michael@0: add r11, r4, #1 ; w->pos++ michael@0: bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff michael@0: str r11, [r0, #vp8_writer_pos] michael@0: sub r3, r3, #8 ; count -= 8 michael@0: michael@0: VALIDATE_POS r10, r11 ; validate_buffer at pos michael@0: michael@0: strb r7, [r10, r4] ; w->buffer[w->pos++]=(lowvalue >> (24-offset)) michael@0: ldr r10, [sp, #4] ; b->tree michael@0: extra_count_lt_zero michael@0: lsl r2, r2, r6 michael@0: michael@0: subs r8, r8, #1 ; --n michael@0: bne extra_bits_loop ; while (n) michael@0: michael@0: no_extra_bits michael@0: ldr lr, [r1, #4] ; e = p->Extra michael@0: add r4, r5, #1 ; range + 1 michael@0: tst lr, #1 michael@0: lsr r4, r4, #1 ; split = (range + 1) >> 1 michael@0: addne r2, r2, r4 ; lowvalue += split michael@0: subne r4, r5, r4 ; range = range-split michael@0: tst r2, #0x80000000 ; lowvalue & 0x80000000 michael@0: lsl r5, r4, #1 ; range <<= 1 michael@0: beq end_high_bit_not_set michael@0: michael@0: ldr r4, [r0, #vp8_writer_pos] michael@0: mov r7, #0 michael@0: sub r4, r4, #1 michael@0: b end_zero_while_start michael@0: end_zero_while_loop michael@0: strb r7, [r6, r4] michael@0: sub r4, r4, #1 ; x-- michael@0: end_zero_while_start michael@0: cmp r4, #0 michael@0: ldrge r6, [r0, #vp8_writer_buffer] michael@0: ldrb r12, [r6, r4] michael@0: cmpge r12, #0xff michael@0: beq end_zero_while_loop michael@0: michael@0: ldr r6, [r0, #vp8_writer_buffer] michael@0: ldrb r7, [r6, r4] michael@0: add r7, r7, #1 michael@0: strb r7, [r6, r4] michael@0: end_high_bit_not_set michael@0: adds r3, r3, #1 ; ++count michael@0: lsl r2, r2, #1 ; lowvalue <<= 1 michael@0: bne end_count_zero michael@0: michael@0: ldr r4, [r0, #vp8_writer_pos] michael@0: mvn r3, #7 michael@0: ldr r7, [r0, #vp8_writer_buffer] michael@0: lsr r6, r2, #24 ; lowvalue >> 24 michael@0: add r12, r4, #1 ; w->pos++ michael@0: bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff michael@0: str r12, [r0, #vp8_writer_pos] michael@0: michael@0: VALIDATE_POS r7, r12 ; validate_buffer at pos michael@0: michael@0: strb r6, [r7, r4] michael@0: end_count_zero michael@0: skip_extra_bits michael@0: add r1, r1, #TOKENEXTRA_SZ ; ++p michael@0: check_p_lt_stop michael@0: ldr r4, [sp, #0] ; stop michael@0: cmp r1, r4 ; while( p < stop) michael@0: bcc while_p_lt_stop michael@0: michael@0: ldr r6, [sp, #12] ; mb_rows michael@0: ldr r7, [sp, #16] ; tokenlist address michael@0: subs r6, r6, #1 michael@0: add r7, r7, #TOKENLIST_SZ ; next element in the array michael@0: str r6, [sp, #12] michael@0: bne mb_row_loop michael@0: michael@0: str r2, [r0, #vp8_writer_lowvalue] michael@0: str r5, [r0, #vp8_writer_range] michael@0: str r3, [r0, #vp8_writer_count] michael@0: add sp, sp, #24 michael@0: pop {r4-r12, pc} michael@0: ENDP michael@0: michael@0: _VP8_COMP_common_ michael@0: DCD vp8_comp_common michael@0: _VP8_COMMON_MBrows_ michael@0: DCD vp8_common_mb_rows michael@0: _VP8_COMP_tplist_ michael@0: DCD vp8_comp_tplist michael@0: michael@0: END