2008-04-16 07:40:21 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2016-04-27 19:45:23 +02:00
|
|
|
* H.264 / AVC / MPEG-4 part10 codec.
|
2016-03-09 11:27:12 +02:00
|
|
|
* non-SIMD x86-specific optimizations for H.264
|
2008-04-16 07:40:21 +03:00
|
|
|
* @author Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*/
|
|
|
|
|
2011-06-20 03:54:32 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavcodec/cabac.h"
|
2011-06-20 12:53:41 +03:00
|
|
|
#include "cabac.h"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-06-22 20:46:52 +03:00
|
|
|
#if HAVE_INLINE_ASM
|
|
|
|
|
2014-11-15 19:10:53 +02:00
|
|
|
#if ARCH_X86_64
|
|
|
|
#define REG64 "r"
|
|
|
|
#else
|
|
|
|
#define REG64 "m"
|
|
|
|
#endif
|
|
|
|
|
2008-04-16 23:43:37 +03:00
|
|
|
//FIXME use some macros to avoid duplicating get_cabac (cannot be done yet
|
|
|
|
//as that would make optimization work hard)
|
2014-04-10 10:19:11 +03:00
|
|
|
#if HAVE_7REGS && !BROKEN_COMPILER
|
2012-06-22 20:52:27 +03:00
|
|
|
#define decode_significance decode_significance_x86
|
2008-04-16 23:43:37 +03:00
|
|
|
static int decode_significance_x86(CABACContext *c, int max_coeff,
|
|
|
|
uint8_t *significant_coeff_ctx_base,
|
2011-06-03 11:12:28 +03:00
|
|
|
int *index, x86_reg last_off){
|
2008-04-16 07:40:21 +03:00
|
|
|
void *end= significant_coeff_ctx_base + max_coeff - 1;
|
2011-06-20 12:24:26 +03:00
|
|
|
int minusstart= -(intptr_t)significant_coeff_ctx_base;
|
|
|
|
int minusindex= 4-(intptr_t)index;
|
2011-06-20 12:06:07 +03:00
|
|
|
int bit;
|
2011-06-20 11:23:26 +03:00
|
|
|
x86_reg coeff_count;
|
2012-04-27 23:12:19 +03:00
|
|
|
|
2012-04-27 23:12:20 +03:00
|
|
|
#ifdef BROKEN_RELOCATIONS
|
|
|
|
void *tables;
|
|
|
|
|
|
|
|
__asm__ volatile(
|
|
|
|
"lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
|
|
|
|
: "=&r"(tables)
|
2014-05-07 07:16:26 +03:00
|
|
|
: NAMED_CONSTRAINTS_ARRAY(ff_h264_cabac_tables)
|
2012-04-27 23:12:20 +03:00
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2012-03-17 19:04:32 +03:00
|
|
|
"3: \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-04-27 23:12:20 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
|
|
|
|
"%5", "%q5", "%k0", "%b0",
|
2012-08-12 04:18:41 +03:00
|
|
|
"%c11(%6)", "%c12(%6)",
|
|
|
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
|
|
|
"%13")
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:06:07 +03:00
|
|
|
"test $1, %4 \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
" jz 4f \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"add %10, %1 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-04-27 23:12:20 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%1)", "%3", "%w3",
|
|
|
|
"%5", "%q5", "%k0", "%b0",
|
2012-08-12 04:18:41 +03:00
|
|
|
"%c11(%6)", "%c12(%6)",
|
|
|
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
|
|
|
"%13")
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
"sub %10, %1 \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"mov %2, %0 \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"movl %7, %%ecx \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"add %1, %%"FF_REG_c" \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"movl %%ecx, (%0) \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:06:07 +03:00
|
|
|
"test $1, %4 \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
" jnz 5f \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2016-06-27 17:21:04 +02:00
|
|
|
"add"FF_OPSIZE" $4, %2 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-03-17 19:04:32 +03:00
|
|
|
"4: \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
"add $1, %1 \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"cmp %8, %1 \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
" jb 3b \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"mov %2, %0 \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"movl %7, %%ecx \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"add %1, %%"FF_REG_c" \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"movl %%ecx, (%0) \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
"5: \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"add %9, %k0 \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"shr $2, %k0 \n\t"
|
2012-03-17 19:02:44 +03:00
|
|
|
: "=&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),
|
2012-03-17 19:09:41 +03:00
|
|
|
"i"(offsetof(CABACContext, bytestream)),
|
2012-08-12 04:18:41 +03:00
|
|
|
"i"(offsetof(CABACContext, bytestream_end))
|
|
|
|
TABLES_ARG
|
2016-06-27 17:21:04 +02:00
|
|
|
: "%"FF_REG_c, "memory"
|
2008-04-16 07:40:21 +03:00
|
|
|
);
|
|
|
|
return coeff_count;
|
|
|
|
}
|
|
|
|
|
2012-06-22 20:52:27 +03:00
|
|
|
#define decode_significance_8x8 decode_significance_8x8_x86
|
2008-04-16 23:43:37 +03:00
|
|
|
static int decode_significance_8x8_x86(CABACContext *c,
|
|
|
|
uint8_t *significant_coeff_ctx_base,
|
2011-07-27 05:08:05 +03:00
|
|
|
int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){
|
2011-06-20 12:24:26 +03:00
|
|
|
int minusindex= 4-(intptr_t)index;
|
2011-06-20 12:06:07 +03:00
|
|
|
int bit;
|
2011-06-20 11:23:26 +03:00
|
|
|
x86_reg coeff_count;
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg last=0;
|
2011-06-20 12:20:15 +03:00
|
|
|
x86_reg state;
|
2012-04-27 23:12:19 +03:00
|
|
|
|
2012-04-27 23:12:20 +03:00
|
|
|
#ifdef BROKEN_RELOCATIONS
|
|
|
|
void *tables;
|
|
|
|
|
|
|
|
__asm__ volatile(
|
|
|
|
"lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t"
|
|
|
|
: "=&r"(tables)
|
2014-05-07 07:16:26 +03:00
|
|
|
: NAMED_CONSTRAINTS_ARRAY(ff_h264_cabac_tables)
|
2012-04-27 23:12:20 +03:00
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2011-06-20 12:20:15 +03:00
|
|
|
"mov %1, %6 \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
"3: \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:20:15 +03:00
|
|
|
"mov %10, %0 \n\t"
|
2014-11-15 19:10:53 +02:00
|
|
|
"movzb (%0, %6), %6 \n\t"
|
2011-06-20 12:20:15 +03:00
|
|
|
"add %9, %6 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-04-27 23:12:20 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
|
|
|
|
"%5", "%q5", "%k0", "%b0",
|
2012-08-12 04:18:41 +03:00
|
|
|
"%c12(%7)", "%c13(%7)",
|
|
|
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
|
|
|
"%15")
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2014-11-15 19:10:53 +02:00
|
|
|
"mov %1, %6 \n\t"
|
2011-06-20 12:06:07 +03:00
|
|
|
"test $1, %4 \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
" jz 4f \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-04-27 23:12:20 +03:00
|
|
|
#ifdef BROKEN_RELOCATIONS
|
2014-11-15 19:10:53 +02:00
|
|
|
"movzb %c14(%15, %q6), %6\n\t"
|
2012-04-27 23:12:20 +03:00
|
|
|
#else
|
2014-11-15 19:10:53 +02:00
|
|
|
"movzb "MANGLE(ff_h264_cabac_tables)"+%c14(%6), %6\n\t"
|
2012-04-27 23:12:20 +03:00
|
|
|
#endif
|
2011-06-20 12:20:15 +03:00
|
|
|
"add %11, %6 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-04-27 23:12:20 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%q4", "(%6)", "%3", "%w3",
|
|
|
|
"%5", "%q5", "%k0", "%b0",
|
2012-08-12 04:18:41 +03:00
|
|
|
"%c12(%7)", "%c13(%7)",
|
|
|
|
AV_STRINGIFY(H264_NORM_SHIFT_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_LPS_RANGE_OFFSET),
|
|
|
|
AV_STRINGIFY(H264_MLPS_STATE_OFFSET),
|
|
|
|
"%15")
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 11:23:26 +03:00
|
|
|
"mov %2, %0 \n\t"
|
2014-11-15 19:10:53 +02:00
|
|
|
"mov %1, %6 \n\t"
|
2014-12-03 23:39:00 +02:00
|
|
|
"mov %k6, (%0) \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:06:07 +03:00
|
|
|
"test $1, %4 \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
" jnz 5f \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2016-06-27 17:21:04 +02:00
|
|
|
"add"FF_OPSIZE" $4, %2 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-03-17 19:04:32 +03:00
|
|
|
"4: \n\t"
|
2014-11-15 19:10:53 +02:00
|
|
|
"add $1, %6 \n\t"
|
|
|
|
"mov %6, %1 \n\t"
|
|
|
|
"cmp $63, %6 \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
" jb 3b \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"mov %2, %0 \n\t"
|
2014-12-03 23:39:00 +02:00
|
|
|
"mov %k6, (%0) \n\t"
|
2012-03-17 19:04:32 +03:00
|
|
|
"5: \n\t"
|
2011-06-20 12:20:15 +03:00
|
|
|
"addl %8, %k0 \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"shr $2, %k0 \n\t"
|
2014-11-15 19:10:53 +02:00
|
|
|
: "=&q"(coeff_count), "+"REG64(last), "+"REG64(index), "+&r"(c->low),
|
2012-03-17 19:02:44 +03:00
|
|
|
"=&r"(bit), "+&r"(c->range), "=&r"(state)
|
|
|
|
: "r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base),
|
2014-11-15 19:10:53 +02:00
|
|
|
REG64(sig_off), REG64(last_coeff_ctx_base),
|
2012-03-17 19:09:41 +03:00
|
|
|
"i"(offsetof(CABACContext, bytestream)),
|
2012-04-27 23:12:19 +03:00
|
|
|
"i"(offsetof(CABACContext, bytestream_end)),
|
2012-04-27 23:12:20 +03:00
|
|
|
"i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET) TABLES_ARG
|
2016-06-27 17:21:04 +02:00
|
|
|
: "%"FF_REG_c, "memory"
|
2008-04-16 07:40:21 +03:00
|
|
|
);
|
|
|
|
return coeff_count;
|
|
|
|
}
|
2014-04-10 10:19:11 +03:00
|
|
|
#endif /* HAVE_7REGS && BROKEN_COMPILER */
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2012-06-22 20:46:52 +03:00
|
|
|
#endif /* HAVE_INLINE_ASM */
|