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 |vp8_start_encode| michael@0: EXPORT |vp8_encode_bool| michael@0: EXPORT |vp8_stop_encode| michael@0: EXPORT |vp8_encode_value| 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: ; 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 BOOL_CODER *br michael@0: ; r1 unsigned char *source michael@0: ; r2 unsigned char *source_end michael@0: |vp8_start_encode| PROC michael@0: str r2, [r0, #vp8_writer_buffer_end] michael@0: mov r12, #0 michael@0: mov r3, #255 michael@0: mvn r2, #23 michael@0: str r12, [r0, #vp8_writer_lowvalue] michael@0: str r3, [r0, #vp8_writer_range] michael@0: str r2, [r0, #vp8_writer_count] michael@0: str r12, [r0, #vp8_writer_pos] michael@0: str r1, [r0, #vp8_writer_buffer] michael@0: bx lr michael@0: ENDP michael@0: michael@0: ; r0 BOOL_CODER *br michael@0: ; r1 int bit michael@0: ; r2 int probability michael@0: |vp8_encode_bool| PROC michael@0: push {r4-r10, lr} michael@0: michael@0: mov r4, r2 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: sub r7, r5, #1 ; range-1 michael@0: michael@0: cmp r1, #0 michael@0: mul r6, r4, r7 ; ((range-1) * probability) michael@0: michael@0: mov r7, #1 michael@0: add r4, r7, r6, lsr #8 ; 1 + (((range-1) * probability) >> 8) michael@0: michael@0: addne r2, r2, r4 ; if (bit) lowvalue += split michael@0: subne r4, r5, r4 ; if (bit) 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 r9, #0 michael@0: strb r9, [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 r1, [r7, r4] michael@0: cmpge r1, #0xff michael@0: beq token_zero_while_loop michael@0: michael@0: ldr r7, [r0, #vp8_writer_buffer] michael@0: ldrb r9, [r7, r4] ; w->buffer[x] michael@0: add r9, r9, #1 michael@0: strb r9, [r7, r4] ; w->buffer[x] + 1 michael@0: token_high_bit_not_set michael@0: rsb r4, r6, #24 ; 24-offset michael@0: ldr r9, [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 r1, r4, #1 ; w->pos++ michael@0: bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff michael@0: str r1, [r0, #vp8_writer_pos] michael@0: sub r3, r3, #8 ; count -= 8 michael@0: michael@0: VALIDATE_POS r9, r1 ; validate_buffer at pos michael@0: michael@0: strb r7, [r9, r4] ; w->buffer[w->pos++] michael@0: michael@0: token_count_lt_zero michael@0: lsl r2, r2, r6 ; lowvalue <<= shift 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: pop {r4-r10, pc} michael@0: ENDP michael@0: michael@0: ; r0 BOOL_CODER *br michael@0: |vp8_stop_encode| PROC michael@0: push {r4-r10, lr} 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: mov r10, #32 michael@0: michael@0: stop_encode_loop michael@0: sub r7, r5, #1 ; range-1 michael@0: michael@0: mov r4, r7, lsl #7 ; ((range-1) * 128) michael@0: michael@0: mov r7, #1 michael@0: add r4, r7, r4, lsr #8 ; 1 + (((range-1) * 128) >> 8) 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_se ; 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_se 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_se michael@0: token_zero_while_loop_se michael@0: mov r9, #0 michael@0: strb r9, [r7, r4] ; w->buffer[x] =(unsigned char)0 michael@0: sub r4, r4, #1 ; x-- michael@0: token_zero_while_start_se michael@0: cmp r4, #0 michael@0: ldrge r7, [r0, #vp8_writer_buffer] michael@0: ldrb r1, [r7, r4] michael@0: cmpge r1, #0xff michael@0: beq token_zero_while_loop_se michael@0: michael@0: ldr r7, [r0, #vp8_writer_buffer] michael@0: ldrb r9, [r7, r4] ; w->buffer[x] michael@0: add r9, r9, #1 michael@0: strb r9, [r7, r4] ; w->buffer[x] + 1 michael@0: token_high_bit_not_set_se michael@0: rsb r4, r6, #24 ; 24-offset michael@0: ldr r9, [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 r1, r4, #1 ; w->pos++ michael@0: bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff michael@0: str r1, [r0, #vp8_writer_pos] michael@0: sub r3, r3, #8 ; count -= 8 michael@0: michael@0: VALIDATE_POS r9, r1 ; validate_buffer at pos michael@0: michael@0: strb r7, [r9, r4] ; w->buffer[w->pos++] michael@0: michael@0: token_count_lt_zero_se michael@0: lsl r2, r2, r6 ; lowvalue <<= shift michael@0: michael@0: subs r10, r10, #1 michael@0: bne stop_encode_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: pop {r4-r10, pc} michael@0: michael@0: ENDP michael@0: michael@0: ; r0 BOOL_CODER *br michael@0: ; r1 int data michael@0: ; r2 int bits michael@0: |vp8_encode_value| PROC michael@0: push {r4-r12, lr} michael@0: michael@0: mov r10, r2 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: rsb r4, r10, #32 ; 32-n michael@0: michael@0: ; v is kept in r1 during the token pack loop michael@0: lsl r1, r1, r4 ; r1 = v << 32 - n michael@0: michael@0: encode_value_loop 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 r1, r1, #1 ; bit = v >> n michael@0: mov r4, r7, lsl #7 ; ((range-1) * 128) michael@0: michael@0: mov r7, #1 michael@0: add r4, r7, r4, lsr #8 ; 1 + (((range-1) * 128) >> 8) michael@0: michael@0: addcs r2, r2, r4 ; if (bit) lowvalue += split michael@0: subcs r4, r5, r4 ; if (bit) 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_ev ; 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_ev 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_ev michael@0: token_zero_while_loop_ev michael@0: mov r9, #0 michael@0: strb r9, [r7, r4] ; w->buffer[x] =(unsigned char)0 michael@0: sub r4, r4, #1 ; x-- michael@0: token_zero_while_start_ev 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_ev michael@0: michael@0: ldr r7, [r0, #vp8_writer_buffer] michael@0: ldrb r9, [r7, r4] ; w->buffer[x] michael@0: add r9, r9, #1 michael@0: strb r9, [r7, r4] ; w->buffer[x] + 1 michael@0: token_high_bit_not_set_ev michael@0: rsb r4, r6, #24 ; 24-offset michael@0: ldr r9, [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 r9, r11 ; validate_buffer at pos michael@0: michael@0: strb r7, [r9, r4] ; w->buffer[w->pos++] michael@0: michael@0: token_count_lt_zero_ev michael@0: lsl r2, r2, r6 ; lowvalue <<= shift michael@0: michael@0: subs r10, r10, #1 michael@0: bne encode_value_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: pop {r4-r12, pc} michael@0: ENDP michael@0: michael@0: END