]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/h264_i386.h
x86: h264: remove hardcoded edx in decode_significance[_8x8]_x86()
[ffmpeg] / libavcodec / x86 / h264_i386.h
1 /*
2  * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 /**
23  * @file
24  * H.264 / AVC / MPEG4 part10 codec.
25  * non-MMX i386-specific optimizations for H.264
26  * @author Michael Niedermayer <michaelni@gmx.at>
27  */
28
29 #ifndef AVCODEC_X86_H264_I386_H
30 #define AVCODEC_X86_H264_I386_H
31
32 #include <stddef.h>
33
34 #include "libavcodec/cabac.h"
35
36 //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
37 //as that would make optimization work hard)
38 #if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
39 static int decode_significance_x86(CABACContext *c, int max_coeff,
40                                    uint8_t *significant_coeff_ctx_base,
41                                    int *index, x86_reg last_off){
42     void *end= significant_coeff_ctx_base + max_coeff - 1;
43     int minusstart= -(int)significant_coeff_ctx_base;
44     int minusindex= 4-(int)index;
45     int bit;
46     x86_reg coeff_count;
47     int low;
48     __asm__ volatile(
49         "movl %a10(%5), %%esi                   \n\t"
50         "movl %a11(%5), %3                      \n\t"
51
52         "2:                                     \n\t"
53
54         BRANCHLESS_GET_CABAC("%4", "%5", "(%1)", "%3",
55                              "%w3", "%%esi", "%k0", "%b0", "%a12")
56
57         "test $1, %4                            \n\t"
58         " jz 3f                                 \n\t"
59         "add  %9, %1                            \n\t"
60
61         BRANCHLESS_GET_CABAC("%4", "%5", "(%1)", "%3",
62                              "%w3", "%%esi", "%k0", "%b0", "%a12")
63
64         "sub  %9, %1                            \n\t"
65         "mov  %2, %0                            \n\t"
66         "movl %6, %%ecx                         \n\t"
67         "add  %1, %%"REG_c"                     \n\t"
68         "movl %%ecx, (%0)                       \n\t"
69
70         "test $1, %4                            \n\t"
71         " jnz 4f                                \n\t"
72
73         "add  $4, %0                            \n\t"
74         "mov  %0, %2                            \n\t"
75
76         "3:                                     \n\t"
77         "add  $1, %1                            \n\t"
78         "cmp  %7, %1                            \n\t"
79         " jb 2b                                 \n\t"
80         "mov  %2, %0                            \n\t"
81         "movl %6, %%ecx                         \n\t"
82         "add  %1, %%"REG_c"                     \n\t"
83         "movl %%ecx, (%0)                       \n\t"
84         "4:                                     \n\t"
85         "add  %8, %k0                           \n\t"
86         "shr $2, %k0                            \n\t"
87
88         "movl %%esi, %a10(%5)                   \n\t"
89         "movl %3, %a11(%5)                      \n\t"
90         :"=&r"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
91          "=&r"(low), "=&r"(bit)
92         :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
93          "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
94          "i"(offsetof(CABACContext, bytestream))
95         : "%"REG_c, "%esi", "memory"
96     );
97     return coeff_count;
98 }
99
100 static int decode_significance_8x8_x86(CABACContext *c,
101                                        uint8_t *significant_coeff_ctx_base,
102                                        int *index, x86_reg last_off, const uint8_t *sig_off){
103     int minusindex= 4-(int)index;
104     int bit;
105     x86_reg coeff_count;
106     int low;
107     x86_reg last=0;
108     __asm__ volatile(
109         "movl %a10(%5), %%esi                   \n\t"
110         "movl %a11(%5), %3                      \n\t"
111
112         "mov %1, %%"REG_D"                      \n\t"
113         "2:                                     \n\t"
114
115         "mov %8, %0                             \n\t"
116         "movzbl (%0, %%"REG_D"), %%edi          \n\t"
117         "add %7, %%"REG_D"                      \n\t"
118
119         BRANCHLESS_GET_CABAC("%4", "%5", "(%%"REG_D")", "%3",
120                              "%w3", "%%esi", "%k0", "%b0", "%a12")
121
122         "mov %1, %%edi                          \n\t"
123         "test $1, %4                            \n\t"
124         " jz 3f                                 \n\t"
125
126         "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
127         "add %7, %%"REG_D"                      \n\t"
128         "add %9, %%"REG_D"                      \n\t"
129
130         BRANCHLESS_GET_CABAC("%4", "%5", "(%%"REG_D")", "%3",
131                              "%w3", "%%esi", "%k0", "%b0", "%a12")
132
133         "mov %2, %0                             \n\t"
134         "mov %1, %%edi                          \n\t"
135         "movl %%edi, (%0)                       \n\t"
136
137         "test $1, %4                            \n\t"
138         " jnz 4f                                \n\t"
139
140         "add $4, %0                             \n\t"
141         "mov %0, %2                             \n\t"
142
143         "3:                                     \n\t"
144         "addl $1, %%edi                         \n\t"
145         "mov %%edi, %1                          \n\t"
146         "cmpl $63, %%edi                        \n\t"
147         " jb 2b                                 \n\t"
148         "mov %2, %0                             \n\t"
149         "movl %%edi, (%0)                       \n\t"
150         "4:                                     \n\t"
151         "addl %6, %k0                           \n\t"
152         "shr $2, %k0                            \n\t"
153
154         "movl %%esi, %a10(%5)                   \n\t"
155         "movl %3, %a11(%5)                      \n\t"
156         :"=&r"(coeff_count),"+m"(last), "+m"(index), "=&r"(low), "=&r"(bit)
157         :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off),
158          "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
159          "i"(offsetof(CABACContext, bytestream))
160         : "%"REG_c, "%esi", "%"REG_D, "memory"
161     );
162     return coeff_count;
163 }
164 #endif /* ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
165
166 #endif /* AVCODEC_X86_H264_I386_H */