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