2011-06-20 12:53:41 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*
|
|
|
|
* This file is part of Libav.
|
|
|
|
*
|
|
|
|
* Libav 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.
|
|
|
|
*
|
|
|
|
* Libav 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 Libav; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVCODEC_X86_CABAC_H
|
|
|
|
#define AVCODEC_X86_CABAC_H
|
|
|
|
|
|
|
|
#include "libavcodec/cabac.h"
|
|
|
|
#include "libavutil/attributes.h"
|
|
|
|
#include "libavutil/x86_cpu.h"
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#if HAVE_FAST_CMOV
|
2012-03-17 19:03:22 +03:00
|
|
|
#define BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, range, tmp)\
|
2011-06-20 12:53:41 +03:00
|
|
|
"mov "tmp" , %%ecx \n\t"\
|
|
|
|
"shl $17 , "tmp" \n\t"\
|
|
|
|
"cmp "low" , "tmp" \n\t"\
|
|
|
|
"cmova %%ecx , "range" \n\t"\
|
|
|
|
"sbb %%ecx , %%ecx \n\t"\
|
|
|
|
"and %%ecx , "tmp" \n\t"\
|
2011-07-27 05:08:05 +03:00
|
|
|
"xor %%ecx , "ret" \n\t"\
|
|
|
|
"sub "tmp" , "low" \n\t"
|
2011-06-20 12:53:41 +03:00
|
|
|
#else /* HAVE_FAST_CMOV */
|
2012-03-17 19:03:22 +03:00
|
|
|
#define BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, range, tmp)\
|
2011-06-20 12:53:41 +03:00
|
|
|
"mov "tmp" , %%ecx \n\t"\
|
|
|
|
"shl $17 , "tmp" \n\t"\
|
|
|
|
"sub "low" , "tmp" \n\t"\
|
|
|
|
"sar $31 , "tmp" \n\t" /*lps_mask*/\
|
|
|
|
"sub %%ecx , "range" \n\t" /*RangeLPS - range*/\
|
|
|
|
"and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\
|
|
|
|
"add %%ecx , "range" \n\t" /*new range*/\
|
|
|
|
"shl $17 , %%ecx \n\t"\
|
|
|
|
"and "tmp" , %%ecx \n\t"\
|
|
|
|
"sub %%ecx , "low" \n\t"\
|
|
|
|
"xor "tmp" , "ret" \n\t"
|
|
|
|
#endif /* HAVE_FAST_CMOV */
|
|
|
|
|
2012-03-17 19:09:41 +03:00
|
|
|
#define BRANCHLESS_GET_CABAC(ret, statep, low, lowword, range, tmp, tmpbyte, byte, end) \
|
2011-06-20 12:53:41 +03:00
|
|
|
"movzbl "statep" , "ret" \n\t"\
|
|
|
|
"mov "range" , "tmp" \n\t"\
|
|
|
|
"and $0xC0 , "range" \n\t"\
|
|
|
|
"movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\
|
|
|
|
"sub "range" , "tmp" \n\t"\
|
2012-03-17 19:03:22 +03:00
|
|
|
BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, range, tmp) \
|
2011-06-20 12:53:41 +03:00
|
|
|
"movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
|
|
|
|
"shl %%cl , "range" \n\t"\
|
|
|
|
"movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
|
|
|
|
"shl %%cl , "low" \n\t"\
|
2011-07-27 05:08:05 +03:00
|
|
|
"mov "tmpbyte" , "statep" \n\t"\
|
2011-06-20 12:53:41 +03:00
|
|
|
"test "lowword" , "lowword" \n\t"\
|
2012-03-17 19:09:41 +03:00
|
|
|
" jnz 2f \n\t"\
|
2012-01-09 05:32:06 +03:00
|
|
|
"mov "byte" , %%"REG_c" \n\t"\
|
|
|
|
"add"OPSIZE" $2 , "byte" \n\t"\
|
2011-06-20 12:53:41 +03:00
|
|
|
"movzwl (%%"REG_c") , "tmp" \n\t"\
|
|
|
|
"lea -1("low") , %%ecx \n\t"\
|
|
|
|
"xor "low" , %%ecx \n\t"\
|
|
|
|
"shr $15 , %%ecx \n\t"\
|
2011-07-27 05:08:05 +03:00
|
|
|
"bswap "tmp" \n\t"\
|
|
|
|
"shr $15 , "tmp" \n\t"\
|
2011-06-20 12:53:41 +03:00
|
|
|
"movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
|
2011-07-27 05:08:05 +03:00
|
|
|
"sub $0xFFFF , "tmp" \n\t"\
|
2011-06-20 12:53:41 +03:00
|
|
|
"neg %%ecx \n\t"\
|
|
|
|
"add $7 , %%ecx \n\t"\
|
|
|
|
"shl %%cl , "tmp" \n\t"\
|
|
|
|
"add "tmp" , "low" \n\t"\
|
2012-03-17 19:09:41 +03:00
|
|
|
"2: \n\t"
|
2011-06-20 12:53:41 +03:00
|
|
|
|
2012-01-09 18:02:11 +03:00
|
|
|
|
2012-01-11 20:09:56 +03:00
|
|
|
#if HAVE_7REGS && !defined(BROKEN_RELOCATIONS) && !(defined(__i386) && defined(__clang__) && (__clang_major__<2 || (__clang_major__==2 && __clang_minor__<10)))\
|
|
|
|
&& !(defined(__i386) && !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1)
|
2011-06-20 12:53:41 +03:00
|
|
|
#define get_cabac_inline get_cabac_inline_x86
|
|
|
|
static av_always_inline int get_cabac_inline_x86(CABACContext *c,
|
|
|
|
uint8_t *const state)
|
|
|
|
{
|
2012-01-09 05:32:06 +03:00
|
|
|
int bit, tmp;
|
2011-06-20 12:53:41 +03:00
|
|
|
|
|
|
|
__asm__ volatile(
|
2012-03-17 19:02:44 +03:00
|
|
|
BRANCHLESS_GET_CABAC("%0", "(%4)", "%1", "%w1",
|
2012-03-17 19:09:41 +03:00
|
|
|
"%2", "%3", "%b3",
|
|
|
|
"%a6(%5)", "%a7(%5)")
|
2012-03-17 19:02:44 +03:00
|
|
|
: "=&r"(bit), "+&r"(c->low), "+&r"(c->range), "=&q"(tmp)
|
|
|
|
: "r"(state), "r"(c),
|
2012-03-17 19:09:41 +03:00
|
|
|
"i"(offsetof(CABACContext, bytestream)),
|
|
|
|
"i"(offsetof(CABACContext, bytestream_end))
|
2011-06-20 12:53:41 +03:00
|
|
|
: "%"REG_c, "memory"
|
|
|
|
);
|
|
|
|
return bit & 1;
|
|
|
|
}
|
2011-12-12 15:48:53 +03:00
|
|
|
#endif /* HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */
|
2011-06-20 12:53:41 +03:00
|
|
|
|
|
|
|
#define get_cabac_bypass_sign get_cabac_bypass_sign_x86
|
|
|
|
static av_always_inline int get_cabac_bypass_sign_x86(CABACContext *c, int val)
|
|
|
|
{
|
|
|
|
x86_reg tmp;
|
|
|
|
__asm__ volatile(
|
2012-03-17 18:58:48 +03:00
|
|
|
"movl %a6(%2), %k1 \n\t"
|
2012-03-17 19:32:03 +03:00
|
|
|
"movl %a3(%2), %%eax \n\t"
|
|
|
|
"shl $17, %k1 \n\t"
|
|
|
|
"add %%eax, %%eax \n\t"
|
|
|
|
"sub %k1, %%eax \n\t"
|
|
|
|
"cltd \n\t"
|
|
|
|
"and %%edx, %k1 \n\t"
|
|
|
|
"add %k1, %%eax \n\t"
|
|
|
|
"xor %%edx, %%ecx \n\t"
|
|
|
|
"sub %%edx, %%ecx \n\t"
|
|
|
|
"test %%ax, %%ax \n\t"
|
|
|
|
"jnz 1f \n\t"
|
|
|
|
"mov %a4(%2), %1 \n\t"
|
|
|
|
"subl $0xFFFF, %%eax \n\t"
|
|
|
|
"movzwl (%1), %%edx \n\t"
|
|
|
|
"bswap %%edx \n\t"
|
|
|
|
"shrl $15, %%edx \n\t"
|
2012-03-29 02:41:04 +03:00
|
|
|
"add $2, %1 \n\t"
|
2012-03-17 19:32:03 +03:00
|
|
|
"addl %%edx, %%eax \n\t"
|
2012-03-29 02:41:04 +03:00
|
|
|
"mov %1, %a4(%2) \n\t"
|
2012-03-17 19:32:03 +03:00
|
|
|
"1: \n\t"
|
|
|
|
"movl %%eax, %a3(%2) \n\t"
|
2011-06-20 12:53:41 +03:00
|
|
|
|
2012-03-17 08:41:17 +03:00
|
|
|
: "+c"(val), "=&r"(tmp)
|
|
|
|
: "r"(c),
|
|
|
|
"i"(offsetof(CABACContext, low)),
|
|
|
|
"i"(offsetof(CABACContext, bytestream)),
|
2012-03-17 18:58:48 +03:00
|
|
|
"i"(offsetof(CABACContext, bytestream_end)),
|
2012-03-17 08:41:17 +03:00
|
|
|
"i"(offsetof(CABACContext, range))
|
|
|
|
: "%eax", "%edx", "memory"
|
2011-06-20 12:53:41 +03:00
|
|
|
);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* AVCODEC_X86_CABAC_H */
|