mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-12 19:18:44 +02:00
d7463c6813
* commit 'fab9df63a3156ffe1f9490aafaea41e03ef60ddf': dsputil: Split off global motion compensation bits into a separate context Conflicts: libavcodec/dsputil.c libavcodec/dsputil.h libavcodec/ppc/dsputil_altivec.h libavcodec/x86/dsputil_init.c libavcodec/x86/dsputil_mmx.c libavcodec/x86/dsputil_x86.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
251 lines
9.5 KiB
C
251 lines
9.5 KiB
C
/*
|
|
* MMX optimized DSP utils
|
|
* Copyright (c) 2000, 2001 Fabrice Bellard
|
|
* Copyright (c) 2002-2004 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
|
|
*
|
|
* MMX optimization by Nick Kurshev <nickols_k@mail.ru>
|
|
*/
|
|
|
|
#include "config.h"
|
|
#include "libavutil/avassert.h"
|
|
#include "libavutil/cpu.h"
|
|
#include "libavutil/x86/asm.h"
|
|
#include "libavcodec/pixels.h"
|
|
#include "libavcodec/videodsp.h"
|
|
#include "dsputil_x86.h"
|
|
#include "inline_asm.h"
|
|
|
|
#if HAVE_INLINE_ASM
|
|
|
|
void ff_put_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
|
|
int line_size)
|
|
{
|
|
const int16_t *p;
|
|
uint8_t *pix;
|
|
|
|
/* read the pixels */
|
|
p = block;
|
|
pix = pixels;
|
|
/* unrolled loop */
|
|
__asm__ volatile (
|
|
"movq (%3), %%mm0 \n\t"
|
|
"movq 8(%3), %%mm1 \n\t"
|
|
"movq 16(%3), %%mm2 \n\t"
|
|
"movq 24(%3), %%mm3 \n\t"
|
|
"movq 32(%3), %%mm4 \n\t"
|
|
"movq 40(%3), %%mm5 \n\t"
|
|
"movq 48(%3), %%mm6 \n\t"
|
|
"movq 56(%3), %%mm7 \n\t"
|
|
"packuswb %%mm1, %%mm0 \n\t"
|
|
"packuswb %%mm3, %%mm2 \n\t"
|
|
"packuswb %%mm5, %%mm4 \n\t"
|
|
"packuswb %%mm7, %%mm6 \n\t"
|
|
"movq %%mm0, (%0) \n\t"
|
|
"movq %%mm2, (%0, %1) \n\t"
|
|
"movq %%mm4, (%0, %1, 2) \n\t"
|
|
"movq %%mm6, (%0, %2) \n\t"
|
|
:: "r" (pix), "r" ((x86_reg) line_size), "r" ((x86_reg) line_size * 3),
|
|
"r" (p)
|
|
: "memory");
|
|
pix += line_size * 4;
|
|
p += 32;
|
|
|
|
// if here would be an exact copy of the code above
|
|
// compiler would generate some very strange code
|
|
// thus using "r"
|
|
__asm__ volatile (
|
|
"movq (%3), %%mm0 \n\t"
|
|
"movq 8(%3), %%mm1 \n\t"
|
|
"movq 16(%3), %%mm2 \n\t"
|
|
"movq 24(%3), %%mm3 \n\t"
|
|
"movq 32(%3), %%mm4 \n\t"
|
|
"movq 40(%3), %%mm5 \n\t"
|
|
"movq 48(%3), %%mm6 \n\t"
|
|
"movq 56(%3), %%mm7 \n\t"
|
|
"packuswb %%mm1, %%mm0 \n\t"
|
|
"packuswb %%mm3, %%mm2 \n\t"
|
|
"packuswb %%mm5, %%mm4 \n\t"
|
|
"packuswb %%mm7, %%mm6 \n\t"
|
|
"movq %%mm0, (%0) \n\t"
|
|
"movq %%mm2, (%0, %1) \n\t"
|
|
"movq %%mm4, (%0, %1, 2) \n\t"
|
|
"movq %%mm6, (%0, %2) \n\t"
|
|
:: "r" (pix), "r" ((x86_reg) line_size), "r" ((x86_reg) line_size * 3),
|
|
"r" (p)
|
|
: "memory");
|
|
}
|
|
|
|
void ff_add_pixels_clamped_mmx(const int16_t *block, uint8_t *pixels,
|
|
int line_size)
|
|
{
|
|
const int16_t *p;
|
|
uint8_t *pix;
|
|
int i;
|
|
|
|
/* read the pixels */
|
|
p = block;
|
|
pix = pixels;
|
|
MOVQ_ZERO(mm7);
|
|
i = 4;
|
|
do {
|
|
__asm__ volatile (
|
|
"movq (%2), %%mm0 \n\t"
|
|
"movq 8(%2), %%mm1 \n\t"
|
|
"movq 16(%2), %%mm2 \n\t"
|
|
"movq 24(%2), %%mm3 \n\t"
|
|
"movq %0, %%mm4 \n\t"
|
|
"movq %1, %%mm6 \n\t"
|
|
"movq %%mm4, %%mm5 \n\t"
|
|
"punpcklbw %%mm7, %%mm4 \n\t"
|
|
"punpckhbw %%mm7, %%mm5 \n\t"
|
|
"paddsw %%mm4, %%mm0 \n\t"
|
|
"paddsw %%mm5, %%mm1 \n\t"
|
|
"movq %%mm6, %%mm5 \n\t"
|
|
"punpcklbw %%mm7, %%mm6 \n\t"
|
|
"punpckhbw %%mm7, %%mm5 \n\t"
|
|
"paddsw %%mm6, %%mm2 \n\t"
|
|
"paddsw %%mm5, %%mm3 \n\t"
|
|
"packuswb %%mm1, %%mm0 \n\t"
|
|
"packuswb %%mm3, %%mm2 \n\t"
|
|
"movq %%mm0, %0 \n\t"
|
|
"movq %%mm2, %1 \n\t"
|
|
: "+m" (*pix), "+m" (*(pix + line_size))
|
|
: "r" (p)
|
|
: "memory");
|
|
pix += line_size * 2;
|
|
p += 16;
|
|
} while (--i);
|
|
}
|
|
|
|
/* Draw the edges of width 'w' of an image of size width, height
|
|
* this MMX version can only handle w == 8 || w == 16. */
|
|
void ff_draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
|
|
int w, int h, int sides)
|
|
{
|
|
uint8_t *ptr, *last_line;
|
|
int i;
|
|
|
|
last_line = buf + (height - 1) * wrap;
|
|
/* left and right */
|
|
ptr = buf;
|
|
if (w == 8) {
|
|
__asm__ volatile (
|
|
"1: \n\t"
|
|
"movd (%0), %%mm0 \n\t"
|
|
"punpcklbw %%mm0, %%mm0 \n\t"
|
|
"punpcklwd %%mm0, %%mm0 \n\t"
|
|
"punpckldq %%mm0, %%mm0 \n\t"
|
|
"movq %%mm0, -8(%0) \n\t"
|
|
"movq -8(%0, %2), %%mm1 \n\t"
|
|
"punpckhbw %%mm1, %%mm1 \n\t"
|
|
"punpckhwd %%mm1, %%mm1 \n\t"
|
|
"punpckhdq %%mm1, %%mm1 \n\t"
|
|
"movq %%mm1, (%0, %2) \n\t"
|
|
"add %1, %0 \n\t"
|
|
"cmp %3, %0 \n\t"
|
|
"jb 1b \n\t"
|
|
: "+r" (ptr)
|
|
: "r" ((x86_reg) wrap), "r" ((x86_reg) width),
|
|
"r" (ptr + wrap * height));
|
|
} else if (w == 16) {
|
|
__asm__ volatile (
|
|
"1: \n\t"
|
|
"movd (%0), %%mm0 \n\t"
|
|
"punpcklbw %%mm0, %%mm0 \n\t"
|
|
"punpcklwd %%mm0, %%mm0 \n\t"
|
|
"punpckldq %%mm0, %%mm0 \n\t"
|
|
"movq %%mm0, -8(%0) \n\t"
|
|
"movq %%mm0, -16(%0) \n\t"
|
|
"movq -8(%0, %2), %%mm1 \n\t"
|
|
"punpckhbw %%mm1, %%mm1 \n\t"
|
|
"punpckhwd %%mm1, %%mm1 \n\t"
|
|
"punpckhdq %%mm1, %%mm1 \n\t"
|
|
"movq %%mm1, (%0, %2) \n\t"
|
|
"movq %%mm1, 8(%0, %2) \n\t"
|
|
"add %1, %0 \n\t"
|
|
"cmp %3, %0 \n\t"
|
|
"jb 1b \n\t"
|
|
: "+r"(ptr)
|
|
: "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
|
|
);
|
|
} else {
|
|
av_assert1(w == 4);
|
|
__asm__ volatile (
|
|
"1: \n\t"
|
|
"movd (%0), %%mm0 \n\t"
|
|
"punpcklbw %%mm0, %%mm0 \n\t"
|
|
"punpcklwd %%mm0, %%mm0 \n\t"
|
|
"movd %%mm0, -4(%0) \n\t"
|
|
"movd -4(%0, %2), %%mm1 \n\t"
|
|
"punpcklbw %%mm1, %%mm1 \n\t"
|
|
"punpckhwd %%mm1, %%mm1 \n\t"
|
|
"punpckhdq %%mm1, %%mm1 \n\t"
|
|
"movd %%mm1, (%0, %2) \n\t"
|
|
"add %1, %0 \n\t"
|
|
"cmp %3, %0 \n\t"
|
|
"jb 1b \n\t"
|
|
: "+r" (ptr)
|
|
: "r" ((x86_reg) wrap), "r" ((x86_reg) width),
|
|
"r" (ptr + wrap * height));
|
|
}
|
|
|
|
/* top and bottom (and hopefully also the corners) */
|
|
if (sides & EDGE_TOP) {
|
|
for (i = 0; i < h; i += 4) {
|
|
ptr = buf - (i + 1) * wrap - w;
|
|
__asm__ volatile (
|
|
"1: \n\t"
|
|
"movq (%1, %0), %%mm0 \n\t"
|
|
"movq %%mm0, (%0) \n\t"
|
|
"movq %%mm0, (%0, %2) \n\t"
|
|
"movq %%mm0, (%0, %2, 2) \n\t"
|
|
"movq %%mm0, (%0, %3) \n\t"
|
|
"add $8, %0 \n\t"
|
|
"cmp %4, %0 \n\t"
|
|
"jb 1b \n\t"
|
|
: "+r" (ptr)
|
|
: "r" ((x86_reg) buf - (x86_reg) ptr - w),
|
|
"r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3),
|
|
"r" (ptr + width + 2 * w));
|
|
}
|
|
}
|
|
|
|
if (sides & EDGE_BOTTOM) {
|
|
for (i = 0; i < h; i += 4) {
|
|
ptr = last_line + (i + 1) * wrap - w;
|
|
__asm__ volatile (
|
|
"1: \n\t"
|
|
"movq (%1, %0), %%mm0 \n\t"
|
|
"movq %%mm0, (%0) \n\t"
|
|
"movq %%mm0, (%0, %2) \n\t"
|
|
"movq %%mm0, (%0, %2, 2) \n\t"
|
|
"movq %%mm0, (%0, %3) \n\t"
|
|
"add $8, %0 \n\t"
|
|
"cmp %4, %0 \n\t"
|
|
"jb 1b \n\t"
|
|
: "+r" (ptr)
|
|
: "r" ((x86_reg) last_line - (x86_reg) ptr - w),
|
|
"r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3),
|
|
"r" (ptr + width + 2 * w));
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif /* HAVE_INLINE_ASM */
|