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>
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* This file is part of Libav.
|
2008-04-16 07:40:21 +03:00
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2008-04-16 07:40:21 +03:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2008-04-16 07:40:21 +03:00
|
|
|
* 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
|
2011-03-18 19:35:10 +02:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2008-04-16 07:40:21 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2008-04-16 07:40:21 +03:00
|
|
|
* H.264 / AVC / MPEG4 part10 codec.
|
|
|
|
* non-MMX i386-specific optimizations for H.264
|
|
|
|
* @author Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*/
|
|
|
|
|
2008-12-22 11:12:42 +02:00
|
|
|
#ifndef AVCODEC_X86_H264_I386_H
|
|
|
|
#define AVCODEC_X86_H264_I386_H
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 03:54:32 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavcodec/cabac.h"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
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)
|
2011-06-20 04:31:53 +03:00
|
|
|
#if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS)
|
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;
|
|
|
|
int minusstart= -(int)significant_coeff_ctx_base;
|
|
|
|
int minusindex= 4-(int)index;
|
2011-06-20 12:06:07 +03:00
|
|
|
int bit;
|
2011-06-20 11:23:26 +03:00
|
|
|
x86_reg coeff_count;
|
2011-06-20 04:31:53 +03:00
|
|
|
int low;
|
2011-06-20 12:12:29 +03:00
|
|
|
int range;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2011-06-20 12:12:29 +03:00
|
|
|
"movl %a11(%6), %5 \n\t"
|
|
|
|
"movl %a12(%6), %3 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
|
|
|
"2: \n\t"
|
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
|
|
|
|
"%w3", "%5", "%k0", "%b0", "%a13")
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:06:07 +03:00
|
|
|
"test $1, %4 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
" jz 3f \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"add %10, %1 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%6", "(%1)", "%3",
|
|
|
|
"%w3", "%5", "%k0", "%b0", "%a13")
|
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"
|
2008-04-16 07:40:21 +03:00
|
|
|
"add %1, %%"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"
|
2008-04-16 07:40:21 +03:00
|
|
|
" jnz 4f \n\t"
|
|
|
|
|
2011-06-20 11:23:26 +03:00
|
|
|
"add $4, %0 \n\t"
|
|
|
|
"mov %0, %2 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
|
|
|
"3: \n\t"
|
|
|
|
"add $1, %1 \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"cmp %8, %1 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
" jb 2b \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"
|
2008-04-16 07:40:21 +03:00
|
|
|
"add %1, %%"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
|
|
|
"4: \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"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
"movl %5, %a11(%6) \n\t"
|
|
|
|
"movl %3, %a12(%6) \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
:"=&r"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index),
|
2011-06-20 12:12:29 +03:00
|
|
|
"=&r"(low), "=&r"(bit), "=&r"(range)
|
2011-06-20 03:54:32 +03:00
|
|
|
:"r"(c), "m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off),
|
|
|
|
"i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
|
|
|
|
"i"(offsetof(CABACContext, bytestream))
|
2011-06-20 12:12:29 +03:00
|
|
|
: "%"REG_c, "memory"
|
2008-04-16 07:40:21 +03:00
|
|
|
);
|
|
|
|
return coeff_count;
|
|
|
|
}
|
|
|
|
|
2008-04-16 23:43:37 +03:00
|
|
|
static int decode_significance_8x8_x86(CABACContext *c,
|
|
|
|
uint8_t *significant_coeff_ctx_base,
|
2011-06-03 11:12:28 +03:00
|
|
|
int *index, x86_reg last_off, const uint8_t *sig_off){
|
2008-04-16 07:40:21 +03:00
|
|
|
int minusindex= 4-(int)index;
|
2011-06-20 12:06:07 +03:00
|
|
|
int bit;
|
2011-06-20 11:23:26 +03:00
|
|
|
x86_reg coeff_count;
|
2011-06-20 04:31:53 +03:00
|
|
|
int low;
|
2011-06-20 12:12:29 +03:00
|
|
|
int range;
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg last=0;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2011-06-20 12:12:29 +03:00
|
|
|
"movl %a11(%6), %5 \n\t"
|
|
|
|
"movl %a12(%6), %3 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
|
|
|
"mov %1, %%"REG_D" \n\t"
|
|
|
|
"2: \n\t"
|
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
"mov %9, %0 \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"movzbl (%0, %%"REG_D"), %%edi \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"add %8, %%"REG_D" \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%6", "(%%"REG_D")", "%3",
|
|
|
|
"%w3", "%5", "%k0", "%b0", "%a13")
|
2008-04-16 07:40:21 +03:00
|
|
|
|
|
|
|
"mov %1, %%edi \n\t"
|
2011-06-20 12:06:07 +03:00
|
|
|
"test $1, %4 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
" jz 3f \n\t"
|
|
|
|
|
|
|
|
"movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"add %8, %%"REG_D" \n\t"
|
|
|
|
"add %10, %%"REG_D" \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%4", "%6", "(%%"REG_D")", "%3",
|
|
|
|
"%w3", "%5", "%k0", "%b0", "%a13")
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 11:23:26 +03:00
|
|
|
"mov %2, %0 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
"mov %1, %%edi \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"movl %%edi, (%0) \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:06:07 +03:00
|
|
|
"test $1, %4 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
" jnz 4f \n\t"
|
|
|
|
|
2011-06-20 11:23:26 +03:00
|
|
|
"add $4, %0 \n\t"
|
|
|
|
"mov %0, %2 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
|
|
|
"3: \n\t"
|
|
|
|
"addl $1, %%edi \n\t"
|
|
|
|
"mov %%edi, %1 \n\t"
|
|
|
|
"cmpl $63, %%edi \n\t"
|
|
|
|
" jb 2b \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"mov %2, %0 \n\t"
|
|
|
|
"movl %%edi, (%0) \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
"4: \n\t"
|
2011-06-20 12:12:29 +03:00
|
|
|
"addl %7, %k0 \n\t"
|
2011-06-20 11:23:26 +03:00
|
|
|
"shr $2, %k0 \n\t"
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2011-06-20 12:12:29 +03:00
|
|
|
"movl %5, %a11(%6) \n\t"
|
|
|
|
"movl %3, %a12(%6) \n\t"
|
|
|
|
:"=&r"(coeff_count),"+m"(last), "+m"(index), "=&r"(low), "=&r"(bit),
|
|
|
|
"=&r"(range)
|
2011-06-20 03:54:32 +03:00
|
|
|
:"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_off),
|
|
|
|
"i"(offsetof(CABACContext, range)), "i"(offsetof(CABACContext, low)),
|
|
|
|
"i"(offsetof(CABACContext, bytestream))
|
2011-06-20 12:12:29 +03:00
|
|
|
: "%"REG_c, "%"REG_D, "memory"
|
2008-04-16 07:40:21 +03:00
|
|
|
);
|
|
|
|
return coeff_count;
|
|
|
|
}
|
2011-06-20 04:31:53 +03:00
|
|
|
#endif /* ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
|
2008-04-16 07:40:21 +03:00
|
|
|
|
2008-12-22 11:12:42 +02:00
|
|
|
#endif /* AVCODEC_X86_H264_I386_H */
|