media/libvpx/vp8/encoder/arm/armv5te/vp8_packtokens_armv5.asm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial