mirror of https://github.com/FFmpeg/FFmpeg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
209 lines
7.9 KiB
209 lines
7.9 KiB
17 years ago
|
/*
|
||
|
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
|
||
|
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
||
|
*
|
||
|
* This file is part of FFmpeg.
|
||
|
*
|
||
|
* FFmpeg is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* FFmpeg is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with FFmpeg; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
*/
|
||
|
|
||
|
/**
|
||
15 years ago
|
* @file
|
||
9 years ago
|
* H.264 / AVC / MPEG-4 part10 codec.
|
||
9 years ago
|
* non-SIMD x86-specific optimizations for H.264
|
||
17 years ago
|
* @author Michael Niedermayer <michaelni@gmx.at>
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <stddef.h>
|
||
|
|
||
17 years ago
|
#include "libavcodec/cabac.h"
|
||
14 years ago
|
#include "cabac.h"
|
||
17 years ago
|
|
||
13 years ago
|
#if HAVE_INLINE_ASM
|
||
|
|
||
10 years ago
|
#if ARCH_X86_64
|
||
|
#define REG64 "r"
|
||
|
#else
|
||
|
#define REG64 "m"
|
||
|
#endif
|
||
|
|
||
17 years ago
|
//FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
|
||
|
//as that would make optimization work hard)
|
||
11 years ago
|
#if HAVE_7REGS && !BROKEN_COMPILER
|
||
13 years ago
|
#define decode_significance decode_significance_x86
|
||
17 years ago
|
static int decode_significance_x86(CABACContext *c, int max_coeff,
|
||
|
uint8_t *significant_coeff_ctx_base,
|
||
14 years ago
|
int *index, x86_reg last_off){
|
||
17 years ago
|
void *end= significant_coeff_ctx_base + max_coeff - 1;
|
||
14 years ago
|
int minusstart= -(intptr_t)significant_coeff_ctx_base;
|
||
|
int minusindex= 4-(intptr_t)index;
|
||
14 years ago
|
int bit;
|
||
14 years ago
|
x86_reg coeff_count;
|
||
13 years ago
|
|
||
13 years ago
|
#ifdef BROKEN_RELOCATIONS
|
||
|
void *tables;
|
||
|
|
||
|
__asm__ volatile(
|
||
|
"lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
|
||
|
: "=&r"(tables)
|
||
11 years ago
|
: NAMED_CONSTRAINTS_ARRAY(ff_h264_cabac_tables)
|
||
13 years ago
|
);
|
||
|
#endif
|
||
|
|
||
16 years ago
|
__asm__ volatile(
|
||
13 years ago
|
"3: \n\t"
|
||
17 years ago
|
|
||
13 years ago
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
|
||
|
"%5", "%q5", "%k0", "%b0",
|
||
12 years ago
|
"%c11(%6)", "%c12(%6)",
|
||
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
||
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
||
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
||
|
"%13")
|
||
17 years ago
|
|
||
14 years ago
|
"test $1, %4 \n\t"
|
||
13 years ago
|
" jz 4f \n\t"
|
||
14 years ago
|
"add %10, %1 \n\t"
|
||
17 years ago
|
|
||
13 years ago
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
|
||
|
"%5", "%q5", "%k0", "%b0",
|
||
12 years ago
|
"%c11(%6)", "%c12(%6)",
|
||
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
||
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
||
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
||
|
"%13")
|
||
17 years ago
|
|
||
14 years ago
|
"sub %10, %1 \n\t"
|
||
14 years ago
|
"mov %2, %0 \n\t"
|
||
14 years ago
|
"movl %7, %%ecx \n\t"
|
||
9 years ago
|
"add %1, %%"FF_REG_c" \n\t"
|
||
14 years ago
|
"movl %%ecx, (%0) \n\t"
|
||
17 years ago
|
|
||
14 years ago
|
"test $1, %4 \n\t"
|
||
13 years ago
|
" jnz 5f \n\t"
|
||
17 years ago
|
|
||
9 years ago
|
"add"FF_OPSIZE" $4, %2 \n\t"
|
||
17 years ago
|
|
||
13 years ago
|
"4: \n\t"
|
||
17 years ago
|
"add $1, %1 \n\t"
|
||
14 years ago
|
"cmp %8, %1 \n\t"
|
||
13 years ago
|
" jb 3b \n\t"
|
||
14 years ago
|
"mov %2, %0 \n\t"
|
||
14 years ago
|
"movl %7, %%ecx \n\t"
|
||
9 years ago
|
"add %1, %%"FF_REG_c" \n\t"
|
||
14 years ago
|
"movl %%ecx, (%0) \n\t"
|
||
13 years ago
|
"5: \n\t"
|
||
14 years ago
|
"add %9, %k0 \n\t"
|
||
14 years ago
|
"shr $2, %k0 \n\t"
|
||
13 years ago
|
: "=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
|
||
|
"+&r"(c->low), "=&r"(bit), "+&r"(c->range)
|
||
|
: "r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
|
||
13 years ago
|
"i"(offsetof(CABACContext, bytestream)),
|
||
12 years ago
|
"i"(offsetof(CABACContext, bytestream_end))
|
||
|
TABLES_ARG
|
||
9 years ago
|
: "%"FF_REG_c, "memory"
|
||
17 years ago
|
);
|
||
|
return coeff_count;
|
||
|
}
|
||
|
|
||
13 years ago
|
#define decode_significance_8x8 decode_significance_8x8_x86
|
||
17 years ago
|
static int decode_significance_8x8_x86(CABACContext *c,
|
||
|
uint8_t *significant_coeff_ctx_base,
|
||
14 years ago
|
int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
|
||
14 years ago
|
int minusindex= 4-(intptr_t)index;
|
||
14 years ago
|
int bit;
|
||
14 years ago
|
x86_reg coeff_count;
|
||
17 years ago
|
x86_reg last=0;
|
||
14 years ago
|
x86_reg state;
|
||
13 years ago
|
|
||
13 years ago
|
#ifdef BROKEN_RELOCATIONS
|
||
|
void *tables;
|
||
|
|
||
|
__asm__ volatile(
|
||
|
"lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
|
||
|
: "=&r"(tables)
|
||
11 years ago
|
: NAMED_CONSTRAINTS_ARRAY(ff_h264_cabac_tables)
|
||
13 years ago
|
);
|
||
|
#endif
|
||
|
|
||
16 years ago
|
__asm__ volatile(
|
||
14 years ago
|
"mov %1, %6 \n\t"
|
||
13 years ago
|
"3: \n\t"
|
||
17 years ago
|
|
||
14 years ago
|
"mov %10, %0 \n\t"
|
||
10 years ago
|
"movzb (%0, %6), %6 \n\t"
|
||
14 years ago
|
"add %9, %6 \n\t"
|
||
17 years ago
|
|
||
13 years ago
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
|
||
|
"%5", "%q5", "%k0", "%b0",
|
||
12 years ago
|
"%c12(%7)", "%c13(%7)",
|
||
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
||
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
||
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
||
|
"%15")
|
||
17 years ago
|
|
||
10 years ago
|
"mov %1, %6 \n\t"
|
||
14 years ago
|
"test $1, %4 \n\t"
|
||
13 years ago
|
" jz 4f \n\t"
|
||
17 years ago
|
|
||
13 years ago
|
#ifdef BROKEN_RELOCATIONS
|
||
10 years ago
|
"movzb %c14(%15, %q6), %6\n\t"
|
||
13 years ago
|
#else
|
||
10 years ago
|
"movzb "MANGLE(ff_h264_cabac_tables)"+%c14(%6), %6\n\t"
|
||
13 years ago
|
#endif
|
||
14 years ago
|
"add %11, %6 \n\t"
|
||
17 years ago
|
|
||
13 years ago
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
|
||
|
"%5", "%q5", "%k0", "%b0",
|
||
12 years ago
|
"%c12(%7)", "%c13(%7)",
|
||
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
||
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
||
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
||
|
"%15")
|
||
17 years ago
|
|
||
14 years ago
|
"mov %2, %0 \n\t"
|
||
10 years ago
|
"mov %1, %6 \n\t"
|
||
10 years ago
|
"mov %k6, (%0) \n\t"
|
||
17 years ago
|
|
||
14 years ago
|
"test $1, %4 \n\t"
|
||
13 years ago
|
" jnz 5f \n\t"
|
||
17 years ago
|
|
||
9 years ago
|
"add"FF_OPSIZE" $4, %2 \n\t"
|
||
17 years ago
|
|
||
13 years ago
|
"4: \n\t"
|
||
10 years ago
|
"add $1, %6 \n\t"
|
||
|
"mov %6, %1 \n\t"
|
||
|
"cmp $63, %6 \n\t"
|
||
13 years ago
|
" jb 3b \n\t"
|
||
14 years ago
|
"mov %2, %0 \n\t"
|
||
10 years ago
|
"mov %k6, (%0) \n\t"
|
||
13 years ago
|
"5: \n\t"
|
||
14 years ago
|
"addl %8, %k0 \n\t"
|
||
14 years ago
|
"shr $2, %k0 \n\t"
|
||
10 years ago
|
: "=&q"(coeff_count), "+"REG64(last), "+"REG64(index), "+&r"(c->low),
|
||
13 years ago
|
"=&r"(bit), "+&r"(c->range), "=&r"(state)
|
||
|
: "r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base),
|
||
10 years ago
|
REG64(sig_off), REG64(last_coeff_ctx_base),
|
||
13 years ago
|
"i"(offsetof(CABACContext, bytestream)),
|
||
13 years ago
|
"i"(offsetof(CABACContext, bytestream_end)),
|
||
13 years ago
|
"i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET) TABLES_ARG
|
||
9 years ago
|
: "%"FF_REG_c, "memory"
|
||
17 years ago
|
);
|
||
|
return coeff_count;
|
||
|
}
|
||
11 years ago
|
#endif /* HAVE_7REGS && BROKEN_COMPILER */
|
||
17 years ago
|
|
||
13 years ago
|
#endif /* HAVE_INLINE_ASM */
|