mirror of https://github.com/FFmpeg/FFmpeg.git
parent
a7985cfd4c
commit
8d686ca59d
11 changed files with 245 additions and 125 deletions
@ -0,0 +1,64 @@ |
||||
/*
|
||||
* 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 |
||||
*/ |
||||
|
||||
#include <assert.h> |
||||
#include <stdint.h> |
||||
|
||||
#include "config.h" |
||||
#include "libavutil/attributes.h" |
||||
#include "avcodec.h" |
||||
#include "mpegvideoencdsp.h" |
||||
|
||||
static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], |
||||
int16_t basis[64], int scale) |
||||
{ |
||||
int i; |
||||
unsigned int sum = 0; |
||||
|
||||
for (i = 0; i < 8 * 8; i++) { |
||||
int b = rem[i] + ((basis[i] * scale + |
||||
(1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >> |
||||
(BASIS_SHIFT - RECON_SHIFT)); |
||||
int w = weight[i]; |
||||
b >>= RECON_SHIFT; |
||||
assert(-512 < b && b < 512); |
||||
|
||||
sum += (w * b) * (w * b) >> 4; |
||||
} |
||||
return sum >> 2; |
||||
} |
||||
|
||||
static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale) |
||||
{ |
||||
int i; |
||||
|
||||
for (i = 0; i < 8 * 8; i++) |
||||
rem[i] += (basis[i] * scale + |
||||
(1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >> |
||||
(BASIS_SHIFT - RECON_SHIFT); |
||||
} |
||||
|
||||
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, |
||||
AVCodecContext *avctx) |
||||
{ |
||||
c->try_8x8basis = try_8x8basis_c; |
||||
c->add_8x8basis = add_8x8basis_c; |
||||
|
||||
if (ARCH_X86) |
||||
ff_mpegvideoencdsp_init_x86(c, avctx); |
||||
} |
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* 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_MPEGVIDEOENCDSP_H |
||||
#define AVCODEC_MPEGVIDEOENCDSP_H |
||||
|
||||
#include <stdint.h> |
||||
|
||||
#include "avcodec.h" |
||||
|
||||
#define BASIS_SHIFT 16 |
||||
#define RECON_SHIFT 6 |
||||
|
||||
typedef struct MpegvideoEncDSPContext { |
||||
int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], |
||||
int16_t basis[64], int scale); |
||||
void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale); |
||||
|
||||
} MpegvideoEncDSPContext; |
||||
|
||||
void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, |
||||
AVCodecContext *avctx); |
||||
void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c, |
||||
AVCodecContext *avctx); |
||||
|
||||
#endif /* AVCODEC_MPEGVIDEOENCDSP_H */ |
@ -1,5 +1,5 @@ |
||||
/*
|
||||
* DSP utils : QNS functions are compiled 3 times for mmx/3dnow/ssse3 |
||||
* QNS functions are compiled 3 times for MMX/3DNOW/SSSE3 |
||||
* Copyright (c) 2004 Michael Niedermayer |
||||
* |
||||
* MMX optimization by Michael Niedermayer <michaelni@gmx.at> |
@ -0,0 +1,125 @@ |
||||
/*
|
||||
* 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 |
||||
*/ |
||||
|
||||
#include "libavutil/attributes.h" |
||||
#include "libavutil/cpu.h" |
||||
#include "libavutil/x86/cpu.h" |
||||
#include "libavcodec/avcodec.h" |
||||
#include "libavcodec/mpegvideoencdsp.h" |
||||
|
||||
#if HAVE_INLINE_ASM |
||||
|
||||
#define PHADDD(a, t) \ |
||||
"movq " #a ", " #t " \n\t" \
|
||||
"psrlq $32, " #a " \n\t" \
|
||||
"paddd " #t ", " #a " \n\t" |
||||
|
||||
/*
|
||||
* pmulhw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15])[16 - 31] |
||||
* pmulhrw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15] + 0x8000)[16 - 31] |
||||
* pmulhrsw: dst[0 - 15] = (src[0 - 15] * dst[0 - 15] + 0x4000)[15 - 30] |
||||
*/ |
||||
#define PMULHRW(x, y, s, o) \ |
||||
"pmulhw " #s ", " #x " \n\t" \
|
||||
"pmulhw " #s ", " #y " \n\t" \
|
||||
"paddw " #o ", " #x " \n\t" \
|
||||
"paddw " #o ", " #y " \n\t" \
|
||||
"psraw $1, " #x " \n\t" \
|
||||
"psraw $1, " #y " \n\t" |
||||
#define DEF(x) x ## _mmx |
||||
#define SET_RND MOVQ_WONE |
||||
#define SCALE_OFFSET 1 |
||||
|
||||
#include "mpegvideoenc_qns_template.c" |
||||
|
||||
#undef DEF |
||||
#undef SET_RND |
||||
#undef SCALE_OFFSET |
||||
#undef PMULHRW |
||||
|
||||
#define DEF(x) x ## _3dnow |
||||
#define SET_RND(x) |
||||
#define SCALE_OFFSET 0 |
||||
#define PMULHRW(x, y, s, o) \ |
||||
"pmulhrw " #s ", " #x " \n\t" \
|
||||
"pmulhrw " #s ", " #y " \n\t" |
||||
|
||||
#include "mpegvideoenc_qns_template.c" |
||||
|
||||
#undef DEF |
||||
#undef SET_RND |
||||
#undef SCALE_OFFSET |
||||
#undef PMULHRW |
||||
|
||||
#if HAVE_SSSE3_INLINE |
||||
#undef PHADDD |
||||
#define DEF(x) x ## _ssse3 |
||||
#define SET_RND(x) |
||||
#define SCALE_OFFSET -1 |
||||
|
||||
#define PHADDD(a, t) \ |
||||
"pshufw $0x0E, " #a ", " #t " \n\t" \
|
||||
/* faster than phaddd on core2 */ \
|
||||
"paddd " #t ", " #a " \n\t" |
||||
|
||||
#define PMULHRW(x, y, s, o) \ |
||||
"pmulhrsw " #s ", " #x " \n\t" \
|
||||
"pmulhrsw " #s ", " #y " \n\t" |
||||
|
||||
#include "mpegvideoenc_qns_template.c" |
||||
|
||||
#undef DEF |
||||
#undef SET_RND |
||||
#undef SCALE_OFFSET |
||||
#undef PMULHRW |
||||
#undef PHADDD |
||||
#endif /* HAVE_SSSE3_INLINE */ |
||||
|
||||
#endif /* HAVE_INLINE_ASM */ |
||||
|
||||
av_cold void ff_mpegvideoencdsp_init_x86(MpegvideoEncDSPContext *c, |
||||
AVCodecContext *avctx) |
||||
{ |
||||
#if HAVE_INLINE_ASM |
||||
int cpu_flags = av_get_cpu_flags(); |
||||
|
||||
if (INLINE_MMX(cpu_flags)) { |
||||
if (!(avctx->flags & CODEC_FLAG_BITEXACT)) { |
||||
c->try_8x8basis = try_8x8basis_mmx; |
||||
} |
||||
c->add_8x8basis = add_8x8basis_mmx; |
||||
} |
||||
|
||||
if (INLINE_AMD3DNOW(cpu_flags)) { |
||||
if (!(avctx->flags & CODEC_FLAG_BITEXACT)) { |
||||
c->try_8x8basis = try_8x8basis_3dnow; |
||||
} |
||||
c->add_8x8basis = add_8x8basis_3dnow; |
||||
} |
||||
|
||||
#if HAVE_SSSE3_INLINE |
||||
if (INLINE_SSSE3(cpu_flags)) { |
||||
if (!(avctx->flags & CODEC_FLAG_BITEXACT)) { |
||||
c->try_8x8basis = try_8x8basis_ssse3; |
||||
} |
||||
c->add_8x8basis = add_8x8basis_ssse3; |
||||
} |
||||
#endif /* HAVE_SSSE3_INLINE */ |
||||
|
||||
#endif /* HAVE_INLINE_ASM */ |
||||
} |
Loading…
Reference in new issue