00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "libavutil/cpu.h"
00020 #include "libavutil/x86_cpu.h"
00021 #include "libavfilter/gradfun.h"
00022
00023 DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F};
00024 DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
00025
00026 void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers)
00027 {
00028 #if HAVE_MMX
00029 intptr_t x;
00030 if (width & 3) {
00031 x = width & ~3;
00032 ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2, width - x, thresh, dithers);
00033 width = x;
00034 }
00035 x = -width;
00036 __asm__ volatile(
00037 "movd %4, %%mm5 \n"
00038 "pxor %%mm7, %%mm7 \n"
00039 "pshufw $0, %%mm5, %%mm5 \n"
00040 "movq %6, %%mm6 \n"
00041 "movq %5, %%mm4 \n"
00042 "1: \n"
00043 "movd (%2,%0), %%mm0 \n"
00044 "movd (%3,%0), %%mm1 \n"
00045 "punpcklbw %%mm7, %%mm0 \n"
00046 "punpcklwd %%mm1, %%mm1 \n"
00047 "psllw $7, %%mm0 \n"
00048 "pxor %%mm2, %%mm2 \n"
00049 "psubw %%mm0, %%mm1 \n"
00050 "psubw %%mm1, %%mm2 \n"
00051 "pmaxsw %%mm1, %%mm2 \n"
00052 "pmulhuw %%mm5, %%mm2 \n"
00053 "psubw %%mm6, %%mm2 \n"
00054 "pminsw %%mm7, %%mm2 \n"
00055 "pmullw %%mm2, %%mm2 \n"
00056 "paddw %%mm4, %%mm0 \n"
00057 "pmulhw %%mm2, %%mm1 \n"
00058 "psllw $2, %%mm1 \n"
00059 "paddw %%mm1, %%mm0 \n"
00060 "psraw $7, %%mm0 \n"
00061 "packuswb %%mm0, %%mm0 \n"
00062 "movd %%mm0, (%1,%0) \n"
00063 "add $4, %0 \n"
00064 "jl 1b \n"
00065 "emms \n"
00066 :"+r"(x)
00067 :"r"(dst+width), "r"(src+width), "r"(dc+width/2),
00068 "rm"(thresh), "m"(*dithers), "m"(*pw_7f)
00069 :"memory"
00070 );
00071 #endif
00072 }
00073
00074 void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers)
00075 {
00076 #if HAVE_SSSE3
00077 intptr_t x;
00078 if (width & 7) {
00079
00080 x = width & ~7;
00081 ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2, width - x, thresh, dithers);
00082 width = x;
00083 }
00084 x = -width;
00085 __asm__ volatile(
00086 "movd %4, %%xmm5 \n"
00087 "pxor %%xmm7, %%xmm7 \n"
00088 "pshuflw $0,%%xmm5, %%xmm5 \n"
00089 "movdqa %6, %%xmm6 \n"
00090 "punpcklqdq %%xmm5, %%xmm5 \n"
00091 "movdqa %5, %%xmm4 \n"
00092 "1: \n"
00093 "movq (%2,%0), %%xmm0 \n"
00094 "movq (%3,%0), %%xmm1 \n"
00095 "punpcklbw %%xmm7, %%xmm0 \n"
00096 "punpcklwd %%xmm1, %%xmm1 \n"
00097 "psllw $7, %%xmm0 \n"
00098 "psubw %%xmm0, %%xmm1 \n"
00099 "pabsw %%xmm1, %%xmm2 \n"
00100 "pmulhuw %%xmm5, %%xmm2 \n"
00101 "psubw %%xmm6, %%xmm2 \n"
00102 "pminsw %%xmm7, %%xmm2 \n"
00103 "pmullw %%xmm2, %%xmm2 \n"
00104 "psllw $1, %%xmm2 \n"
00105 "paddw %%xmm4, %%xmm0 \n"
00106 "pmulhrsw %%xmm2, %%xmm1 \n"
00107 "paddw %%xmm1, %%xmm0 \n"
00108 "psraw $7, %%xmm0 \n"
00109 "packuswb %%xmm0, %%xmm0 \n"
00110 "movq %%xmm0, (%1,%0) \n"
00111 "add $8, %0 \n"
00112 "jl 1b \n"
00113 :"+&r"(x)
00114 :"r"(dst+width), "r"(src+width), "r"(dc+width/2),
00115 "rm"(thresh), "m"(*dithers), "m"(*pw_7f)
00116 :"memory"
00117 );
00118 #endif // HAVE_SSSE3
00119 }
00120
00121 void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width)
00122 {
00123 #if HAVE_SSE
00124 #define BLURV(load)\
00125 intptr_t x = -2*width;\
00126 __asm__ volatile(\
00127 "movdqa %6, %%xmm7 \n"\
00128 "1: \n"\
00129 load" (%4,%0), %%xmm0 \n"\
00130 load" (%5,%0), %%xmm1 \n"\
00131 "movdqa %%xmm0, %%xmm2 \n"\
00132 "movdqa %%xmm1, %%xmm3 \n"\
00133 "psrlw $8, %%xmm0 \n"\
00134 "psrlw $8, %%xmm1 \n"\
00135 "pand %%xmm7, %%xmm2 \n"\
00136 "pand %%xmm7, %%xmm3 \n"\
00137 "paddw %%xmm1, %%xmm0 \n"\
00138 "paddw %%xmm3, %%xmm2 \n"\
00139 "paddw %%xmm2, %%xmm0 \n"\
00140 "paddw (%2,%0), %%xmm0 \n"\
00141 "movdqa (%1,%0), %%xmm1 \n"\
00142 "movdqa %%xmm0, (%1,%0) \n"\
00143 "psubw %%xmm1, %%xmm0 \n"\
00144 "movdqa %%xmm0, (%3,%0) \n"\
00145 "add $16, %0 \n"\
00146 "jl 1b \n"\
00147 :"+&r"(x)\
00148 :"r"(buf+width),\
00149 "r"(buf1+width),\
00150 "r"(dc+width),\
00151 "r"(src+width*2),\
00152 "r"(src+width*2+src_linesize),\
00153 "m"(*pw_ff)\
00154 :"memory"\
00155 );
00156 if (((intptr_t) src | src_linesize) & 15) {
00157 BLURV("movdqu");
00158 } else {
00159 BLURV("movdqa");
00160 }
00161 #endif // HAVE_SSE
00162 }