📄 vc1dsp_mmx.c.svn-base
字号:
/* * VC-1 and WMV3 - DSP functions MMX-optimized * Copyright (c) 2007 Christophe GISQUET <christophe.gisquet@free.fr> * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */#include "dsputil.h"#include "dsputil_mmx.h"#include "x86_cpu.h"/** Add rounder from mm7 to mm3 and pack result at destination */#define NORMALIZE_MMX(SHIFT) \ "paddw %%mm7, %%mm3 \n\t" /* +bias-r */ \ "paddw %%mm7, %%mm4 \n\t" /* +bias-r */ \ "psraw "SHIFT", %%mm3 \n\t" \ "psraw "SHIFT", %%mm4 \n\t"#define TRANSFER_DO_PACK \ "packuswb %%mm4, %%mm3 \n\t" \ "movq %%mm3, (%2) \n\t"#define TRANSFER_DONT_PACK \ "movq %%mm3, 0(%2) \n\t" \ "movq %%mm4, 8(%2) \n\t"/** @see MSPEL_FILTER13_CORE for use as UNPACK macro */#define DO_UNPACK(reg) "punpcklbw %%mm0, " reg "\n\t"#define DONT_UNPACK(reg)/** Compute the rounder 32-r or 8-r and unpacks it to mm7 */#define LOAD_ROUNDER_MMX(ROUND) \ "movd "ROUND", %%mm7 \n\t" \ "punpcklwd %%mm7, %%mm7 \n\t" \ "punpckldq %%mm7, %%mm7 \n\t"#define SHIFT2_LINE(OFF, R0,R1,R2,R3) \ "paddw %%mm"#R2", %%mm"#R1" \n\t" \ "movd (%0,%3), %%mm"#R0" \n\t" \ "pmullw %%mm6, %%mm"#R1" \n\t" \ "punpcklbw %%mm0, %%mm"#R0" \n\t" \ "movd (%0,%2), %%mm"#R3" \n\t" \ "psubw %%mm"#R0", %%mm"#R1" \n\t" \ "punpcklbw %%mm0, %%mm"#R3" \n\t" \ "paddw %%mm7, %%mm"#R1" \n\t" \ "psubw %%mm"#R3", %%mm"#R1" \n\t" \ "psraw %4, %%mm"#R1" \n\t" \ "movq %%mm"#R1", "#OFF"(%1) \n\t" \ "add %2, %0 \n\t"DECLARE_ALIGNED_16(const uint64_t, ff_pw_9) = 0x0009000900090009ULL;/** Sacrifying mm6 allows to pipeline loads from src */static void vc1_put_ver_16b_shift2_mmx(int16_t *dst, const uint8_t *src, long int stride, int rnd, int64_t shift){ asm volatile( "mov $3, %%"REG_c" \n\t" LOAD_ROUNDER_MMX("%5") "movq "MANGLE(ff_pw_9)", %%mm6 \n\t" "1: \n\t" "movd (%0), %%mm2 \n\t" "add %2, %0 \n\t" "movd (%0), %%mm3 \n\t" "punpcklbw %%mm0, %%mm2 \n\t" "punpcklbw %%mm0, %%mm3 \n\t" SHIFT2_LINE( 0, 1, 2, 3, 4) SHIFT2_LINE( 24, 2, 3, 4, 1) SHIFT2_LINE( 48, 3, 4, 1, 2) SHIFT2_LINE( 72, 4, 1, 2, 3) SHIFT2_LINE( 96, 1, 2, 3, 4) SHIFT2_LINE(120, 2, 3, 4, 1) SHIFT2_LINE(144, 3, 4, 1, 2) SHIFT2_LINE(168, 4, 1, 2, 3) "sub %6, %0 \n\t" "add $8, %1 \n\t" "dec %%"REG_c" \n\t" "jnz 1b \n\t" : "+r"(src), "+r"(dst) : "r"(stride), "r"(-2*stride), "m"(shift), "m"(rnd), "r"(9*stride-4) : "%"REG_c, "memory" );}/** * Data is already unpacked, so some operations can directly be made from * memory. */static void vc1_put_hor_16b_shift2_mmx(uint8_t *dst, long int stride, const int16_t *src, int rnd){ int h = 8; src -= 1; rnd -= (-1+9+9-1)*1024; /* Add -1024 bias */ asm volatile( LOAD_ROUNDER_MMX("%4") "movq "MANGLE(ff_pw_128)", %%mm6\n\t" "movq "MANGLE(ff_pw_9)", %%mm5 \n\t" "1: \n\t" "movq 2*0+0(%1), %%mm1 \n\t" "movq 2*0+8(%1), %%mm2 \n\t" "movq 2*1+0(%1), %%mm3 \n\t" "movq 2*1+8(%1), %%mm4 \n\t" "paddw 2*3+0(%1), %%mm1 \n\t" "paddw 2*3+8(%1), %%mm2 \n\t" "paddw 2*2+0(%1), %%mm3 \n\t" "paddw 2*2+8(%1), %%mm4 \n\t" "pmullw %%mm5, %%mm3 \n\t" "pmullw %%mm5, %%mm4 \n\t" "psubw %%mm1, %%mm3 \n\t" "psubw %%mm2, %%mm4 \n\t" NORMALIZE_MMX("$7") /* Remove bias */ "paddw %%mm6, %%mm3 \n\t" "paddw %%mm6, %%mm4 \n\t" TRANSFER_DO_PACK "add $24, %1 \n\t" "add %3, %2 \n\t" "decl %0 \n\t" "jnz 1b \n\t" : "+r"(h), "+r" (src), "+r" (dst) : "r"(stride), "m"(rnd) : "memory" );}/** * Purely vertical or horizontal 1/2 shift interpolation. * Sacrify mm6 for *9 factor. */static void vc1_put_shift2_mmx(uint8_t *dst, const uint8_t *src, long int stride, int rnd, long int offset){ rnd = 8-rnd; asm volatile( "mov $8, %%"REG_c" \n\t" LOAD_ROUNDER_MMX("%5") "movq "MANGLE(ff_pw_9)", %%mm6\n\t" "1: \n\t" "movd 0(%0 ), %%mm3 \n\t" "movd 4(%0 ), %%mm4 \n\t" "movd 0(%0,%2), %%mm1 \n\t" "movd 4(%0,%2), %%mm2 \n\t" "add %2, %0 \n\t" "punpcklbw %%mm0, %%mm3 \n\t" "punpcklbw %%mm0, %%mm4 \n\t" "punpcklbw %%mm0, %%mm1 \n\t" "punpcklbw %%mm0, %%mm2 \n\t" "paddw %%mm1, %%mm3 \n\t" "paddw %%mm2, %%mm4 \n\t" "movd 0(%0,%3), %%mm1 \n\t" "movd 4(%0,%3), %%mm2 \n\t" "pmullw %%mm6, %%mm3 \n\t" /* 0,9,9,0*/ "pmullw %%mm6, %%mm4 \n\t" /* 0,9,9,0*/ "punpcklbw %%mm0, %%mm1 \n\t" "punpcklbw %%mm0, %%mm2 \n\t" "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,0*/ "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,0*/ "movd 0(%0,%2), %%mm1 \n\t" "movd 4(%0,%2), %%mm2 \n\t" "punpcklbw %%mm0, %%mm1 \n\t" "punpcklbw %%mm0, %%mm2 \n\t" "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,-1*/ "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,-1*/ NORMALIZE_MMX("$4") "packuswb %%mm4, %%mm3 \n\t" "movq %%mm3, (%1) \n\t" "add %6, %0 \n\t" "add %4, %1 \n\t" "dec %%"REG_c" \n\t" "jnz 1b \n\t" : "+r"(src), "+r"(dst) : "r"(offset), "r"(-2*offset), "g"(stride), "m"(rnd), "g"(stride-offset) : "%"REG_c, "memory" );}/** * Filter coefficients made global to allow access by all 1 or 3 quarter shift * interpolation functions. */DECLARE_ALIGNED_16(const uint64_t, ff_pw_53) = 0x0035003500350035ULL;DECLARE_ALIGNED_16(const uint64_t, ff_pw_18) = 0x0012001200120012ULL;/** * Core of the 1/4 and 3/4 shift bicubic interpolation. * * @param UNPACK Macro unpacking arguments from 8 to 16bits (can be empty). * @param MOVQ "movd 1" or "movq 2", if data read is already unpacked. * @param A1 Address of 1st tap (beware of unpacked/packed). * @param A2 Address of 2nd tap * @param A3 Address of 3rd tap * @param A4 Address of 4th tap */#define MSPEL_FILTER13_CORE(UNPACK, MOVQ, A1, A2, A3, A4) \ MOVQ "*0+"A1", %%mm1 \n\t" \ MOVQ "*4+"A1", %%mm2 \n\t" \ UNPACK("%%mm1") \ UNPACK("%%mm2") \ "pmullw "MANGLE(ff_pw_3)", %%mm1\n\t" \ "pmullw "MANGLE(ff_pw_3)", %%mm2\n\t" \ MOVQ "*0+"A2", %%mm3 \n\t" \ MOVQ "*4+"A2", %%mm4 \n\t" \ UNPACK("%%mm3") \ UNPACK("%%mm4") \ "pmullw %%mm6, %%mm3 \n\t" /* *18 */ \ "pmullw %%mm6, %%mm4 \n\t" /* *18 */ \ "psubw %%mm1, %%mm3 \n\t" /* 18,-3 */ \ "psubw %%mm2, %%mm4 \n\t" /* 18,-3 */ \ MOVQ "*0+"A4", %%mm1 \n\t" \ MOVQ "*4+"A4", %%mm2 \n\t" \ UNPACK("%%mm1") \ UNPACK("%%mm2") \ "psllw $2, %%mm1 \n\t" /* 4* */ \ "psllw $2, %%mm2 \n\t" /* 4* */ \ "psubw %%mm1, %%mm3 \n\t" /* -4,18,-3 */ \ "psubw %%mm2, %%mm4 \n\t" /* -4,18,-3 */ \ MOVQ "*0+"A3", %%mm1 \n\t" \ MOVQ "*4+"A3", %%mm2 \n\t" \ UNPACK("%%mm1") \ UNPACK("%%mm2") \ "pmullw %%mm5, %%mm1 \n\t" /* *53 */ \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -