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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/*
* Alpha optimized DSP utils
* Copyright (c) 2002 Falk Hueffner <falk@debian.org>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/attributes.h"
#include "libavcodec/me_cmp.h"
#include "asm.h"
int pix_abs16x16_mvi_asm(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
ptrdiff_t line_size, int h);
static inline uint64_t avg2(uint64_t a, uint64_t b)
{
return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
}
static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4)
{
uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
+ ((l2 & ~BYTE_VEC(0x03)) >> 2)
+ ((l3 & ~BYTE_VEC(0x03)) >> 2)
+ ((l4 & ~BYTE_VEC(0x03)) >> 2);
uint64_t r2 = (( (l1 & BYTE_VEC(0x03))
+ (l2 & BYTE_VEC(0x03))
+ (l3 & BYTE_VEC(0x03))
+ (l4 & BYTE_VEC(0x03))
+ BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03);
return r1 + r2;
}
static int pix_abs8x8_mvi(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
ptrdiff_t line_size, int h)
{
int result = 0;
if ((size_t) pix2 & 0x7) {
/* works only when pix2 is actually unaligned */
do { /* do 8 pixel a time */
uint64_t p1, p2;
p1 = ldq(pix1);
p2 = uldq(pix2);
result += perr(p1, p2);
pix1 += line_size;
pix2 += line_size;
} while (--h);
} else {
do {
uint64_t p1, p2;
p1 = ldq(pix1);
p2 = ldq(pix2);
result += perr(p1, p2);
pix1 += line_size;
pix2 += line_size;
} while (--h);
}
return result;
}
static int pix_abs16x16_x2_mvi(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
ptrdiff_t line_size, int h)
{
int result = 0;
uint64_t disalign = (size_t) pix2 & 0x7;
switch (disalign) {
case 0:
do {
uint64_t p1_l, p1_r, p2_l, p2_r;
uint64_t l, r;
p1_l = ldq(pix1);
p1_r = ldq(pix1 + 8);
l = ldq(pix2);
r = ldq(pix2 + 8);
p2_l = avg2(l, (l >> 8) | ((uint64_t) r << 56));
p2_r = avg2(r, (r >> 8) | ((uint64_t) pix2[16] << 56));
pix1 += line_size;
pix2 += line_size;
result += perr(p1_l, p2_l)
+ perr(p1_r, p2_r);
} while (--h);
break;
case 7:
/* |.......l|lllllllr|rrrrrrr*|
This case is special because disalign1 would be 8, which
gets treated as 0 by extqh. At least it is a bit faster
that way :) */
do {
uint64_t p1_l, p1_r, p2_l, p2_r;
uint64_t l, m, r;
p1_l = ldq(pix1);
p1_r = ldq(pix1 + 8);
l = ldq_u(pix2);
m = ldq_u(pix2 + 8);
r = ldq_u(pix2 + 16);
p2_l = avg2(extql(l, disalign) | extqh(m, disalign), m);
p2_r = avg2(extql(m, disalign) | extqh(r, disalign), r);
pix1 += line_size;
pix2 += line_size;
result += perr(p1_l, p2_l)
+ perr(p1_r, p2_r);
} while (--h);
break;
default:
do {
uint64_t disalign1 = disalign + 1;
uint64_t p1_l, p1_r, p2_l, p2_r;
uint64_t l, m, r;
p1_l = ldq(pix1);
p1_r = ldq(pix1 + 8);
l = ldq_u(pix2);
m = ldq_u(pix2 + 8);
r = ldq_u(pix2 + 16);
p2_l = avg2(extql(l, disalign) | extqh(m, disalign),
extql(l, disalign1) | extqh(m, disalign1));
p2_r = avg2(extql(m, disalign) | extqh(r, disalign),
extql(m, disalign1) | extqh(r, disalign1));
pix1 += line_size;
pix2 += line_size;
result += perr(p1_l, p2_l)
+ perr(p1_r, p2_r);
} while (--h);
break;
}
return result;
}
static int pix_abs16x16_y2_mvi(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
ptrdiff_t line_size, int h)
{
int result = 0;
if ((size_t) pix2 & 0x7) {
uint64_t t, p2_l, p2_r;
t = ldq_u(pix2 + 8);
p2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
p2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
do {
uint64_t p1_l, p1_r, np2_l, np2_r;
uint64_t t;
p1_l = ldq(pix1);
p1_r = ldq(pix1 + 8);
pix2 += line_size;
t = ldq_u(pix2 + 8);
np2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
np2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
result += perr(p1_l, avg2(p2_l, np2_l))
+ perr(p1_r, avg2(p2_r, np2_r));
pix1 += line_size;
p2_l = np2_l;
p2_r = np2_r;
} while (--h);
} else {
uint64_t p2_l, p2_r;
p2_l = ldq(pix2);
p2_r = ldq(pix2 + 8);
do {
uint64_t p1_l, p1_r, np2_l, np2_r;
p1_l = ldq(pix1);
p1_r = ldq(pix1 + 8);
pix2 += line_size;
np2_l = ldq(pix2);
np2_r = ldq(pix2 + 8);
result += perr(p1_l, avg2(p2_l, np2_l))
+ perr(p1_r, avg2(p2_r, np2_r));
pix1 += line_size;
p2_l = np2_l;
p2_r = np2_r;
} while (--h);
}
return result;
}
static int pix_abs16x16_xy2_mvi(struct MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
ptrdiff_t line_size, int h)
{
int result = 0;
uint64_t p1_l, p1_r;
uint64_t p2_l, p2_r, p2_x;
p1_l = ldq(pix1);
p1_r = ldq(pix1 + 8);
if ((size_t) pix2 & 0x7) { /* could be optimized a lot */
p2_l = uldq(pix2);
p2_r = uldq(pix2 + 8);
p2_x = (uint64_t) pix2[16] << 56;
} else {
p2_l = ldq(pix2);
p2_r = ldq(pix2 + 8);
p2_x = ldq(pix2 + 16) << 56;
}
do {
uint64_t np1_l, np1_r;
uint64_t np2_l, np2_r, np2_x;
pix1 += line_size;
pix2 += line_size;
np1_l = ldq(pix1);
np1_r = ldq(pix1 + 8);
if ((size_t) pix2 & 0x7) { /* could be optimized a lot */
np2_l = uldq(pix2);
np2_r = uldq(pix2 + 8);
np2_x = (uint64_t) pix2[16] << 56;
} else {
np2_l = ldq(pix2);
np2_r = ldq(pix2 + 8);
np2_x = ldq(pix2 + 16) << 56;
}
result += perr(p1_l,
avg4( p2_l, ( p2_l >> 8) | ((uint64_t) p2_r << 56),
np2_l, (np2_l >> 8) | ((uint64_t) np2_r << 56)))
+ perr(p1_r,
avg4( p2_r, ( p2_r >> 8) | ((uint64_t) p2_x),
np2_r, (np2_r >> 8) | ((uint64_t) np2_x)));
p1_l = np1_l;
p1_r = np1_r;
p2_l = np2_l;
p2_r = np2_r;
p2_x = np2_x;
} while (--h);
return result;
}
av_cold void ff_me_cmp_init_alpha(MECmpContext *c, AVCodecContext *avctx)
{
/* amask clears all bits that correspond to present features. */
if (amask(AMASK_MVI) == 0) {
c->sad[0] = pix_abs16x16_mvi_asm;
c->sad[1] = pix_abs8x8_mvi;
c->pix_abs[0][0] = pix_abs16x16_mvi_asm;
c->pix_abs[1][0] = pix_abs8x8_mvi;
c->pix_abs[0][1] = pix_abs16x16_x2_mvi;
c->pix_abs[0][2] = pix_abs16x16_y2_mvi;
c->pix_abs[0][3] = pix_abs16x16_xy2_mvi;
}
}
|