~ubuntu-branches/ubuntu/intrepid/x264/intrepid

« back to all changes in this revision

Viewing changes to common/x86/cabac-a.asm

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-05-03 01:12:18 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080503011218-3l7ra58egb7gezht
Tags: 1:0.svn20080408-0.0ubuntu1
* Merge from debian-multimedia. Remaining Ubuntu changes:
 - Maintainer field
 - Set epoch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;*****************************************************************************
 
2
;* cabac-a.asm: h264 encoder library
 
3
;*****************************************************************************
 
4
;* Copyright (C) 2008 x264 project
 
5
;*
 
6
;* Author: Loren Merritt <lorenm@u.washington.edu>
 
7
;*
 
8
;* This program is free software; you can redistribute it and/or modify
 
9
;* it under the terms of the GNU General Public License as published by
 
10
;* the Free Software Foundation; either version 2 of the License, or
 
11
;* (at your option) any later version.
 
12
;*
 
13
;* This program is distributed in the hope that it will be useful,
 
14
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
;* GNU General Public License for more details.
 
17
;*
 
18
;* You should have received a copy of the GNU General Public License
 
19
;* along with this program; if not, write to the Free Software
 
20
;* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 
21
;*****************************************************************************
 
22
 
 
23
%include "x86inc.asm"
 
24
 
 
25
SECTION .text
 
26
 
 
27
cextern x264_cabac_range_lps
 
28
cextern x264_cabac_transition
 
29
cextern x264_cabac_renorm_shift
 
30
 
 
31
%macro DEF_TMP 16
 
32
    %rep 8
 
33
        %define t%1d r%9d
 
34
        %define t%1b r%9b
 
35
        %define t%1  r%9
 
36
        %rotate 1
 
37
    %endrep
 
38
%endmacro
 
39
 
 
40
; t3 must be ecx, since it's used for shift.
 
41
%ifdef ARCH_X86_64
 
42
    DEF_TMP 0,1,2,3,4,5,6,7, 0,1,2,3,4,5,6,10
 
43
    %define pointer resq
 
44
%else
 
45
    DEF_TMP 0,1,2,3,4,5,6,7, 0,3,2,1,4,5,6,3
 
46
    %define pointer resd
 
47
%endif
 
48
 
 
49
struc cb
 
50
    .low: resd 1
 
51
    .range: resd 1
 
52
    .queue: resd 1
 
53
    .bytes_outstanding: resd 1
 
54
    .start: pointer 1
 
55
    .p: pointer 1
 
56
    .end: pointer 1
 
57
    align 16, resb 1
 
58
    .bits_encoded: resd 1
 
59
    .state: resb 460
 
60
endstruc
 
61
 
 
62
%macro LOAD_GLOBAL 4
 
63
%ifdef PIC64
 
64
    ; this would be faster if the arrays were declared in asm, so that I didn't have to duplicate the lea
 
65
    lea   r11, [%2 GLOBAL]
 
66
    %ifnidn %3, 0
 
67
    add   r11, %3
 
68
    %endif
 
69
    movzx %1, byte [r11+%4]
 
70
%elifdef PIC32
 
71
    %ifnidn %3, 0
 
72
    lea   %1, [%3+%4]
 
73
    movzx %1, byte [%2+%1 GLOBAL]
 
74
    %else
 
75
    movzx %1, byte [%2+%3+%4 GLOBAL]
 
76
    %endif
 
77
%else
 
78
    movzx %1, byte [%2+%3+%4]
 
79
%endif
 
80
%endmacro
 
81
 
 
82
cglobal x264_cabac_encode_decision, 0,7
 
83
    movifnidn t0d, r0m
 
84
    movifnidn t1d, r1m
 
85
    picgetgot t2
 
86
    mov   t5d, [r0+cb.range]
 
87
    movzx t3d, byte [r0+cb.state+t1]
 
88
    mov   t4d, t5d
 
89
    shr   t5d, 6
 
90
    and   t5d, 3
 
91
    LOAD_GLOBAL t5d, x264_cabac_range_lps, t5, t3*4
 
92
    sub   t4d, t5d
 
93
    mov   t6d, t3d
 
94
    shr   t6d, 6
 
95
%ifdef PIC32
 
96
    cmp   t6d, r2m
 
97
%else
 
98
    movifnidn t2d, r2m
 
99
    cmp   t6d, t2d
 
100
%endif
 
101
    mov   t6d, [r0+cb.low]
 
102
    lea   t7,  [t6+t4]
 
103
    cmovne t4d, t5d
 
104
    cmovne t6d, t7d
 
105
%ifdef PIC32
 
106
    mov   t1,  r2m
 
107
    LOAD_GLOBAL t3d, x264_cabac_transition, t1, t3*2
 
108
%else
 
109
    LOAD_GLOBAL t3d, x264_cabac_transition, t2, t3*2
 
110
%endif
 
111
    movifnidn t1d, r1m
 
112
    mov   [r0+cb.state+t1], t3b
 
113
.renorm:
 
114
    mov   t3d, t4d
 
115
    shr   t3d, 3
 
116
    LOAD_GLOBAL t3d, x264_cabac_renorm_shift, 0, t3
 
117
    shl   t4d, t3b
 
118
    shl   t6d, t3b
 
119
    add   t3d, [r0+cb.queue]
 
120
    mov   [r0+cb.range], t4d
 
121
    mov   [r0+cb.low], t6d
 
122
    mov   [r0+cb.queue], t3d
 
123
    cmp   t3d, 8
 
124
    jge .putbyte
 
125
.ret:
 
126
    REP_RET
 
127
.putbyte:
 
128
    ; alive: t0=cb t3=queue t6=low
 
129
    add   t3d, 2
 
130
    mov   t1d, 1
 
131
    mov   t2d, t6d
 
132
    shl   t1d, t3b
 
133
    shr   t2d, t3b ; out
 
134
    dec   t1d
 
135
    sub   t3d, 10
 
136
    and   t6d, t1d
 
137
    cmp   t2b, 0xff ; FIXME is a 32bit op faster?
 
138
    mov   [r0+cb.queue], t3d
 
139
    mov   [r0+cb.low], t6d
 
140
    mov   t1d, t2d
 
141
    mov   t4,  [r0+cb.p]
 
142
    je .postpone
 
143
    mov   t5d, [r0+cb.bytes_outstanding]
 
144
    shr   t1d, 8 ; carry
 
145
    lea   t6, [t4+t5+1]
 
146
    cmp   t6, [r0+cb.end]
 
147
    jge .ret
 
148
    add   [t4-1], t1b
 
149
    test  t5d, t5d
 
150
    jz .no_outstanding
 
151
    dec   t1d
 
152
.loop_outstanding:
 
153
    mov   [t4], t1b
 
154
    inc   t4
 
155
    dec   t5d
 
156
    jg .loop_outstanding
 
157
.no_outstanding:
 
158
    mov   [t4], t2b
 
159
    inc   t4
 
160
    mov   [r0+cb.bytes_outstanding], t5d ; is zero, but a reg has smaller opcode than an immediate
 
161
    mov   [r0+cb.p], t4
 
162
    RET
 
163
.postpone:
 
164
    inc   dword [r0+cb.bytes_outstanding]
 
165
    RET
 
166