PageRenderTime 56ms CodeModel.GetById 14ms app.highlight 37ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zpao/v8monkey
Assembly | 327 lines | 234 code | 60 blank | 33 comment | 0 complexity | 398704bf05e1b31e95acb79a331c97ec MD5 | raw file
  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 asm_enc_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    ldrb    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    ldrb    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    ldrb    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 == 16
170    add     r12, r7, r6, lsl #4         ; b = vp8_extra_bits + t
171
172    ldr     r4, [r12, #vp8_extra_bit_struct_base_val]
173    cmp     r4, #0
174    beq     skip_extra_bits
175
176;   if( b->base_val)
177    ldr     r8, [r12, #vp8_extra_bit_struct_len] ; L
178    ldrsh   lr, [r1, #tokenextra_extra] ; e = p->Extra
179    cmp     r8, #0                      ; if( L)
180    beq     no_extra_bits
181
182    ldr     r9, [r12, #vp8_extra_bit_struct_prob]
183    asr     r7, lr, #1                  ; v=e>>1
184
185    ldr     r10, [r12, #vp8_extra_bit_struct_tree]
186    str     r10, [sp, #4]               ; b->tree
187
188    rsb     r4, r8, #32
189    lsl     r12, r7, r4
190
191    mov     lr, #0                      ; i = 0
192
193extra_bits_loop
194    ldrb    r4, [r9, lr, asr #1]            ; pp[i>>1]
195    sub     r7, r5, #1                  ; range-1
196    lsls    r12, r12, #1                ; v >> n
197    mul     r4, r4, r7                  ; (range-1) * pp[i>>1]
198    addcs   lr, lr, #1                  ; i + bb
199
200    mov     r7, #1
201    ldrsb   lr, [r10, lr]               ; i = b->tree[i+bb]
202    add     r4, r7, r4, lsr #8          ; split = 1 +  (((range-1) * pp[i>>1]) >> 8)
203
204    addcs   r2, r2, r4                  ; if  (bb) lowvalue += split
205    subcs   r4, r5, r4                  ; if  (bb) range = range-split
206
207    clz     r6, r4
208    sub     r6, r6, #24
209
210    adds    r3, r3, r6                  ; count += shift
211    lsl     r5, r4, r6                  ; range <<= shift
212    bmi     extra_count_lt_zero         ; if(count >= 0)
213
214    sub     r6, r6, r3                  ; offset= shift - count
215    sub     r4, r6, #1                  ; offset-1
216    lsls    r4, r2, r4                  ; if((lowvalue<<(offset-1)) & 0x80000000 )
217    bpl     extra_high_bit_not_set
218
219    ldr     r4, [r0, #vp8_writer_pos]   ; x
220    sub     r4, r4, #1                  ; x = w->pos - 1
221    b       extra_zero_while_start
222extra_zero_while_loop
223    mov     r10, #0
224    strb    r10, [r7, r4]               ; w->buffer[x] =(unsigned char)0
225    sub     r4, r4, #1                  ; x--
226extra_zero_while_start
227    cmp     r4, #0
228    ldrge   r7, [r0, #vp8_writer_buffer]
229    ldrb    r11, [r7, r4]
230    cmpge   r11, #0xff
231    beq     extra_zero_while_loop
232
233    ldr     r7, [r0, #vp8_writer_buffer]
234    ldrb    r10, [r7, r4]
235    add     r10, r10, #1
236    strb    r10, [r7, r4]
237extra_high_bit_not_set
238    rsb     r4, r6, #24                 ; 24-offset
239    ldr     r10, [r0, #vp8_writer_buffer]
240    lsr     r7, r2, r4                  ; lowvalue >> (24-offset)
241    ldr     r4, [r0, #vp8_writer_pos]
242    lsl     r2, r2, r6                  ; lowvalue <<= offset
243    mov     r6, r3                      ; shift = count
244    add     r11, r4, #1                 ; w->pos++
245    bic     r2, r2, #0xff000000         ; lowvalue &= 0xffffff
246    str     r11, [r0, #vp8_writer_pos]
247    sub     r3, r3, #8                  ; count -= 8
248    strb    r7, [r10, r4]               ; w->buffer[w->pos++]=(lowvalue >> (24-offset))
249    ldr     r10, [sp, #4]               ; b->tree
250extra_count_lt_zero
251    lsl     r2, r2, r6
252
253    subs    r8, r8, #1                  ; --n
254    bne     extra_bits_loop             ; while (n)
255
256no_extra_bits
257    ldr     lr, [r1, #4]                ; e = p->Extra
258    add     r4, r5, #1                  ; range + 1
259    tst     lr, #1
260    lsr     r4, r4, #1                  ; split = (range + 1) >> 1
261    addne   r2, r2, r4                  ; lowvalue += split
262    subne   r4, r5, r4                  ; range = range-split
263    tst     r2, #0x80000000             ; lowvalue & 0x80000000
264    lsl     r5, r4, #1                  ; range <<= 1
265    beq     end_high_bit_not_set
266
267    ldr     r4, [r0, #vp8_writer_pos]
268    mov     r7, #0
269    sub     r4, r4, #1
270    b       end_zero_while_start
271end_zero_while_loop
272    strb    r7, [r6, r4]
273    sub     r4, r4, #1                  ; x--
274end_zero_while_start
275    cmp     r4, #0
276    ldrge   r6, [r0, #vp8_writer_buffer]
277    ldrb    r12, [r6, r4]
278    cmpge   r12, #0xff
279    beq     end_zero_while_loop
280
281    ldr     r6, [r0, #vp8_writer_buffer]
282    ldrb    r7, [r6, r4]
283    add     r7, r7, #1
284    strb    r7, [r6, r4]
285end_high_bit_not_set
286    adds    r3, r3, #1                  ; ++count
287    lsl     r2, r2, #1                  ; lowvalue  <<= 1
288    bne     end_count_zero
289
290    ldr     r4, [r0, #vp8_writer_pos]
291    mvn     r3, #7
292    ldr     r7, [r0, #vp8_writer_buffer]
293    lsr     r6, r2, #24                 ; lowvalue >> 24
294    add     r12, r4, #1                 ; w->pos++
295    bic     r2, r2, #0xff000000         ; lowvalue &= 0xffffff
296    str     r12, [r0, #0x10]
297    strb    r6, [r7, r4]
298end_count_zero
299skip_extra_bits
300    add     r1, r1, #TOKENEXTRA_SZ      ; ++p
301check_p_lt_stop
302    ldr     r4, [sp, #0]                ; stop
303    cmp     r1, r4                      ; while( p < stop)
304    bcc     while_p_lt_stop
305
306    ldr     r6, [sp, #12]               ; mb_rows
307    ldr     r7, [sp, #16]               ; tokenlist address
308    subs    r6, r6, #1
309    add     r7, r7, #TOKENLIST_SZ       ; next element in the array
310    str     r6, [sp, #12]
311    bne     mb_row_loop
312
313    str     r2, [r0, #vp8_writer_lowvalue]
314    str     r5, [r0, #vp8_writer_range]
315    str     r3, [r0, #vp8_writer_count]
316    add     sp, sp, #24
317    pop     {r4-r11, pc}
318    ENDP
319
320_VP8_COMP_common_
321    DCD     vp8_comp_common
322_VP8_COMMON_MBrows_
323    DCD     vp8_common_mb_rows
324_VP8_COMP_tplist_
325    DCD     vp8_comp_tplist
326
327    END