00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavcodec/dsputil.h"
00023 #include "asm.h"
00024
00025 void get_pixels_mvi(DCTELEM *restrict block,
00026 const uint8_t *restrict pixels, int line_size)
00027 {
00028 int h = 8;
00029
00030 do {
00031 uint64_t p;
00032
00033 p = ldq(pixels);
00034 stq(unpkbw(p), block);
00035 stq(unpkbw(p >> 32), block + 4);
00036
00037 pixels += line_size;
00038 block += 8;
00039 } while (--h);
00040 }
00041
00042 void diff_pixels_mvi(DCTELEM *block, const uint8_t *s1, const uint8_t *s2,
00043 int stride) {
00044 int h = 8;
00045 uint64_t mask = 0x4040;
00046
00047 mask |= mask << 16;
00048 mask |= mask << 32;
00049 do {
00050 uint64_t x, y, c, d, a;
00051 uint64_t signs;
00052
00053 x = ldq(s1);
00054 y = ldq(s2);
00055 c = cmpbge(x, y);
00056 d = x - y;
00057 a = zap(mask, c);
00058 d += 4 * a;
00059 signs = zap(-1, c);
00060
00061 stq(unpkbw(d) | (unpkbw(signs) << 8), block);
00062 stq(unpkbw(d >> 32) | (unpkbw(signs >> 32) << 8), block + 4);
00063
00064 s1 += stride;
00065 s2 += stride;
00066 block += 8;
00067 } while (--h);
00068 }
00069
00070 static inline uint64_t avg2(uint64_t a, uint64_t b)
00071 {
00072 return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
00073 }
00074
00075 static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4)
00076 {
00077 uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
00078 + ((l2 & ~BYTE_VEC(0x03)) >> 2)
00079 + ((l3 & ~BYTE_VEC(0x03)) >> 2)
00080 + ((l4 & ~BYTE_VEC(0x03)) >> 2);
00081 uint64_t r2 = (( (l1 & BYTE_VEC(0x03))
00082 + (l2 & BYTE_VEC(0x03))
00083 + (l3 & BYTE_VEC(0x03))
00084 + (l4 & BYTE_VEC(0x03))
00085 + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03);
00086 return r1 + r2;
00087 }
00088
00089 int pix_abs8x8_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00090 {
00091 int result = 0;
00092
00093 if ((size_t) pix2 & 0x7) {
00094
00095 do {
00096 uint64_t p1, p2;
00097
00098 p1 = ldq(pix1);
00099 p2 = uldq(pix2);
00100 result += perr(p1, p2);
00101
00102 pix1 += line_size;
00103 pix2 += line_size;
00104 } while (--h);
00105 } else {
00106 do {
00107 uint64_t p1, p2;
00108
00109 p1 = ldq(pix1);
00110 p2 = ldq(pix2);
00111 result += perr(p1, p2);
00112
00113 pix1 += line_size;
00114 pix2 += line_size;
00115 } while (--h);
00116 }
00117
00118 return result;
00119 }
00120
00121 #if 0
00122 int pix_abs16x16_mvi(uint8_t *pix1, uint8_t *pix2, int line_size)
00123 {
00124 int result = 0;
00125 int h = 16;
00126
00127 if ((size_t) pix2 & 0x7) {
00128
00129 do {
00130 uint64_t p1_l, p1_r, p2_l, p2_r;
00131 uint64_t t;
00132
00133 p1_l = ldq(pix1);
00134 p1_r = ldq(pix1 + 8);
00135 t = ldq_u(pix2 + 8);
00136 p2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
00137 p2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
00138 pix1 += line_size;
00139 pix2 += line_size;
00140
00141 result += perr(p1_l, p2_l)
00142 + perr(p1_r, p2_r);
00143 } while (--h);
00144 } else {
00145 do {
00146 uint64_t p1_l, p1_r, p2_l, p2_r;
00147
00148 p1_l = ldq(pix1);
00149 p1_r = ldq(pix1 + 8);
00150 p2_l = ldq(pix2);
00151 p2_r = ldq(pix2 + 8);
00152 pix1 += line_size;
00153 pix2 += line_size;
00154
00155 result += perr(p1_l, p2_l)
00156 + perr(p1_r, p2_r);
00157 } while (--h);
00158 }
00159
00160 return result;
00161 }
00162 #endif
00163
00164 int pix_abs16x16_x2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00165 {
00166 int result = 0;
00167 uint64_t disalign = (size_t) pix2 & 0x7;
00168
00169 switch (disalign) {
00170 case 0:
00171 do {
00172 uint64_t p1_l, p1_r, p2_l, p2_r;
00173 uint64_t l, r;
00174
00175 p1_l = ldq(pix1);
00176 p1_r = ldq(pix1 + 8);
00177 l = ldq(pix2);
00178 r = ldq(pix2 + 8);
00179 p2_l = avg2(l, (l >> 8) | ((uint64_t) r << 56));
00180 p2_r = avg2(r, (r >> 8) | ((uint64_t) pix2[16] << 56));
00181 pix1 += line_size;
00182 pix2 += line_size;
00183
00184 result += perr(p1_l, p2_l)
00185 + perr(p1_r, p2_r);
00186 } while (--h);
00187 break;
00188 case 7:
00189
00190
00191
00192
00193 do {
00194 uint64_t p1_l, p1_r, p2_l, p2_r;
00195 uint64_t l, m, r;
00196
00197 p1_l = ldq(pix1);
00198 p1_r = ldq(pix1 + 8);
00199 l = ldq_u(pix2);
00200 m = ldq_u(pix2 + 8);
00201 r = ldq_u(pix2 + 16);
00202 p2_l = avg2(extql(l, disalign) | extqh(m, disalign), m);
00203 p2_r = avg2(extql(m, disalign) | extqh(r, disalign), r);
00204 pix1 += line_size;
00205 pix2 += line_size;
00206
00207 result += perr(p1_l, p2_l)
00208 + perr(p1_r, p2_r);
00209 } while (--h);
00210 break;
00211 default:
00212 do {
00213 uint64_t disalign1 = disalign + 1;
00214 uint64_t p1_l, p1_r, p2_l, p2_r;
00215 uint64_t l, m, r;
00216
00217 p1_l = ldq(pix1);
00218 p1_r = ldq(pix1 + 8);
00219 l = ldq_u(pix2);
00220 m = ldq_u(pix2 + 8);
00221 r = ldq_u(pix2 + 16);
00222 p2_l = avg2(extql(l, disalign) | extqh(m, disalign),
00223 extql(l, disalign1) | extqh(m, disalign1));
00224 p2_r = avg2(extql(m, disalign) | extqh(r, disalign),
00225 extql(m, disalign1) | extqh(r, disalign1));
00226 pix1 += line_size;
00227 pix2 += line_size;
00228
00229 result += perr(p1_l, p2_l)
00230 + perr(p1_r, p2_r);
00231 } while (--h);
00232 break;
00233 }
00234 return result;
00235 }
00236
00237 int pix_abs16x16_y2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00238 {
00239 int result = 0;
00240
00241 if ((size_t) pix2 & 0x7) {
00242 uint64_t t, p2_l, p2_r;
00243 t = ldq_u(pix2 + 8);
00244 p2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
00245 p2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
00246
00247 do {
00248 uint64_t p1_l, p1_r, np2_l, np2_r;
00249 uint64_t t;
00250
00251 p1_l = ldq(pix1);
00252 p1_r = ldq(pix1 + 8);
00253 pix2 += line_size;
00254 t = ldq_u(pix2 + 8);
00255 np2_l = extql(ldq_u(pix2), pix2) | extqh(t, pix2);
00256 np2_r = extql(t, pix2) | extqh(ldq_u(pix2 + 16), pix2);
00257
00258 result += perr(p1_l, avg2(p2_l, np2_l))
00259 + perr(p1_r, avg2(p2_r, np2_r));
00260
00261 pix1 += line_size;
00262 p2_l = np2_l;
00263 p2_r = np2_r;
00264
00265 } while (--h);
00266 } else {
00267 uint64_t p2_l, p2_r;
00268 p2_l = ldq(pix2);
00269 p2_r = ldq(pix2 + 8);
00270 do {
00271 uint64_t p1_l, p1_r, np2_l, np2_r;
00272
00273 p1_l = ldq(pix1);
00274 p1_r = ldq(pix1 + 8);
00275 pix2 += line_size;
00276 np2_l = ldq(pix2);
00277 np2_r = ldq(pix2 + 8);
00278
00279 result += perr(p1_l, avg2(p2_l, np2_l))
00280 + perr(p1_r, avg2(p2_r, np2_r));
00281
00282 pix1 += line_size;
00283 p2_l = np2_l;
00284 p2_r = np2_r;
00285 } while (--h);
00286 }
00287 return result;
00288 }
00289
00290 int pix_abs16x16_xy2_mvi(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
00291 {
00292 int result = 0;
00293
00294 uint64_t p1_l, p1_r;
00295 uint64_t p2_l, p2_r, p2_x;
00296
00297 p1_l = ldq(pix1);
00298 p1_r = ldq(pix1 + 8);
00299
00300 if ((size_t) pix2 & 0x7) {
00301 p2_l = uldq(pix2);
00302 p2_r = uldq(pix2 + 8);
00303 p2_x = (uint64_t) pix2[16] << 56;
00304 } else {
00305 p2_l = ldq(pix2);
00306 p2_r = ldq(pix2 + 8);
00307 p2_x = ldq(pix2 + 16) << 56;
00308 }
00309
00310 do {
00311 uint64_t np1_l, np1_r;
00312 uint64_t np2_l, np2_r, np2_x;
00313
00314 pix1 += line_size;
00315 pix2 += line_size;
00316
00317 np1_l = ldq(pix1);
00318 np1_r = ldq(pix1 + 8);
00319
00320 if ((size_t) pix2 & 0x7) {
00321 np2_l = uldq(pix2);
00322 np2_r = uldq(pix2 + 8);
00323 np2_x = (uint64_t) pix2[16] << 56;
00324 } else {
00325 np2_l = ldq(pix2);
00326 np2_r = ldq(pix2 + 8);
00327 np2_x = ldq(pix2 + 16) << 56;
00328 }
00329
00330 result += perr(p1_l,
00331 avg4( p2_l, ( p2_l >> 8) | ((uint64_t) p2_r << 56),
00332 np2_l, (np2_l >> 8) | ((uint64_t) np2_r << 56)))
00333 + perr(p1_r,
00334 avg4( p2_r, ( p2_r >> 8) | ((uint64_t) p2_x),
00335 np2_r, (np2_r >> 8) | ((uint64_t) np2_x)));
00336
00337 p1_l = np1_l;
00338 p1_r = np1_r;
00339 p2_l = np2_l;
00340 p2_r = np2_r;
00341 p2_x = np2_x;
00342 } while (--h);
00343
00344 return result;
00345 }