]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/h264_i386.h
x86: h264: cast pointers to intptr_t rather than int
[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= -(intptr_t)significant_coeff_ctx_base;
44     int minusindex= 4-(intptr_t)index;
45     int bit;
46     x86_reg coeff_count;
47     int low;
48     int range;
49     __asm__ volatile(
50         "movl %a11(%6), %5                      \n\t"
51         "movl %a12(%6), %3                      \n\t"
52
53         "2:                                     \n\t"
54
55         BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
56                              "%w3", "%5", "%k0", "%b0", "%a13")
57
58         "test $1, %4                            \n\t"
59         " jz 3f                                 \n\t"
60         "add  %10, %1                           \n\t"
61
62         BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
63                              "%w3", "%5", "%k0", "%b0", "%a13")
64
65         "sub  %10, %1                           \n\t"
66         "mov  %2, %0                            \n\t"
67         "movl %7, %%ecx                         \n\t"
68         "add  %1, %%"REG_c"                     \n\t"
69         "movl %%ecx, (%0)                       \n\t"
70
71         "test $1, %4                            \n\t"
72         " jnz 4f                                \n\t"
73
74         "add  $4, %0                            \n\t"
75         "mov  %0, %2                            \n\t"
76
77         "3:                                     \n\t"
78         "add  $1, %1                            \n\t"
79         "cmp  %8, %1                            \n\t"
80         " jb 2b                                 \n\t"
81         "mov  %2, %0                            \n\t"
82         "movl %7, %%ecx                         \n\t"
83         "add  %1, %%"REG_c"                     \n\t"
84         "movl %%ecx, (%0)                       \n\t"
85         "4:                                     \n\t"
86         "add  %9, %k0                           \n\t"
87         "shr $2, %k0                            \n\t"
88
89         "movl %5, %a11(%6)                      \n\t"
90         "movl %3, %a12(%6)                      \n\t"
91         :"=&r"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
92          "=&r"(low), "=&r"(bit), "=&r"(range)
93         :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
94          "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
95          "i"(offsetof(CABACContext, bytestream))
96         : "%"REG_c, "memory"
97     );
98     return coeff_count;
99 }
100
101 static int decode_significance_8x8_x86(CABACContext *c,
102                                        uint8_t *significant_coeff_ctx_base,
103                                        int *index, x86_reg last_off, const uint8_t *sig_off){
104     int minusindex= 4-(intptr_t)index;
105     int bit;
106     x86_reg coeff_count;
107     int low;
108     int range;
109     x86_reg last=0;
110     x86_reg state;
111     __asm__ volatile(
112         "movl %a12(%7), %5                      \n\t"
113         "movl %a13(%7), %3                      \n\t"
114
115         "mov %1, %6                             \n\t"
116         "2:                                     \n\t"
117
118         "mov %10, %0                            \n\t"
119         "movzbl (%0, %6), %k6                   \n\t"
120         "add %9, %6                             \n\t"
121
122         BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
123                              "%w3", "%5", "%k0", "%b0", "%a14")
124
125         "mov %1, %k6                            \n\t"
126         "test $1, %4                            \n\t"
127         " jz 3f                                 \n\t"
128
129         "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%k6), %k6\n\t"
130         "add %9, %6                             \n\t"
131         "add %11, %6                            \n\t"
132
133         BRANCHLESS_GET_CABAC("%4", "%7", "(%6)", "%3",
134                              "%w3", "%5", "%k0", "%b0", "%a14")
135
136         "mov %2, %0                             \n\t"
137         "mov %1, %k6                            \n\t"
138         "movl %k6, (%0)                         \n\t"
139
140         "test $1, %4                            \n\t"
141         " jnz 4f                                \n\t"
142
143         "add $4, %0                             \n\t"
144         "mov %0, %2                             \n\t"
145
146         "3:                                     \n\t"
147         "addl $1, %k6                           \n\t"
148         "mov %k6, %1                            \n\t"
149         "cmpl $63, %k6                          \n\t"
150         " jb 2b                                 \n\t"
151         "mov %2, %0                             \n\t"
152         "movl %k6, (%0)                         \n\t"
153         "4:                                     \n\t"
154         "addl %8, %k0                           \n\t"
155         "shr $2, %k0                            \n\t"
156
157         "movl %5, %a12(%7)                      \n\t"
158         "movl %3, %a13(%7)                      \n\t"
159         :"=&r"(coeff_count),"+m"(last), "+m"(index), "=&r"(low), "=&r"(bit),
160          "=&r"(range), "=&r"(state)
161         :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off),
162          "i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
163          "i"(offsetof(CABACContext, bytestream))
164         : "%"REG_c, "memory"
165     );
166     return coeff_count;
167 }
168 #endif /* ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
169
170 #endif /* AVCODEC_X86_H264_I386_H */