-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvf_yadif_template.h
More file actions
245 lines (235 loc) · 10.4 KB
/
Copy pathvf_yadif_template.h
File metadata and controls
245 lines (235 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
*
* SSE2/SSSE3 version (custom optimization) by h.yamagata
*
* Small fix by Alexander Balakhnin (fizick@avisynth.org.ru)
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define LOAD8(mem,dst) \
"movq "mem", "#dst" \n\t"\
"punpcklbw %%xmm7, "#dst" \n\t"
#define CHECK(pj,mj) \
"movdqu "#pj"(%[cur],%[mrefs]), %%xmm2 \n\t" /* cur[x-refs-1+j] */\
"movdqu "#mj"(%[cur],%[prefs]), %%xmm3 \n\t" /* cur[x+refs-1-j] */\
"movdqa %%xmm2, %%xmm4 \n\t"\
"movdqa %%xmm2, %%xmm5 \n\t"\
"pxor %%xmm3, %%xmm4 \n\t"\
"pavgb %%xmm3, %%xmm5 \n\t"\
"pand %[pb1], %%xmm4 \n\t"\
"psubusb %%xmm4, %%xmm5 \n\t"\
"psrldq $1, %%xmm5 \n\t"\
"punpcklbw %%xmm7, %%xmm5 \n\t" /* (cur[x-refs+j] + cur[x+refs-j])>>1 */\
"movdqa %%xmm2, %%xmm4 \n\t"\
"psubusb %%xmm3, %%xmm2 \n\t"\
"psubusb %%xmm4, %%xmm3 \n\t"\
"pmaxub %%xmm3, %%xmm2 \n\t"\
"movdqa %%xmm2, %%xmm3 \n\t"\
"movdqa %%xmm2, %%xmm4 \n\t" /* ABS(cur[x-refs-1+j] - cur[x+refs-1-j]) */\
"psrldq $1, %%xmm3 \n\t" /* ABS(cur[x-refs +j] - cur[x+refs -j]) */\
"psrldq $2, %%xmm4 \n\t" /* ABS(cur[x-refs+1+j] - cur[x+refs+1-j]) */\
"punpcklbw %%xmm7, %%xmm2 \n\t"\
"punpcklbw %%xmm7, %%xmm3 \n\t"\
"punpcklbw %%xmm7, %%xmm4 \n\t"\
"paddw %%xmm3, %%xmm2 \n\t"\
"paddw %%xmm4, %%xmm2 \n\t" /* score */
#define CHECK1 \
"movdqa %%xmm0, %%xmm3 \n\t"\
"pcmpgtw %%xmm2, %%xmm3 \n\t" /* if(score < spatial_score) */\
"pminsw %%xmm2, %%xmm0 \n\t" /* spatial_score= score; */\
"movdqa %%xmm3, %%xmm6 \n\t"\
"pand %%xmm3, %%xmm5 \n\t"\
"pandn %%xmm1, %%xmm3 \n\t"\
"por %%xmm5, %%xmm3 \n\t"\
"movdqa %%xmm3, %%xmm1 \n\t" /* spatial_pred= (cur[x-refs+j] + cur[x+refs-j])>>1; */
#define CHECK2 /* pretend not to have checked dir=2 if dir=1 was bad.\
hurts both quality and speed, but matches the C version. */\
"paddw %[pw1], %%xmm6 \n\t"\
"psllw $14, %%xmm6 \n\t"\
"paddsw %%xmm6, %%xmm2 \n\t"\
"movdqa %%xmm0, %%xmm3 \n\t"\
"pcmpgtw %%xmm2, %%xmm3 \n\t"\
"pminsw %%xmm2, %%xmm0 \n\t"\
"pand %%xmm3, %%xmm5 \n\t"\
"pandn %%xmm1, %%xmm3 \n\t"\
"por %%xmm5, %%xmm3 \n\t"\
"movdqa %%xmm3, %%xmm1 \n\t"
/* mode argument mod - Fizick */
/* static attribute_align_arg void FILTER_LINE_FUNC_NAME(YadifContext *yadctx, uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int refs, int parity){
const int mode = yadctx->mode; */
static attribute_align_arg void FILTER_LINE_FUNC_NAME(int mode, uint8_t *dst, const uint8_t *prev, const uint8_t *cur, const uint8_t *next, int w, int refs, int parity){
DECLARE_ALIGNED(16, uint8_t, tmp0[16]);
DECLARE_ALIGNED(16, uint8_t, tmp1[16]);
DECLARE_ALIGNED(16, uint8_t, tmp2[16]);
DECLARE_ALIGNED(16, uint8_t, tmp3[16]);
int x;
static DECLARE_ALIGNED(16, const unsigned short, pw_1[]) =
{
0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001
};
static DECLARE_ALIGNED(16, const unsigned short, pb_1[]) =
{
0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101
};
#define FILTER\
for(x=0; x<w; x+=8){\
__asm__ volatile(\
"pxor %%xmm7, %%xmm7 \n\t"\
LOAD8("(%[cur],%[mrefs])", %%xmm0) /* c = cur[x-refs] */\
LOAD8("(%[cur],%[prefs])", %%xmm1) /* e = cur[x+refs] */\
LOAD8("(%["prev2"])", %%xmm2) /* prev2[x] */\
LOAD8("(%["next2"])", %%xmm3) /* next2[x] */\
"movdqa %%xmm3, %%xmm4 \n\t"\
"paddw %%xmm2, %%xmm3 \n\t"\
"psraw $1, %%xmm3 \n\t" /* d = (prev2[x] + next2[x])>>1 */\
"movdqa %%xmm0, %[tmp0] \n\t" /* c */\
"movdqa %%xmm3, %[tmp1] \n\t" /* d */\
"movdqa %%xmm1, %[tmp2] \n\t" /* e */\
"psubw %%xmm4, %%xmm2 \n\t"\
PABS( %%xmm4, %%xmm2) /* temporal_diff0 */\
LOAD8("(%[prev],%[mrefs])", %%xmm3) /* prev[x-refs] */\
LOAD8("(%[prev],%[prefs])", %%xmm4) /* prev[x+refs] */\
"psubw %%xmm0, %%xmm3 \n\t"\
"psubw %%xmm1, %%xmm4 \n\t"\
PABS( %%xmm5, %%xmm3)\
PABS( %%xmm5, %%xmm4)\
"paddw %%xmm4, %%xmm3 \n\t" /* temporal_diff1 */\
"psrlw $1, %%xmm2 \n\t"\
"psrlw $1, %%xmm3 \n\t"\
"pmaxsw %%xmm3, %%xmm2 \n\t"\
LOAD8("(%[next],%[mrefs])", %%xmm3) /* next[x-refs] */\
LOAD8("(%[next],%[prefs])", %%xmm4) /* next[x+refs] */\
"psubw %%xmm0, %%xmm3 \n\t"\
"psubw %%xmm1, %%xmm4 \n\t"\
PABS( %%xmm5, %%xmm3)\
PABS( %%xmm5, %%xmm4)\
"paddw %%xmm4, %%xmm3 \n\t" /* temporal_diff2 */\
"psrlw $1, %%xmm3 \n\t"\
"pmaxsw %%xmm3, %%xmm2 \n\t"\
"movdqa %%xmm2, %[tmp3] \n\t" /* diff */\
\
"paddw %%xmm0, %%xmm1 \n\t"\
"paddw %%xmm0, %%xmm0 \n\t"\
"psubw %%xmm1, %%xmm0 \n\t"\
"psrlw $1, %%xmm1 \n\t" /* spatial_pred */\
PABS( %%xmm2, %%xmm0) /* ABS(c-e) */\
\
"movdqu -1(%[cur],%[mrefs]), %%xmm2 \n\t" /* cur[x-refs-1] */\
"movdqu -1(%[cur],%[prefs]), %%xmm3 \n\t" /* cur[x+refs-1] */\
"movdqa %%xmm2, %%xmm4 \n\t"\
"psubusb %%xmm3, %%xmm2 \n\t"\
"psubusb %%xmm4, %%xmm3 \n\t"\
"pmaxub %%xmm3, %%xmm2 \n\t"\
/*"pshuflw $9,%%xmm2, %%xmm3 \n\t"*/\
/*"pshufhw $9,%%xmm2, %%xmm3 \n\t"*/\
"movdqa %%xmm2, %%xmm3 \n\t" /* correct replacement (here) */\
"psrldq $2, %%xmm3 \n\t"/* for "pshufw $9,%%mm2, %%mm3" - fix by Fizick */\
"punpcklbw %%xmm7, %%xmm2 \n\t" /* ABS(cur[x-refs-1] - cur[x+refs-1]) */\
"punpcklbw %%xmm7, %%xmm3 \n\t" /* ABS(cur[x-refs+1] - cur[x+refs+1]) */\
"paddw %%xmm2, %%xmm0 \n\t"\
"paddw %%xmm3, %%xmm0 \n\t"\
"psubw %[pw1], %%xmm0 \n\t" /* spatial_score */\
\
CHECK(-2,0)\
CHECK1\
CHECK(-3,1)\
CHECK2\
CHECK(0,-2)\
CHECK1\
CHECK(1,-3)\
CHECK2\
\
/* if(yadctx->mode<2) ... */\
"movdqa %[tmp3], %%xmm6 \n\t" /* diff */\
"cmp $2, %[mode] \n\t"\
"jge 1f \n\t"\
LOAD8("(%["prev2"],%[mrefs],2)", %%xmm2) /* prev2[x-2*refs] */\
LOAD8("(%["next2"],%[mrefs],2)", %%xmm4) /* next2[x-2*refs] */\
LOAD8("(%["prev2"],%[prefs],2)", %%xmm3) /* prev2[x+2*refs] */\
LOAD8("(%["next2"],%[prefs],2)", %%xmm5) /* next2[x+2*refs] */\
"paddw %%xmm4, %%xmm2 \n\t"\
"paddw %%xmm5, %%xmm3 \n\t"\
"psrlw $1, %%xmm2 \n\t" /* b */\
"psrlw $1, %%xmm3 \n\t" /* f */\
"movdqa %[tmp0], %%xmm4 \n\t" /* c */\
"movdqa %[tmp1], %%xmm5 \n\t" /* d */\
"movdqa %[tmp2], %%xmm7 \n\t" /* e */\
"psubw %%xmm4, %%xmm2 \n\t" /* b-c */\
"psubw %%xmm7, %%xmm3 \n\t" /* f-e */\
"movdqa %%xmm5, %%xmm0 \n\t"\
"psubw %%xmm4, %%xmm5 \n\t" /* d-c */\
"psubw %%xmm7, %%xmm0 \n\t" /* d-e */\
"movdqa %%xmm2, %%xmm4 \n\t"\
"pminsw %%xmm3, %%xmm2 \n\t"\
"pmaxsw %%xmm4, %%xmm3 \n\t"\
"pmaxsw %%xmm5, %%xmm2 \n\t"\
"pminsw %%xmm5, %%xmm3 \n\t"\
"pmaxsw %%xmm0, %%xmm2 \n\t" /* max */\
"pminsw %%xmm0, %%xmm3 \n\t" /* min */\
"pxor %%xmm4, %%xmm4 \n\t"\
"pmaxsw %%xmm3, %%xmm6 \n\t"\
"psubw %%xmm2, %%xmm4 \n\t" /* -max */\
"pmaxsw %%xmm4, %%xmm6 \n\t" /* diff= MAX3(diff, min, -max); */\
"1: \n\t"\
\
"movdqa %[tmp1], %%xmm2 \n\t" /* d */\
"movdqa %%xmm2, %%xmm3 \n\t"\
"psubw %%xmm6, %%xmm2 \n\t" /* d-diff */\
"paddw %%xmm6, %%xmm3 \n\t" /* d+diff */\
"pmaxsw %%xmm2, %%xmm1 \n\t"\
"pminsw %%xmm3, %%xmm1 \n\t" /* d = clip(spatial_pred, d-diff, d+diff); */\
"packuswb %%xmm1, %%xmm1 \n\t"\
\
:[tmp0]"=m"(tmp0),\
[tmp1]"=m"(tmp1),\
[tmp2]"=m"(tmp2),\
[tmp3]"=m"(tmp3)\
:[prev] "r"(prev),\
[cur] "r"(cur),\
[next] "r"(next),\
[prefs]"r"((long)refs),\
[mrefs]"r"((long)-refs),\
[pw1] "m"(*pw_1),\
[pb1] "m"(*pb_1),\
[mode] "g"(mode)\
);\
__asm__ volatile("movq %%xmm1, %0" :"=m"(*dst));\
dst += 8;\
prev+= 8;\
cur += 8;\
next+= 8;\
}
if(parity){
#define prev2 "prev"
#define next2 "cur"
FILTER
#undef prev2
#undef next2
}else{
#define prev2 "cur"
#define next2 "next"
FILTER
#undef prev2
#undef next2
}
}
#undef LOAD8
#undef PABS
#undef CHECK
#undef CHECK1
#undef CHECK2
#undef FILTER
#undef FILTER_LINE_FUNC_NAME