x86: Tighten register constraints for decode_significance*_x86.
[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"
2143d69b 35#include "cabac.h"
52cb7981 36
591d87ba
JD
37//FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
38//as that would make optimization work hard)
6fdb2ce3 39#if HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
591d87ba
JD
40static int decode_significance_x86(CABACContext *c, int max_coeff,
41 uint8_t *significant_coeff_ctx_base,
c90b9442 42 int *index, x86_reg last_off){
52cb7981 43 void *end= significant_coeff_ctx_base + max_coeff - 1;
d075e7d5
MR
44 int minusstart= -(intptr_t)significant_coeff_ctx_base;
45 int minusindex= 4-(intptr_t)index;
3fc4e36c 46 int bit;
e4b5a204 47 x86_reg coeff_count;
be449fca 48 __asm__ volatile(
52cb7981
JD
49 "2: \n\t"
50
599b4c6e
MR
51 BRANCHLESS_GET_CABAC("%4", "(%1)", "%3",
52 "%w3", "%5", "%k0", "%b0", "%6")
52cb7981 53
3fc4e36c 54 "test $1, %4 \n\t"
52cb7981 55 " jz 3f \n\t"
b92c1a6d 56 "add %10, %1 \n\t"
52cb7981 57
599b4c6e
MR
58 BRANCHLESS_GET_CABAC("%4", "(%1)", "%3",
59 "%w3", "%5", "%k0", "%b0", "%6")
52cb7981 60
b92c1a6d 61 "sub %10, %1 \n\t"
e4b5a204 62 "mov %2, %0 \n\t"
b92c1a6d 63 "movl %7, %%ecx \n\t"
52cb7981 64 "add %1, %%"REG_c" \n\t"
e4b5a204 65 "movl %%ecx, (%0) \n\t"
52cb7981 66
3fc4e36c 67 "test $1, %4 \n\t"
52cb7981
JD
68 " jnz 4f \n\t"
69
3ad16841 70 "add"OPSIZE" $4, %2 \n\t"
52cb7981
JD
71
72 "3: \n\t"
73 "add $1, %1 \n\t"
b92c1a6d 74 "cmp %8, %1 \n\t"
52cb7981 75 " jb 2b \n\t"
e4b5a204 76 "mov %2, %0 \n\t"
b92c1a6d 77 "movl %7, %%ecx \n\t"
52cb7981 78 "add %1, %%"REG_c" \n\t"
e4b5a204 79 "movl %%ecx, (%0) \n\t"
52cb7981 80 "4: \n\t"
b92c1a6d 81 "add %9, %k0 \n\t"
e4b5a204 82 "shr $2, %k0 \n\t"
c5ee7407 83 :"=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
599b4c6e
MR
84 "+&r"(c->low), "=&r"(bit), "+&r"(c->range),
85 "+m"(c->bytestream)
86 :"m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off)
b92c1a6d 87 : "%"REG_c, "memory"
52cb7981
JD
88 );
89 return coeff_count;
90}
91
591d87ba
JD
92static int decode_significance_8x8_x86(CABACContext *c,
93 uint8_t *significant_coeff_ctx_base,
6c325765 94 int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
d075e7d5 95 int minusindex= 4-(intptr_t)index;
3fc4e36c 96 int bit;
e4b5a204 97 x86_reg coeff_count;
40d0e665 98 x86_reg last=0;
3a4edb76 99 x86_reg state;
be449fca 100 __asm__ volatile(
3a4edb76 101 "mov %1, %6 \n\t"
52cb7981
JD
102 "2: \n\t"
103
3a4edb76
MR
104 "mov %10, %0 \n\t"
105 "movzbl (%0, %6), %k6 \n\t"
106 "add %9, %6 \n\t"
52cb7981 107
599b4c6e
MR
108 BRANCHLESS_GET_CABAC("%4", "(%6)", "%3",
109 "%w3", "%5", "%k0", "%b0", "%7")
52cb7981 110
3a4edb76 111 "mov %1, %k6 \n\t"
3fc4e36c 112 "test $1, %4 \n\t"
52cb7981
JD
113 " jz 3f \n\t"
114
3a4edb76 115 "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%k6), %k6\n\t"
3a4edb76 116 "add %11, %6 \n\t"
52cb7981 117
599b4c6e
MR
118 BRANCHLESS_GET_CABAC("%4", "(%6)", "%3",
119 "%w3", "%5", "%k0", "%b0", "%7")
52cb7981 120
e4b5a204 121 "mov %2, %0 \n\t"
3a4edb76
MR
122 "mov %1, %k6 \n\t"
123 "movl %k6, (%0) \n\t"
52cb7981 124
3fc4e36c 125 "test $1, %4 \n\t"
52cb7981
JD
126 " jnz 4f \n\t"
127
3ad16841 128 "add"OPSIZE" $4, %2 \n\t"
52cb7981
JD
129
130 "3: \n\t"
3a4edb76
MR
131 "addl $1, %k6 \n\t"
132 "mov %k6, %1 \n\t"
133 "cmpl $63, %k6 \n\t"
52cb7981 134 " jb 2b \n\t"
e4b5a204 135 "mov %2, %0 \n\t"
3a4edb76 136 "movl %k6, (%0) \n\t"
52cb7981 137 "4: \n\t"
3a4edb76 138 "addl %8, %k0 \n\t"
e4b5a204 139 "shr $2, %k0 \n\t"
f5f004bc 140 :"=&q"(coeff_count),"+m"(last), "+m"(index), "+&r"(c->low), "=&r"(bit),
599b4c6e
MR
141 "+&r"(c->range), "=&r"(state), "+m"(c->bytestream)
142 :"m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_coeff_ctx_base)
3a4edb76 143 : "%"REG_c, "memory"
52cb7981
JD
144 );
145 return coeff_count;
146}
6fdb2ce3 147#endif /* HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */
52cb7981 148
a6493a8f 149#endif /* AVCODEC_X86_H264_I386_H */