]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/h264_i386.h
Merge remote-tracking branch 'qatar/master'
[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 FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 #include "cabac.h"
36
37 //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
38 //as that would make optimization work hard)
39 #if HAVE_7REGS
40 static int decode_significance_x86(CABACContext *c, int max_coeff,
41                                    uint8_t *significant_coeff_ctx_base,
42                                    int *index, x86_reg last_off){
43     void *end= significant_coeff_ctx_base + max_coeff - 1;
44     int minusstart= -(intptr_t)significant_coeff_ctx_base;
45     int minusindex= 4-(intptr_t)index;
46     int bit;
47     x86_reg coeff_count;
48
49 #ifdef BROKEN_RELOCATIONS
50     void *tables;
51
52     __asm__ volatile(
53         "lea   "MANGLE(ff_h264_cabac_tables)", %0      \n\t"
54         : "=&r"(tables)
55     );
56 #endif
57
58     __asm__ volatile(
59         "3:                                     \n\t"
60
61         BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
62                              "%5", "%q5", "%k0", "%b0",
63                              "%a11(%6)", "%a12(%6)", "%a13", "%a14", "%a15", "%16")
64
65         "test $1, %4                            \n\t"
66         " jz 4f                                 \n\t"
67         "add  %10, %1                           \n\t"
68
69         BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
70                              "%5", "%q5", "%k0", "%b0",
71                              "%a11(%6)", "%a12(%6)", "%a13", "%a14", "%a15", "%16")
72
73         "sub  %10, %1                           \n\t"
74         "mov  %2, %0                            \n\t"
75         "movl %7, %%ecx                         \n\t"
76         "add  %1, %%"REG_c"                     \n\t"
77         "movl %%ecx, (%0)                       \n\t"
78
79         "test $1, %4                            \n\t"
80         " jnz 5f                                \n\t"
81
82         "add"OPSIZE"  $4, %2                    \n\t"
83
84         "4:                                     \n\t"
85         "add  $1, %1                            \n\t"
86         "cmp  %8, %1                            \n\t"
87         " jb 3b                                 \n\t"
88         "mov  %2, %0                            \n\t"
89         "movl %7, %%ecx                         \n\t"
90         "add  %1, %%"REG_c"                     \n\t"
91         "movl %%ecx, (%0)                       \n\t"
92         "5:                                     \n\t"
93         "add  %9, %k0                           \n\t"
94         "shr $2, %k0                            \n\t"
95         : "=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
96           "+&r"(c->low), "=&r"(bit), "+&r"(c->range)
97         : "r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
98           "i"(offsetof(CABACContext, bytestream)),
99           "i"(offsetof(CABACContext, bytestream_end)),
100           "i"(H264_NORM_SHIFT_OFFSET),
101           "i"(H264_LPS_RANGE_OFFSET),
102           "i"(H264_MLPS_STATE_OFFSET) TABLES_ARG
103         : "%"REG_c, "memory"
104     );
105     return coeff_count;
106 }
107
108 static int decode_significance_8x8_x86(CABACContext *c,
109                                        uint8_t *significant_coeff_ctx_base,
110                                        int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
111     int minusindex= 4-(intptr_t)index;
112     int bit;
113     x86_reg coeff_count;
114     x86_reg last=0;
115     x86_reg state;
116
117 #ifdef BROKEN_RELOCATIONS
118     void *tables;
119
120     __asm__ volatile(
121         "lea    "MANGLE(ff_h264_cabac_tables)", %0      \n\t"
122         : "=&r"(tables)
123     );
124 #endif
125
126     __asm__ volatile(
127         "mov %1, %6                             \n\t"
128         "3:                                     \n\t"
129
130         "mov %10, %0                            \n\t"
131         "movzbl (%0, %6), %k6                   \n\t"
132         "add %9, %6                             \n\t"
133
134         BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
135                              "%5", "%q5", "%k0", "%b0",
136                              "%a12(%7)", "%a13(%7)", "%a14", "%a15", "%a16", "%18")
137
138         "mov %1, %k6                            \n\t"
139         "test $1, %4                            \n\t"
140         " jz 4f                                 \n\t"
141
142 #ifdef BROKEN_RELOCATIONS
143         "movzbl %a17(%18, %q6), %k6\n\t"
144 #else
145         "movzbl "MANGLE(ff_h264_cabac_tables)"+%a17(%k6), %k6\n\t"
146 #endif
147         "add %11, %6                            \n\t"
148
149         BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
150                              "%5", "%q5", "%k0", "%b0",
151                              "%a12(%7)", "%a13(%7)", "%a14", "%a15", "%a16", "%18")
152
153         "mov %2, %0                             \n\t"
154         "mov %1, %k6                            \n\t"
155         "movl %k6, (%0)                         \n\t"
156
157         "test $1, %4                            \n\t"
158         " jnz 5f                                \n\t"
159
160         "add"OPSIZE"  $4, %2                    \n\t"
161
162         "4:                                     \n\t"
163         "addl $1, %k6                           \n\t"
164         "mov %k6, %1                            \n\t"
165         "cmpl $63, %k6                          \n\t"
166         " jb 3b                                 \n\t"
167         "mov %2, %0                             \n\t"
168         "movl %k6, (%0)                         \n\t"
169         "5:                                     \n\t"
170         "addl %8, %k0                           \n\t"
171         "shr $2, %k0                            \n\t"
172         : "=&q"(coeff_count), "+m"(last), "+m"(index), "+&r"(c->low),
173           "=&r"(bit), "+&r"(c->range), "=&r"(state)
174         : "r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base),
175           "m"(sig_off), "m"(last_coeff_ctx_base),
176           "i"(offsetof(CABACContext, bytestream)),
177           "i"(offsetof(CABACContext, bytestream_end)),
178           "i"(H264_NORM_SHIFT_OFFSET),
179           "i"(H264_LPS_RANGE_OFFSET),
180           "i"(H264_MLPS_STATE_OFFSET),
181           "i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET) TABLES_ARG
182         : "%"REG_c, "memory"
183     );
184     return coeff_count;
185 }
186 #endif /* HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
187
188 #endif /* AVCODEC_X86_H264_I386_H */