x86: cabac: remove hardcoded struct offsets from inline asm
[libav.git] / libavcodec / x86 / h264_i386.h
CommitLineData
52cb7981
JD
1/*
2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
2912e87a 5 * This file is part of Libav.
52cb7981 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
52cb7981
JD
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 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
52cb7981
JD
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
52cb7981
JD
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
ba87f080 23 * @file
52cb7981
JD
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
a6493a8f
DB
29#ifndef AVCODEC_X86_H264_I386_H
30#define AVCODEC_X86_H264_I386_H
52cb7981 31
6b712acc
MR
32#include <stddef.h>
33
245976da 34#include "libavcodec/cabac.h"
52cb7981 35
591d87ba
JD
36//FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
37//as that would make optimization work hard)
b250f9c6 38#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
591d87ba
JD
39static int decode_significance_x86(CABACContext *c, int max_coeff,
40 uint8_t *significant_coeff_ctx_base,
c90b9442 41 int *index, x86_reg last_off){
52cb7981
JD
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 coeff_count;
be449fca 46 __asm__ volatile(
6b712acc
MR
47 "movl %a8(%3), %%esi \n\t"
48 "movl %a9(%3), %%ebx \n\t"
52cb7981
JD
49
50 "2: \n\t"
51
591d87ba 52 BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx",
6b712acc 53 "%%bx", "%%esi", "%%eax", "%%al", "%a10")
52cb7981
JD
54
55 "test $1, %%edx \n\t"
56 " jz 3f \n\t"
c90b9442 57 "add %7, %1 \n\t"
52cb7981 58
c90b9442 59 BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx",
6b712acc 60 "%%bx", "%%esi", "%%eax", "%%al", "%a10")
52cb7981 61
c90b9442 62 "sub %7, %1 \n\t"
52cb7981
JD
63 "mov %2, %%"REG_a" \n\t"
64 "movl %4, %%ecx \n\t"
65 "add %1, %%"REG_c" \n\t"
66 "movl %%ecx, (%%"REG_a") \n\t"
67
68 "test $1, %%edx \n\t"
69 " jnz 4f \n\t"
70
71 "add $4, %%"REG_a" \n\t"
72 "mov %%"REG_a", %2 \n\t"
73
74 "3: \n\t"
75 "add $1, %1 \n\t"
76 "cmp %5, %1 \n\t"
77 " jb 2b \n\t"
78 "mov %2, %%"REG_a" \n\t"
79 "movl %4, %%ecx \n\t"
80 "add %1, %%"REG_c" \n\t"
81 "movl %%ecx, (%%"REG_a") \n\t"
82 "4: \n\t"
83 "add %6, %%eax \n\t"
84 "shr $2, %%eax \n\t"
85
6b712acc
MR
86 "movl %%esi, %a8(%3) \n\t"
87 "movl %%ebx, %a9(%3) \n\t"
52cb7981 88 :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index)
6b712acc
MR
89 :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
90 "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
91 "i"(offsetof(CABACContext, bytestream))
52cb7981
JD
92 : "%"REG_c, "%ebx", "%edx", "%esi", "memory"
93 );
94 return coeff_count;
95}
96
591d87ba
JD
97static int decode_significance_8x8_x86(CABACContext *c,
98 uint8_t *significant_coeff_ctx_base,
c90b9442 99 int *index, x86_reg last_off, const uint8_t *sig_off){
52cb7981
JD
100 int minusindex= 4-(int)index;
101 int coeff_count;
40d0e665 102 x86_reg last=0;
be449fca 103 __asm__ volatile(
6b712acc
MR
104 "movl %a8(%3), %%esi \n\t"
105 "movl %a9(%3), %%ebx \n\t"
52cb7981
JD
106
107 "mov %1, %%"REG_D" \n\t"
108 "2: \n\t"
109
110 "mov %6, %%"REG_a" \n\t"
111 "movzbl (%%"REG_a", %%"REG_D"), %%edi \n\t"
112 "add %5, %%"REG_D" \n\t"
113
591d87ba 114 BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx",
6b712acc 115 "%%bx", "%%esi", "%%eax", "%%al", "%a10")
52cb7981
JD
116
117 "mov %1, %%edi \n\t"
118 "test $1, %%edx \n\t"
119 " jz 3f \n\t"
120
121 "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
122 "add %5, %%"REG_D" \n\t"
c90b9442 123 "add %7, %%"REG_D" \n\t"
52cb7981 124
c90b9442 125 BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx",
6b712acc 126 "%%bx", "%%esi", "%%eax", "%%al", "%a10")
52cb7981
JD
127
128 "mov %2, %%"REG_a" \n\t"
129 "mov %1, %%edi \n\t"
130 "movl %%edi, (%%"REG_a") \n\t"
131
132 "test $1, %%edx \n\t"
133 " jnz 4f \n\t"
134
135 "add $4, %%"REG_a" \n\t"
136 "mov %%"REG_a", %2 \n\t"
137
138 "3: \n\t"
139 "addl $1, %%edi \n\t"
140 "mov %%edi, %1 \n\t"
141 "cmpl $63, %%edi \n\t"
142 " jb 2b \n\t"
143 "mov %2, %%"REG_a" \n\t"
144 "movl %%edi, (%%"REG_a") \n\t"
145 "4: \n\t"
146 "addl %4, %%eax \n\t"
147 "shr $2, %%eax \n\t"
148
6b712acc
MR
149 "movl %%esi, %a8(%3) \n\t"
150 "movl %%ebx, %a9(%3) \n\t"
52cb7981 151 :"=&a"(coeff_count),"+m"(last), "+m"(index)
6b712acc
MR
152 :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off),
153 "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
154 "i"(offsetof(CABACContext, bytestream))
52cb7981
JD
155 : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory"
156 );
157 return coeff_count;
158}
b250f9c6
AJ
159#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE */
160 /* !defined(BROKEN_RELOCATIONS) */
52cb7981 161
a6493a8f 162#endif /* AVCODEC_X86_H264_I386_H */