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