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_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_writer *w 23 ; r1 const TOKENEXTRA *p 24 ; r2 int xcount 25 ; r3 vp8_coef_encodings 26 ; s0 vp8_extra_bits 27 ; s1 vp8_coef_tree 28 |vp8cx_pack_tokens_armv5| PROC 29 push {r4-r11, lr} 30 31 ; Add size of xcount * sizeof (TOKENEXTRA) to get stop 32 ; sizeof (TOKENEXTRA) is 20 33 add r2, r2, r2, lsl #2 ; xcount 34 sub sp, sp, #12 35 add r2, r1, r2, lsl #2 ; stop = p + xcount 36 str r2, [sp, #0] 37 str r3, [sp, #8] ; save vp8_coef_encodings 38 ldr r2, [r0, #vp8_writer_lowvalue] 39 ldr r5, [r0, #vp8_writer_range] 40 ldr r3, [r0, #vp8_writer_count] 41 b check_p_lt_stop 42 43 while_p_lt_stop 44 ldr r6, [r1, #tokenextra_token] ; t 45 ldr r4, [sp, #8] ; vp8_coef_encodings 46 mov lr, #0 47 add r4, r4, r6, lsl #3 ; a = vp8_coef_encodings + t 48 ldr r9, [r1, #tokenextra_context_tree] ; pp 49 50 ldr r7, [r1, #tokenextra_skip_eob_node] 51 52 ldr r6, [r4, #vp8_token_value] ; v 53 ldr r8, [r4, #vp8_token_len] ; n 54 55 ; vp8 specific skip_eob_node 56 cmp r7, #0 57 movne lr, #2 ; i = 2 58 subne r8, r8, #1 ; --n 59 60 rsb r4, r8, #32 ; 32-n 61 ldr r10, [sp, #52] ; vp8_coef_tree 62 63 ; v is kept in r12 during the token pack loop 64 lsl r12, r6, r4 ; r12 = v << 32 - n 65 66 ; loop start 67 token_loop 68 ldrb r4, [r9, lr, asr #1] ; pp [i>>1] 69 sub r7, r5, #1 ; range-1 70 71 ; Decisions are made based on the bit value shifted 72 ; off of v, so set a flag here based on this. 73 ; This value is refered to as "bb" 74 lsls r12, r12, #1 ; bb = v >> n 75 mul r4, r4, r7 ; ((range-1) * pp[i>>1])) 76 77 ; bb can only be 0 or 1. So only execute this statement 78 ; if bb == 1, otherwise it will act like i + 0 79 addcs lr, lr, #1 ; i + bb 80 81 mov r7, #1 82 ldrsb lr, [r10, lr] ; i = vp8_coef_tree[i+bb] 83 add r4, r7, r4, lsr #8 ; 1 + (((range-1) * pp[i>>1]) >> 8) 84 85 addcs r2, r2, r4 ; if (bb) lowvalue += split 86 subcs r4, r5, r4 ; if (bb) range = range-split 87 88 ; Counting the leading zeros is used to normalize range. 89 clz r6, r4 90 sub r6, r6, #24 ; shift 91 92 ; Flag is set on the sum of count. This flag is used later 93 ; to determine if count >= 0 94 adds r3, r3, r6 ; count += shift 95 lsl r5, r4, r6 ; range <<= shift 96 bmi token_count_lt_zero ; if(count >= 0) 97 98 sub r6, r6, r3 ; offset = shift - count 99 sub r4, r6, #1 ; offset-1 100 lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) 101 bpl token_high_bit_not_set 102 103 ldr r4, [r0, #vp8_writer_pos] ; x 104 sub r4, r4, #1 ; x = w->pos-1 105 b token_zero_while_start 106 token_zero_while_loop 107 mov r10, #0 108 strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 109 sub r4, r4, #1 ; x-- 110 token_zero_while_start 111 cmp r4, #0 112 ldrge r7, [r0, #vp8_writer_buffer] 113 ldrb r11, [r7, r4] 114 cmpge r11, #0xff 115 beq token_zero_while_loop 116 117 ldr r7, [r0, #vp8_writer_buffer] 118 ldrb r10, [r7, r4] ; w->buffer[x] 119 add r10, r10, #1 120 strb r10, [r7, r4] ; w->buffer[x] + 1 121 token_high_bit_not_set 122 rsb r4, r6, #24 ; 24-offset 123 ldr r10, [r0, #vp8_writer_buffer] 124 lsr r7, r2, r4 ; lowvalue >> (24-offset) 125 ldr r4, [r0, #vp8_writer_pos] ; w->pos 126 lsl r2, r2, r6 ; lowvalue <<= offset 127 mov r6, r3 ; shift = count 128 add r11, r4, #1 ; w->pos++ 129 bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff 130 str r11, [r0, #vp8_writer_pos] 131 sub r3, r3, #8 ; count -= 8 132 strb r7, [r10, r4] ; w->buffer[w->pos++] 133 134 ; r10 is used earlier in the loop, but r10 is used as 135 ; temp variable here. So after r10 is used, reload 136 ; vp8_coef_tree_dcd into r10 137 ldr r10, [sp, #52] ; vp8_coef_tree 138 139 token_count_lt_zero 140 lsl r2, r2, r6 ; lowvalue <<= shift 141 142 subs r8, r8, #1 ; --n 143 bne token_loop 144 145 ldr r6, [r1, #tokenextra_token] ; t 146 ldr r7, [sp, #48] ; vp8_extra_bits 147 ; Add t * sizeof (vp8_extra_bit_struct) to get the desired 148 ; element. Here vp8_extra_bit_struct == 20 149 add r6, r6, r6, lsl #2 ; b = vp8_extra_bits + t 150 add r12, r7, r6, lsl #2 ; b = vp8_extra_bits + t 151 152 ldr r4, [r12, #vp8_extra_bit_struct_base_val] 153 cmp r4, #0 154 beq skip_extra_bits 155 156 ; if( b->base_val) 157 ldr r8, [r12, #vp8_extra_bit_struct_len] ; L 158 ldr lr, [r1, #tokenextra_extra] ; e = p->Extra 159 cmp r8, #0 ; if( L) 160 beq no_extra_bits 161 162 ldr r9, [r12, #vp8_extra_bit_struct_prob] 163 asr r7, lr, #1 ; v=e>>1 164 165 ldr r10, [r12, #vp8_extra_bit_struct_tree] 166 str r10, [sp, #4] ; b->tree 167 168 rsb r4, r8, #32 169 lsl r12, r7, r4 170 171 mov lr, #0 ; i = 0 172 173 extra_bits_loop 174 ldrb r4, [r9, lr, asr #1] ; pp[i>>1] 175 sub r7, r5, #1 ; range-1 176 lsls r12, r12, #1 ; v >> n 177 mul r4, r4, r7 ; (range-1) * pp[i>>1] 178 addcs lr, lr, #1 ; i + bb 179 180 mov r7, #1 181 ldrsb lr, [r10, lr] ; i = b->tree[i+bb] 182 add r4, r7, r4, lsr #8 ; split = 1 + (((range-1) * pp[i>>1]) >> 8) 183 184 addcs r2, r2, r4 ; if (bb) lowvalue += split 185 subcs r4, r5, r4 ; if (bb) range = range-split 186 187 clz r6, r4 188 sub r6, r6, #24 189 190 adds r3, r3, r6 ; count += shift 191 lsl r5, r4, r6 ; range <<= shift 192 bmi extra_count_lt_zero ; if(count >= 0) 193 194 sub r6, r6, r3 ; offset= shift - count 195 sub r4, r6, #1 ; offset-1 196 lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) 197 bpl extra_high_bit_not_set 198 199 ldr r4, [r0, #vp8_writer_pos] ; x 200 sub r4, r4, #1 ; x = w->pos - 1 201 b extra_zero_while_start 202 extra_zero_while_loop 203 mov r10, #0 204 strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 205 sub r4, r4, #1 ; x-- 206 extra_zero_while_start 207 cmp r4, #0 208 ldrge r7, [r0, #vp8_writer_buffer] 209 ldrb r11, [r7, r4] 210 cmpge r11, #0xff 211 beq extra_zero_while_loop 212 213 ldr r7, [r0, #vp8_writer_buffer] 214 ldrb r10, [r7, r4] 215 add r10, r10, #1 216 strb r10, [r7, r4] 217 extra_high_bit_not_set 218 rsb r4, r6, #24 ; 24-offset 219 ldr r10, [r0, #vp8_writer_buffer] 220 lsr r7, r2, r4 ; lowvalue >> (24-offset) 221 ldr r4, [r0, #vp8_writer_pos] 222 lsl r2, r2, r6 ; lowvalue <<= offset 223 mov r6, r3 ; shift = count 224 add r11, r4, #1 ; w->pos++ 225 bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff 226 str r11, [r0, #vp8_writer_pos] 227 sub r3, r3, #8 ; count -= 8 228 strb r7, [r10, r4] ; w->buffer[w->pos++]=(lowvalue >> (24-offset)) 229 ldr r10, [sp, #4] ; b->tree 230 extra_count_lt_zero 231 lsl r2, r2, r6 232 233 subs r8, r8, #1 ; --n 234 bne extra_bits_loop ; while (n) 235 236 no_extra_bits 237 ldr lr, [r1, #4] ; e = p->Extra 238 add r4, r5, #1 ; range + 1 239 tst lr, #1 240 lsr r4, r4, #1 ; split = (range + 1) >> 1 241 addne r2, r2, r4 ; lowvalue += split 242 subne r4, r5, r4 ; range = range-split 243 tst r2, #0x80000000 ; lowvalue & 0x80000000 244 lsl r5, r4, #1 ; range <<= 1 245 beq end_high_bit_not_set 246 247 ldr r4, [r0, #vp8_writer_pos] 248 mov r7, #0 249 sub r4, r4, #1 250 b end_zero_while_start 251 end_zero_while_loop 252 strb r7, [r6, r4] 253 sub r4, r4, #1 ; x-- 254 end_zero_while_start 255 cmp r4, #0 256 ldrge r6, [r0, #vp8_writer_buffer] 257 ldrb r12, [r6, r4] 258 cmpge r12, #0xff 259 beq end_zero_while_loop 260 261 ldr r6, [r0, #vp8_writer_buffer] 262 ldrb r7, [r6, r4] 263 add r7, r7, #1 264 strb r7, [r6, r4] 265 end_high_bit_not_set 266 adds r3, r3, #1 ; ++count 267 lsl r2, r2, #1 ; lowvalue <<= 1 268 bne end_count_zero 269 270 ldr r4, [r0, #vp8_writer_pos] 271 mvn r3, #7 272 ldr r7, [r0, #vp8_writer_buffer] 273 lsr r6, r2, #24 ; lowvalue >> 24 274 add r12, r4, #1 ; w->pos++ 275 bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff 276 str r12, [r0, #0x10] 277 strb r6, [r7, r4] 278 end_count_zero 279 skip_extra_bits 280 add r1, r1, #TOKENEXTRA_SZ ; ++p 281 check_p_lt_stop 282 ldr r4, [sp, #0] ; stop 283 cmp r1, r4 ; while( p < stop) 284 bcc while_p_lt_stop 285 286 str r2, [r0, #vp8_writer_lowvalue] 287 str r5, [r0, #vp8_writer_range] 288 str r3, [r0, #vp8_writer_count] 289 add sp, sp, #12 290 pop {r4-r11, pc} 291 ENDP 292 293 END 294