1; 2; Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3; 4; Use of this source code is governed by a BSD-style license 5; that can be found in the LICENSE file in the root of the source 6; tree. An additional intellectual property rights grant can be found 7; in the file PATENTS. All contributing project authors may 8; be found in the AUTHORS file in the root of the source tree. 9; 10 11 12 EXPORT |vp8cx_pack_mb_row_tokens_armv5| 13 14 INCLUDE vpx_vp8_enc_asm_offsets.asm 15 16 ARM 17 REQUIRE8 18 PRESERVE8 19 20 AREA |.text|, CODE, READONLY 21 22; r0 VP8_COMP *cpi 23; r1 vp8_writer *w 24; r2 vp8_coef_encodings 25; r3 vp8_extra_bits 26; s0 vp8_coef_tree 27 28|vp8cx_pack_mb_row_tokens_armv5| PROC 29 push {r4-r11, lr} 30 sub sp, sp, #24 31 32 ; Compute address of cpi->common.mb_rows 33 ldr r4, _VP8_COMP_common_ 34 ldr r6, _VP8_COMMON_MBrows_ 35 add r4, r0, r4 36 37 ldr r5, [r4, r6] ; load up mb_rows 38 39 str r2, [sp, #20] ; save vp8_coef_encodings 40 str r5, [sp, #12] ; save mb_rows 41 str r3, [sp, #8] ; save vp8_extra_bits 42 43 ldr r4, _VP8_COMP_tplist_ 44 add r4, r0, r4 45 ldr r7, [r4, #0] ; dereference cpi->tp_list 46 47 mov r0, r1 ; keep same as other loops 48 49 ldr r2, [r0, #vp8_writer_lowvalue] 50 ldr r5, [r0, #vp8_writer_range] 51 ldr r3, [r0, #vp8_writer_count] 52 53mb_row_loop 54 55 ldr r1, [r7, #tokenlist_start] 56 ldr r9, [r7, #tokenlist_stop] 57 str r9, [sp, #0] ; save stop for later comparison 58 str r7, [sp, #16] ; tokenlist address for next time 59 60 b check_p_lt_stop 61 62 ; actuall work gets done here! 63 64while_p_lt_stop 65 ldr r6, [r1, #tokenextra_token] ; t 66 ldr r4, [sp, #20] ; vp8_coef_encodings 67 mov lr, #0 68 add r4, r4, r6, lsl #3 ; a = vp8_coef_encodings + t 69 ldr r9, [r1, #tokenextra_context_tree] ; pp 70 71 ldr r7, [r1, #tokenextra_skip_eob_node] 72 73 ldr r6, [r4, #vp8_token_value] ; v 74 ldr r8, [r4, #vp8_token_len] ; n 75 76 ; vp8 specific skip_eob_node 77 cmp r7, #0 78 movne lr, #2 ; i = 2 79 subne r8, r8, #1 ; --n 80 81 rsb r4, r8, #32 ; 32-n 82 ldr r10, [sp, #60] ; vp8_coef_tree 83 84 ; v is kept in r12 during the token pack loop 85 lsl r12, r6, r4 ; r12 = v << 32 - n 86 87; loop start 88token_loop 89 ldrb r4, [r9, lr, asr #1] ; pp [i>>1] 90 sub r7, r5, #1 ; range-1 91 92 ; Decisions are made based on the bit value shifted 93 ; off of v, so set a flag here based on this. 94 ; This value is refered to as "bb" 95 lsls r12, r12, #1 ; bb = v >> n 96 mul r4, r4, r7 ; ((range-1) * pp[i>>1])) 97 98 ; bb can only be 0 or 1. So only execute this statement 99 ; if bb == 1, otherwise it will act like i + 0 100 addcs lr, lr, #1 ; i + bb 101 102 mov r7, #1 103 ldrsb lr, [r10, lr] ; i = vp8_coef_tree[i+bb] 104 add r4, r7, r4, lsr #8 ; 1 + (((range-1) * pp[i>>1]) >> 8) 105 106 addcs r2, r2, r4 ; if (bb) lowvalue += split 107 subcs r4, r5, r4 ; if (bb) range = range-split 108 109 ; Counting the leading zeros is used to normalize range. 110 clz r6, r4 111 sub r6, r6, #24 ; shift 112 113 ; Flag is set on the sum of count. This flag is used later 114 ; to determine if count >= 0 115 adds r3, r3, r6 ; count += shift 116 lsl r5, r4, r6 ; range <<= shift 117 bmi token_count_lt_zero ; if(count >= 0) 118 119 sub r6, r6, r3 ; offset = shift - count 120 sub r4, r6, #1 ; offset-1 121 lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) 122 bpl token_high_bit_not_set 123 124 ldr r4, [r0, #vp8_writer_pos] ; x 125 sub r4, r4, #1 ; x = w->pos-1 126 b token_zero_while_start 127token_zero_while_loop 128 mov r10, #0 129 strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 130 sub r4, r4, #1 ; x-- 131token_zero_while_start 132 cmp r4, #0 133 ldrge r7, [r0, #vp8_writer_buffer] 134 ldrb r11, [r7, r4] 135 cmpge r11, #0xff 136 beq token_zero_while_loop 137 138 ldr r7, [r0, #vp8_writer_buffer] 139 ldrb r10, [r7, r4] ; w->buffer[x] 140 add r10, r10, #1 141 strb r10, [r7, r4] ; w->buffer[x] + 1 142token_high_bit_not_set 143 rsb r4, r6, #24 ; 24-offset 144 ldr r10, [r0, #vp8_writer_buffer] 145 lsr r7, r2, r4 ; lowvalue >> (24-offset) 146 ldr r4, [r0, #vp8_writer_pos] ; w->pos 147 lsl r2, r2, r6 ; lowvalue <<= offset 148 mov r6, r3 ; shift = count 149 add r11, r4, #1 ; w->pos++ 150 bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff 151 str r11, [r0, #vp8_writer_pos] 152 sub r3, r3, #8 ; count -= 8 153 strb r7, [r10, r4] ; w->buffer[w->pos++] 154 155 ; r10 is used earlier in the loop, but r10 is used as 156 ; temp variable here. So after r10 is used, reload 157 ; vp8_coef_tree_dcd into r10 158 ldr r10, [sp, #60] ; vp8_coef_tree 159 160token_count_lt_zero 161 lsl r2, r2, r6 ; lowvalue <<= shift 162 163 subs r8, r8, #1 ; --n 164 bne token_loop 165 166 ldr r6, [r1, #tokenextra_token] ; t 167 ldr r7, [sp, #8] ; vp8_extra_bits 168 ; Add t * sizeof (vp8_extra_bit_struct) to get the desired 169 ; element. Here vp8_extra_bit_struct == 20 170 add r6, r6, r6, lsl #2 ; b = vp8_extra_bits + t 171 add r12, r7, r6, lsl #2 ; b = vp8_extra_bits + t 172 173 ldr r4, [r12, #vp8_extra_bit_struct_base_val] 174 cmp r4, #0 175 beq skip_extra_bits 176 177; if( b->base_val) 178 ldr r8, [r12, #vp8_extra_bit_struct_len] ; L 179 ldr lr, [r1, #tokenextra_extra] ; e = p->Extra 180 cmp r8, #0 ; if( L) 181 beq no_extra_bits 182 183 ldr r9, [r12, #vp8_extra_bit_struct_prob] 184 asr r7, lr, #1 ; v=e>>1 185 186 ldr r10, [r12, #vp8_extra_bit_struct_tree] 187 str r10, [sp, #4] ; b->tree 188 189 rsb r4, r8, #32 190 lsl r12, r7, r4 191 192 mov lr, #0 ; i = 0 193 194extra_bits_loop 195 ldrb r4, [r9, lr, asr #1] ; pp[i>>1] 196 sub r7, r5, #1 ; range-1 197 lsls r12, r12, #1 ; v >> n 198 mul r4, r4, r7 ; (range-1) * pp[i>>1] 199 addcs lr, lr, #1 ; i + bb 200 201 mov r7, #1 202 ldrsb lr, [r10, lr] ; i = b->tree[i+bb] 203 add r4, r7, r4, lsr #8 ; split = 1 + (((range-1) * pp[i>>1]) >> 8) 204 205 addcs r2, r2, r4 ; if (bb) lowvalue += split 206 subcs r4, r5, r4 ; if (bb) range = range-split 207 208 clz r6, r4 209 sub r6, r6, #24 210 211 adds r3, r3, r6 ; count += shift 212 lsl r5, r4, r6 ; range <<= shift 213 bmi extra_count_lt_zero ; if(count >= 0) 214 215 sub r6, r6, r3 ; offset= shift - count 216 sub r4, r6, #1 ; offset-1 217 lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) 218 bpl extra_high_bit_not_set 219 220 ldr r4, [r0, #vp8_writer_pos] ; x 221 sub r4, r4, #1 ; x = w->pos - 1 222 b extra_zero_while_start 223extra_zero_while_loop 224 mov r10, #0 225 strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 226 sub r4, r4, #1 ; x-- 227extra_zero_while_start 228 cmp r4, #0 229 ldrge r7, [r0, #vp8_writer_buffer] 230 ldrb r11, [r7, r4] 231 cmpge r11, #0xff 232 beq extra_zero_while_loop 233 234 ldr r7, [r0, #vp8_writer_buffer] 235 ldrb r10, [r7, r4] 236 add r10, r10, #1 237 strb r10, [r7, r4] 238extra_high_bit_not_set 239 rsb r4, r6, #24 ; 24-offset 240 ldr r10, [r0, #vp8_writer_buffer] 241 lsr r7, r2, r4 ; lowvalue >> (24-offset) 242 ldr r4, [r0, #vp8_writer_pos] 243 lsl r2, r2, r6 ; lowvalue <<= offset 244 mov r6, r3 ; shift = count 245 add r11, r4, #1 ; w->pos++ 246 bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff 247 str r11, [r0, #vp8_writer_pos] 248 sub r3, r3, #8 ; count -= 8 249 strb r7, [r10, r4] ; w->buffer[w->pos++]=(lowvalue >> (24-offset)) 250 ldr r10, [sp, #4] ; b->tree 251extra_count_lt_zero 252 lsl r2, r2, r6 253 254 subs r8, r8, #1 ; --n 255 bne extra_bits_loop ; while (n) 256 257no_extra_bits 258 ldr lr, [r1, #4] ; e = p->Extra 259 add r4, r5, #1 ; range + 1 260 tst lr, #1 261 lsr r4, r4, #1 ; split = (range + 1) >> 1 262 addne r2, r2, r4 ; lowvalue += split 263 subne r4, r5, r4 ; range = range-split 264 tst r2, #0x80000000 ; lowvalue & 0x80000000 265 lsl r5, r4, #1 ; range <<= 1 266 beq end_high_bit_not_set 267 268 ldr r4, [r0, #vp8_writer_pos] 269 mov r7, #0 270 sub r4, r4, #1 271 b end_zero_while_start 272end_zero_while_loop 273 strb r7, [r6, r4] 274 sub r4, r4, #1 ; x-- 275end_zero_while_start 276 cmp r4, #0 277 ldrge r6, [r0, #vp8_writer_buffer] 278 ldrb r12, [r6, r4] 279 cmpge r12, #0xff 280 beq end_zero_while_loop 281 282 ldr r6, [r0, #vp8_writer_buffer] 283 ldrb r7, [r6, r4] 284 add r7, r7, #1 285 strb r7, [r6, r4] 286end_high_bit_not_set 287 adds r3, r3, #1 ; ++count 288 lsl r2, r2, #1 ; lowvalue <<= 1 289 bne end_count_zero 290 291 ldr r4, [r0, #vp8_writer_pos] 292 mvn r3, #7 293 ldr r7, [r0, #vp8_writer_buffer] 294 lsr r6, r2, #24 ; lowvalue >> 24 295 add r12, r4, #1 ; w->pos++ 296 bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff 297 str r12, [r0, #0x10] 298 strb r6, [r7, r4] 299end_count_zero 300skip_extra_bits 301 add r1, r1, #TOKENEXTRA_SZ ; ++p 302check_p_lt_stop 303 ldr r4, [sp, #0] ; stop 304 cmp r1, r4 ; while( p < stop) 305 bcc while_p_lt_stop 306 307 ldr r6, [sp, #12] ; mb_rows 308 ldr r7, [sp, #16] ; tokenlist address 309 subs r6, r6, #1 310 add r7, r7, #TOKENLIST_SZ ; next element in the array 311 str r6, [sp, #12] 312 bne mb_row_loop 313 314 str r2, [r0, #vp8_writer_lowvalue] 315 str r5, [r0, #vp8_writer_range] 316 str r3, [r0, #vp8_writer_count] 317 add sp, sp, #24 318 pop {r4-r11, pc} 319 ENDP 320 321_VP8_COMP_common_ 322 DCD vp8_comp_common 323_VP8_COMMON_MBrows_ 324 DCD vp8_common_mb_rows 325_VP8_COMP_tplist_ 326 DCD vp8_comp_tplist 327 328 END 329