OLD | NEW |
1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
9 // | 9 // |
10 // SSE2 version of some decoding functions (idct, loop filtering). | 10 // SSE2 version of some decoding functions (idct, loop filtering). |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // (x * K) >> 16 = (x * (k + (1 << 16))) >> 16 = ((x * k ) >> 16) + x | 45 // (x * K) >> 16 = (x * (k + (1 << 16))) >> 16 = ((x * k ) >> 16) + x |
46 const __m128i k1 = _mm_set1_epi16(20091); | 46 const __m128i k1 = _mm_set1_epi16(20091); |
47 const __m128i k2 = _mm_set1_epi16(-30068); | 47 const __m128i k2 = _mm_set1_epi16(-30068); |
48 __m128i T0, T1, T2, T3; | 48 __m128i T0, T1, T2, T3; |
49 | 49 |
50 // Load and concatenate the transform coefficients (we'll do two transforms | 50 // Load and concatenate the transform coefficients (we'll do two transforms |
51 // in parallel). In the case of only one transform, the second half of the | 51 // in parallel). In the case of only one transform, the second half of the |
52 // vectors will just contain random value we'll never use nor store. | 52 // vectors will just contain random value we'll never use nor store. |
53 __m128i in0, in1, in2, in3; | 53 __m128i in0, in1, in2, in3; |
54 { | 54 { |
55 in0 = _mm_loadl_epi64((__m128i*)&in[0]); | 55 in0 = _mm_loadl_epi64((const __m128i*)&in[0]); |
56 in1 = _mm_loadl_epi64((__m128i*)&in[4]); | 56 in1 = _mm_loadl_epi64((const __m128i*)&in[4]); |
57 in2 = _mm_loadl_epi64((__m128i*)&in[8]); | 57 in2 = _mm_loadl_epi64((const __m128i*)&in[8]); |
58 in3 = _mm_loadl_epi64((__m128i*)&in[12]); | 58 in3 = _mm_loadl_epi64((const __m128i*)&in[12]); |
59 // a00 a10 a20 a30 x x x x | 59 // a00 a10 a20 a30 x x x x |
60 // a01 a11 a21 a31 x x x x | 60 // a01 a11 a21 a31 x x x x |
61 // a02 a12 a22 a32 x x x x | 61 // a02 a12 a22 a32 x x x x |
62 // a03 a13 a23 a33 x x x x | 62 // a03 a13 a23 a33 x x x x |
63 if (do_two) { | 63 if (do_two) { |
64 const __m128i inB0 = _mm_loadl_epi64((__m128i*)&in[16]); | 64 const __m128i inB0 = _mm_loadl_epi64((const __m128i*)&in[16]); |
65 const __m128i inB1 = _mm_loadl_epi64((__m128i*)&in[20]); | 65 const __m128i inB1 = _mm_loadl_epi64((const __m128i*)&in[20]); |
66 const __m128i inB2 = _mm_loadl_epi64((__m128i*)&in[24]); | 66 const __m128i inB2 = _mm_loadl_epi64((const __m128i*)&in[24]); |
67 const __m128i inB3 = _mm_loadl_epi64((__m128i*)&in[28]); | 67 const __m128i inB3 = _mm_loadl_epi64((const __m128i*)&in[28]); |
68 in0 = _mm_unpacklo_epi64(in0, inB0); | 68 in0 = _mm_unpacklo_epi64(in0, inB0); |
69 in1 = _mm_unpacklo_epi64(in1, inB1); | 69 in1 = _mm_unpacklo_epi64(in1, inB1); |
70 in2 = _mm_unpacklo_epi64(in2, inB2); | 70 in2 = _mm_unpacklo_epi64(in2, inB2); |
71 in3 = _mm_unpacklo_epi64(in3, inB3); | 71 in3 = _mm_unpacklo_epi64(in3, inB3); |
72 // a00 a10 a20 a30 b00 b10 b20 b30 | 72 // a00 a10 a20 a30 b00 b10 b20 b30 |
73 // a01 a11 a21 a31 b01 b11 b21 b31 | 73 // a01 a11 a21 a31 b01 b11 b21 b31 |
74 // a02 a12 a22 a32 b02 b12 b22 b32 | 74 // a02 a12 a22 a32 b02 b12 b22 b32 |
75 // a03 a13 a23 a33 b03 b13 b23 b33 | 75 // a03 a13 a23 a33 b03 b13 b23 b33 |
76 } | 76 } |
77 } | 77 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Load the reference(s). | 200 // Load the reference(s). |
201 __m128i dst0, dst1, dst2, dst3; | 201 __m128i dst0, dst1, dst2, dst3; |
202 if (do_two) { | 202 if (do_two) { |
203 // Load eight bytes/pixels per line. | 203 // Load eight bytes/pixels per line. |
204 dst0 = _mm_loadl_epi64((__m128i*)(dst + 0 * BPS)); | 204 dst0 = _mm_loadl_epi64((__m128i*)(dst + 0 * BPS)); |
205 dst1 = _mm_loadl_epi64((__m128i*)(dst + 1 * BPS)); | 205 dst1 = _mm_loadl_epi64((__m128i*)(dst + 1 * BPS)); |
206 dst2 = _mm_loadl_epi64((__m128i*)(dst + 2 * BPS)); | 206 dst2 = _mm_loadl_epi64((__m128i*)(dst + 2 * BPS)); |
207 dst3 = _mm_loadl_epi64((__m128i*)(dst + 3 * BPS)); | 207 dst3 = _mm_loadl_epi64((__m128i*)(dst + 3 * BPS)); |
208 } else { | 208 } else { |
209 // Load four bytes/pixels per line. | 209 // Load four bytes/pixels per line. |
210 dst0 = _mm_cvtsi32_si128(*(int*)(dst + 0 * BPS)); | 210 dst0 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 0 * BPS)); |
211 dst1 = _mm_cvtsi32_si128(*(int*)(dst + 1 * BPS)); | 211 dst1 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 1 * BPS)); |
212 dst2 = _mm_cvtsi32_si128(*(int*)(dst + 2 * BPS)); | 212 dst2 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 2 * BPS)); |
213 dst3 = _mm_cvtsi32_si128(*(int*)(dst + 3 * BPS)); | 213 dst3 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 3 * BPS)); |
214 } | 214 } |
215 // Convert to 16b. | 215 // Convert to 16b. |
216 dst0 = _mm_unpacklo_epi8(dst0, zero); | 216 dst0 = _mm_unpacklo_epi8(dst0, zero); |
217 dst1 = _mm_unpacklo_epi8(dst1, zero); | 217 dst1 = _mm_unpacklo_epi8(dst1, zero); |
218 dst2 = _mm_unpacklo_epi8(dst2, zero); | 218 dst2 = _mm_unpacklo_epi8(dst2, zero); |
219 dst3 = _mm_unpacklo_epi8(dst3, zero); | 219 dst3 = _mm_unpacklo_epi8(dst3, zero); |
220 // Add the inverse transform(s). | 220 // Add the inverse transform(s). |
221 dst0 = _mm_add_epi16(dst0, T0); | 221 dst0 = _mm_add_epi16(dst0, T0); |
222 dst1 = _mm_add_epi16(dst1, T1); | 222 dst1 = _mm_add_epi16(dst1, T1); |
223 dst2 = _mm_add_epi16(dst2, T2); | 223 dst2 = _mm_add_epi16(dst2, T2); |
224 dst3 = _mm_add_epi16(dst3, T3); | 224 dst3 = _mm_add_epi16(dst3, T3); |
225 // Unsigned saturate to 8b. | 225 // Unsigned saturate to 8b. |
226 dst0 = _mm_packus_epi16(dst0, dst0); | 226 dst0 = _mm_packus_epi16(dst0, dst0); |
227 dst1 = _mm_packus_epi16(dst1, dst1); | 227 dst1 = _mm_packus_epi16(dst1, dst1); |
228 dst2 = _mm_packus_epi16(dst2, dst2); | 228 dst2 = _mm_packus_epi16(dst2, dst2); |
229 dst3 = _mm_packus_epi16(dst3, dst3); | 229 dst3 = _mm_packus_epi16(dst3, dst3); |
230 // Store the results. | 230 // Store the results. |
231 if (do_two) { | 231 if (do_two) { |
232 // Store eight bytes/pixels per line. | 232 // Store eight bytes/pixels per line. |
233 _mm_storel_epi64((__m128i*)(dst + 0 * BPS), dst0); | 233 _mm_storel_epi64((__m128i*)(dst + 0 * BPS), dst0); |
234 _mm_storel_epi64((__m128i*)(dst + 1 * BPS), dst1); | 234 _mm_storel_epi64((__m128i*)(dst + 1 * BPS), dst1); |
235 _mm_storel_epi64((__m128i*)(dst + 2 * BPS), dst2); | 235 _mm_storel_epi64((__m128i*)(dst + 2 * BPS), dst2); |
236 _mm_storel_epi64((__m128i*)(dst + 3 * BPS), dst3); | 236 _mm_storel_epi64((__m128i*)(dst + 3 * BPS), dst3); |
237 } else { | 237 } else { |
238 // Store four bytes/pixels per line. | 238 // Store four bytes/pixels per line. |
239 *(int*)(dst + 0 * BPS) = _mm_cvtsi128_si32(dst0); | 239 WebPUint32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32(dst0)); |
240 *(int*)(dst + 1 * BPS) = _mm_cvtsi128_si32(dst1); | 240 WebPUint32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(dst1)); |
241 *(int*)(dst + 2 * BPS) = _mm_cvtsi128_si32(dst2); | 241 WebPUint32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(dst2)); |
242 *(int*)(dst + 3 * BPS) = _mm_cvtsi128_si32(dst3); | 242 WebPUint32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(dst3)); |
243 } | 243 } |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 #if defined(USE_TRANSFORM_AC3) | 247 #if defined(USE_TRANSFORM_AC3) |
248 #define MUL(a, b) (((a) * (b)) >> 16) | 248 #define MUL(a, b) (((a) * (b)) >> 16) |
249 static void TransformAC3(const int16_t* in, uint8_t* dst) { | 249 static void TransformAC3(const int16_t* in, uint8_t* dst) { |
250 static const int kC1 = 20091 + (1 << 16); | 250 static const int kC1 = 20091 + (1 << 16); |
251 static const int kC2 = 35468; | 251 static const int kC2 = 35468; |
252 const __m128i A = _mm_set1_epi16(in[0] + 4); | 252 const __m128i A = _mm_set1_epi16(in[0] + 4); |
253 const __m128i c4 = _mm_set1_epi16(MUL(in[4], kC2)); | 253 const __m128i c4 = _mm_set1_epi16(MUL(in[4], kC2)); |
254 const __m128i d4 = _mm_set1_epi16(MUL(in[4], kC1)); | 254 const __m128i d4 = _mm_set1_epi16(MUL(in[4], kC1)); |
255 const int c1 = MUL(in[1], kC2); | 255 const int c1 = MUL(in[1], kC2); |
256 const int d1 = MUL(in[1], kC1); | 256 const int d1 = MUL(in[1], kC1); |
257 const __m128i CD = _mm_set_epi16(0, 0, 0, 0, -d1, -c1, c1, d1); | 257 const __m128i CD = _mm_set_epi16(0, 0, 0, 0, -d1, -c1, c1, d1); |
258 const __m128i B = _mm_adds_epi16(A, CD); | 258 const __m128i B = _mm_adds_epi16(A, CD); |
259 const __m128i m0 = _mm_adds_epi16(B, d4); | 259 const __m128i m0 = _mm_adds_epi16(B, d4); |
260 const __m128i m1 = _mm_adds_epi16(B, c4); | 260 const __m128i m1 = _mm_adds_epi16(B, c4); |
261 const __m128i m2 = _mm_subs_epi16(B, c4); | 261 const __m128i m2 = _mm_subs_epi16(B, c4); |
262 const __m128i m3 = _mm_subs_epi16(B, d4); | 262 const __m128i m3 = _mm_subs_epi16(B, d4); |
263 const __m128i zero = _mm_setzero_si128(); | 263 const __m128i zero = _mm_setzero_si128(); |
264 // Load the source pixels. | 264 // Load the source pixels. |
265 __m128i dst0 = _mm_cvtsi32_si128(*(int*)(dst + 0 * BPS)); | 265 __m128i dst0 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 0 * BPS)); |
266 __m128i dst1 = _mm_cvtsi32_si128(*(int*)(dst + 1 * BPS)); | 266 __m128i dst1 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 1 * BPS)); |
267 __m128i dst2 = _mm_cvtsi32_si128(*(int*)(dst + 2 * BPS)); | 267 __m128i dst2 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 2 * BPS)); |
268 __m128i dst3 = _mm_cvtsi32_si128(*(int*)(dst + 3 * BPS)); | 268 __m128i dst3 = _mm_cvtsi32_si128(WebPMemToUint32(dst + 3 * BPS)); |
269 // Convert to 16b. | 269 // Convert to 16b. |
270 dst0 = _mm_unpacklo_epi8(dst0, zero); | 270 dst0 = _mm_unpacklo_epi8(dst0, zero); |
271 dst1 = _mm_unpacklo_epi8(dst1, zero); | 271 dst1 = _mm_unpacklo_epi8(dst1, zero); |
272 dst2 = _mm_unpacklo_epi8(dst2, zero); | 272 dst2 = _mm_unpacklo_epi8(dst2, zero); |
273 dst3 = _mm_unpacklo_epi8(dst3, zero); | 273 dst3 = _mm_unpacklo_epi8(dst3, zero); |
274 // Add the inverse transform. | 274 // Add the inverse transform. |
275 dst0 = _mm_adds_epi16(dst0, _mm_srai_epi16(m0, 3)); | 275 dst0 = _mm_adds_epi16(dst0, _mm_srai_epi16(m0, 3)); |
276 dst1 = _mm_adds_epi16(dst1, _mm_srai_epi16(m1, 3)); | 276 dst1 = _mm_adds_epi16(dst1, _mm_srai_epi16(m1, 3)); |
277 dst2 = _mm_adds_epi16(dst2, _mm_srai_epi16(m2, 3)); | 277 dst2 = _mm_adds_epi16(dst2, _mm_srai_epi16(m2, 3)); |
278 dst3 = _mm_adds_epi16(dst3, _mm_srai_epi16(m3, 3)); | 278 dst3 = _mm_adds_epi16(dst3, _mm_srai_epi16(m3, 3)); |
279 // Unsigned saturate to 8b. | 279 // Unsigned saturate to 8b. |
280 dst0 = _mm_packus_epi16(dst0, dst0); | 280 dst0 = _mm_packus_epi16(dst0, dst0); |
281 dst1 = _mm_packus_epi16(dst1, dst1); | 281 dst1 = _mm_packus_epi16(dst1, dst1); |
282 dst2 = _mm_packus_epi16(dst2, dst2); | 282 dst2 = _mm_packus_epi16(dst2, dst2); |
283 dst3 = _mm_packus_epi16(dst3, dst3); | 283 dst3 = _mm_packus_epi16(dst3, dst3); |
284 // Store the results. | 284 // Store the results. |
285 *(int*)(dst + 0 * BPS) = _mm_cvtsi128_si32(dst0); | 285 WebPUint32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32(dst0)); |
286 *(int*)(dst + 1 * BPS) = _mm_cvtsi128_si32(dst1); | 286 WebPUint32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(dst1)); |
287 *(int*)(dst + 2 * BPS) = _mm_cvtsi128_si32(dst2); | 287 WebPUint32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(dst2)); |
288 *(int*)(dst + 3 * BPS) = _mm_cvtsi128_si32(dst3); | 288 WebPUint32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(dst3)); |
289 } | 289 } |
290 #undef MUL | 290 #undef MUL |
291 #endif // USE_TRANSFORM_AC3 | 291 #endif // USE_TRANSFORM_AC3 |
292 | 292 |
293 //------------------------------------------------------------------------------ | 293 //------------------------------------------------------------------------------ |
294 // Loop Filter (Paragraph 15) | 294 // Loop Filter (Paragraph 15) |
295 | 295 |
296 // Compute abs(p - q) = subs(p - q) OR subs(q - p) | 296 // Compute abs(p - q) = subs(p - q) OR subs(q - p) |
297 #define MM_ABS(p, q) _mm_or_si128( \ | 297 #define MM_ABS(p, q) _mm_or_si128( \ |
298 _mm_subs_epu8((q), (p)), \ | 298 _mm_subs_epu8((q), (p)), \ |
299 _mm_subs_epu8((p), (q))) | 299 _mm_subs_epu8((p), (q))) |
300 | 300 |
301 // Shift each byte of "x" by 3 bits while preserving by the sign bit. | 301 // Shift each byte of "x" by 3 bits while preserving by the sign bit. |
302 static WEBP_INLINE void SignedShift8b(__m128i* const x) { | 302 static WEBP_INLINE void SignedShift8b(__m128i* const x) { |
303 const __m128i zero = _mm_setzero_si128(); | 303 const __m128i zero = _mm_setzero_si128(); |
304 const __m128i signs = _mm_cmpgt_epi8(zero, *x); | 304 const __m128i lo_0 = _mm_unpacklo_epi8(zero, *x); |
305 const __m128i lo_0 = _mm_unpacklo_epi8(*x, signs); // s8 -> s16 sign extend | 305 const __m128i hi_0 = _mm_unpackhi_epi8(zero, *x); |
306 const __m128i hi_0 = _mm_unpackhi_epi8(*x, signs); | 306 const __m128i lo_1 = _mm_srai_epi16(lo_0, 3 + 8); |
307 const __m128i lo_1 = _mm_srai_epi16(lo_0, 3); | 307 const __m128i hi_1 = _mm_srai_epi16(hi_0, 3 + 8); |
308 const __m128i hi_1 = _mm_srai_epi16(hi_0, 3); | |
309 *x = _mm_packs_epi16(lo_1, hi_1); | 308 *x = _mm_packs_epi16(lo_1, hi_1); |
310 } | 309 } |
311 | 310 |
312 #define FLIP_SIGN_BIT2(a, b) { \ | 311 #define FLIP_SIGN_BIT2(a, b) { \ |
313 a = _mm_xor_si128(a, sign_bit); \ | 312 a = _mm_xor_si128(a, sign_bit); \ |
314 b = _mm_xor_si128(b, sign_bit); \ | 313 b = _mm_xor_si128(b, sign_bit); \ |
315 } | 314 } |
316 | 315 |
317 #define FLIP_SIGN_BIT4(a, b, c, d) { \ | 316 #define FLIP_SIGN_BIT4(a, b, c, d) { \ |
318 FLIP_SIGN_BIT2(a, b); \ | 317 FLIP_SIGN_BIT2(a, b); \ |
319 FLIP_SIGN_BIT2(c, d); \ | 318 FLIP_SIGN_BIT2(c, d); \ |
320 } | 319 } |
321 | 320 |
322 // input/output is uint8_t | 321 // input/output is uint8_t |
323 static WEBP_INLINE void GetNotHEV(const __m128i* const p1, | 322 static WEBP_INLINE void GetNotHEV(const __m128i* const p1, |
324 const __m128i* const p0, | 323 const __m128i* const p0, |
325 const __m128i* const q0, | 324 const __m128i* const q0, |
326 const __m128i* const q1, | 325 const __m128i* const q1, |
327 int hev_thresh, __m128i* const not_hev) { | 326 int hev_thresh, __m128i* const not_hev) { |
328 const __m128i zero = _mm_setzero_si128(); | 327 const __m128i zero = _mm_setzero_si128(); |
329 const __m128i t_1 = MM_ABS(*p1, *p0); | 328 const __m128i t_1 = MM_ABS(*p1, *p0); |
330 const __m128i t_2 = MM_ABS(*q1, *q0); | 329 const __m128i t_2 = MM_ABS(*q1, *q0); |
331 | 330 |
332 const __m128i h = _mm_set1_epi8(hev_thresh); | 331 const __m128i h = _mm_set1_epi8(hev_thresh); |
333 const __m128i t_3 = _mm_subs_epu8(t_1, h); // abs(p1 - p0) - hev_tresh | 332 const __m128i t_max = _mm_max_epu8(t_1, t_2); |
334 const __m128i t_4 = _mm_subs_epu8(t_2, h); // abs(q1 - q0) - hev_tresh | |
335 | 333 |
336 *not_hev = _mm_or_si128(t_3, t_4); | 334 const __m128i t_max_h = _mm_subs_epu8(t_max, h); |
337 *not_hev = _mm_cmpeq_epi8(*not_hev, zero); // not_hev <= t1 && not_hev <= t2 | 335 *not_hev = _mm_cmpeq_epi8(t_max_h, zero); // not_hev <= t1 && not_hev <= t2 |
338 } | 336 } |
339 | 337 |
340 // input pixels are int8_t | 338 // input pixels are int8_t |
341 static WEBP_INLINE void GetBaseDelta(const __m128i* const p1, | 339 static WEBP_INLINE void GetBaseDelta(const __m128i* const p1, |
342 const __m128i* const p0, | 340 const __m128i* const p0, |
343 const __m128i* const q0, | 341 const __m128i* const q0, |
344 const __m128i* const q1, | 342 const __m128i* const q1, |
345 __m128i* const delta) { | 343 __m128i* const delta) { |
346 // beware of addition order, for saturation! | 344 // beware of addition order, for saturation! |
347 const __m128i p1_q1 = _mm_subs_epi8(*p1, *q1); // p1 - q1 | 345 const __m128i p1_q1 = _mm_subs_epi8(*p1, *q1); // p1 - q1 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 GetBaseDelta(&p1s, p0, q0, &q1s, &a); | 419 GetBaseDelta(&p1s, p0, q0, &q1s, &a); |
422 a = _mm_and_si128(a, mask); // mask filter values we don't care about | 420 a = _mm_and_si128(a, mask); // mask filter values we don't care about |
423 DoSimpleFilter(p0, q0, &a); | 421 DoSimpleFilter(p0, q0, &a); |
424 FLIP_SIGN_BIT2(*p0, *q0); | 422 FLIP_SIGN_BIT2(*p0, *q0); |
425 } | 423 } |
426 | 424 |
427 // Applies filter on 4 pixels (p1, p0, q0 and q1) | 425 // Applies filter on 4 pixels (p1, p0, q0 and q1) |
428 static WEBP_INLINE void DoFilter4(__m128i* const p1, __m128i* const p0, | 426 static WEBP_INLINE void DoFilter4(__m128i* const p1, __m128i* const p0, |
429 __m128i* const q0, __m128i* const q1, | 427 __m128i* const q0, __m128i* const q1, |
430 const __m128i* const mask, int hev_thresh) { | 428 const __m128i* const mask, int hev_thresh) { |
| 429 const __m128i zero = _mm_setzero_si128(); |
431 const __m128i sign_bit = _mm_set1_epi8(0x80); | 430 const __m128i sign_bit = _mm_set1_epi8(0x80); |
432 const __m128i k64 = _mm_set1_epi8(0x40); | 431 const __m128i k64 = _mm_set1_epi8(64); |
433 const __m128i zero = _mm_setzero_si128(); | 432 const __m128i k3 = _mm_set1_epi8(3); |
| 433 const __m128i k4 = _mm_set1_epi8(4); |
434 __m128i not_hev; | 434 __m128i not_hev; |
435 __m128i t1, t2, t3; | 435 __m128i t1, t2, t3; |
436 | 436 |
437 // compute hev mask | 437 // compute hev mask |
438 GetNotHEV(p1, p0, q0, q1, hev_thresh, ¬_hev); | 438 GetNotHEV(p1, p0, q0, q1, hev_thresh, ¬_hev); |
439 | 439 |
440 // convert to signed values | 440 // convert to signed values |
441 FLIP_SIGN_BIT4(*p1, *p0, *q0, *q1); | 441 FLIP_SIGN_BIT4(*p1, *p0, *q0, *q1); |
442 | 442 |
443 t1 = _mm_subs_epi8(*p1, *q1); // p1 - q1 | 443 t1 = _mm_subs_epi8(*p1, *q1); // p1 - q1 |
444 t1 = _mm_andnot_si128(not_hev, t1); // hev(p1 - q1) | 444 t1 = _mm_andnot_si128(not_hev, t1); // hev(p1 - q1) |
445 t2 = _mm_subs_epi8(*q0, *p0); // q0 - p0 | 445 t2 = _mm_subs_epi8(*q0, *p0); // q0 - p0 |
446 t1 = _mm_adds_epi8(t1, t2); // hev(p1 - q1) + 1 * (q0 - p0) | 446 t1 = _mm_adds_epi8(t1, t2); // hev(p1 - q1) + 1 * (q0 - p0) |
447 t1 = _mm_adds_epi8(t1, t2); // hev(p1 - q1) + 2 * (q0 - p0) | 447 t1 = _mm_adds_epi8(t1, t2); // hev(p1 - q1) + 2 * (q0 - p0) |
448 t1 = _mm_adds_epi8(t1, t2); // hev(p1 - q1) + 3 * (q0 - p0) | 448 t1 = _mm_adds_epi8(t1, t2); // hev(p1 - q1) + 3 * (q0 - p0) |
449 t1 = _mm_and_si128(t1, *mask); // mask filter values we don't care about | 449 t1 = _mm_and_si128(t1, *mask); // mask filter values we don't care about |
450 | 450 |
451 t2 = _mm_set1_epi8(3); | 451 t2 = _mm_adds_epi8(t1, k3); // 3 * (q0 - p0) + hev(p1 - q1) + 3 |
452 t3 = _mm_set1_epi8(4); | 452 t3 = _mm_adds_epi8(t1, k4); // 3 * (q0 - p0) + hev(p1 - q1) + 4 |
453 t2 = _mm_adds_epi8(t1, t2); // 3 * (q0 - p0) + (p1 - q1) + 3 | |
454 t3 = _mm_adds_epi8(t1, t3); // 3 * (q0 - p0) + (p1 - q1) + 4 | |
455 SignedShift8b(&t2); // (3 * (q0 - p0) + hev(p1 - q1) + 3) >> 3 | 453 SignedShift8b(&t2); // (3 * (q0 - p0) + hev(p1 - q1) + 3) >> 3 |
456 SignedShift8b(&t3); // (3 * (q0 - p0) + hev(p1 - q1) + 4) >> 3 | 454 SignedShift8b(&t3); // (3 * (q0 - p0) + hev(p1 - q1) + 4) >> 3 |
457 *p0 = _mm_adds_epi8(*p0, t2); // p0 += t2 | 455 *p0 = _mm_adds_epi8(*p0, t2); // p0 += t2 |
458 *q0 = _mm_subs_epi8(*q0, t3); // q0 -= t3 | 456 *q0 = _mm_subs_epi8(*q0, t3); // q0 -= t3 |
459 FLIP_SIGN_BIT2(*p0, *q0); | 457 FLIP_SIGN_BIT2(*p0, *q0); |
460 | 458 |
461 // this is equivalent to signed (a + 1) >> 1 calculation | 459 // this is equivalent to signed (a + 1) >> 1 calculation |
462 t2 = _mm_add_epi8(t3, sign_bit); | 460 t2 = _mm_add_epi8(t3, sign_bit); |
463 t3 = _mm_avg_epu8(t2, zero); | 461 t3 = _mm_avg_epu8(t2, zero); |
464 t3 = _mm_sub_epi8(t3, k64); | 462 t3 = _mm_sub_epi8(t3, k64); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 const __m128i a0_lo = _mm_add_epi16(a1_lo, f9_lo); // Filter * 27 + 63 | 511 const __m128i a0_lo = _mm_add_epi16(a1_lo, f9_lo); // Filter * 27 + 63 |
514 const __m128i a0_hi = _mm_add_epi16(a1_hi, f9_hi); // Filter * 27 + 63 | 512 const __m128i a0_hi = _mm_add_epi16(a1_hi, f9_hi); // Filter * 27 + 63 |
515 | 513 |
516 Update2Pixels(p2, q2, &a2_lo, &a2_hi); | 514 Update2Pixels(p2, q2, &a2_lo, &a2_hi); |
517 Update2Pixels(p1, q1, &a1_lo, &a1_hi); | 515 Update2Pixels(p1, q1, &a1_lo, &a1_hi); |
518 Update2Pixels(p0, q0, &a0_lo, &a0_hi); | 516 Update2Pixels(p0, q0, &a0_lo, &a0_hi); |
519 } | 517 } |
520 } | 518 } |
521 | 519 |
522 // reads 8 rows across a vertical edge. | 520 // reads 8 rows across a vertical edge. |
523 // | |
524 // TODO(somnath): Investigate _mm_shuffle* also see if it can be broken into | |
525 // two Load4x4() to avoid code duplication. | |
526 static WEBP_INLINE void Load8x4(const uint8_t* const b, int stride, | 521 static WEBP_INLINE void Load8x4(const uint8_t* const b, int stride, |
527 __m128i* const p, __m128i* const q) { | 522 __m128i* const p, __m128i* const q) { |
528 __m128i t1, t2; | 523 // A0 = 63 62 61 60 23 22 21 20 43 42 41 40 03 02 01 00 |
| 524 // A1 = 73 72 71 70 33 32 31 30 53 52 51 50 13 12 11 10 |
| 525 const __m128i A0 = _mm_set_epi32( |
| 526 WebPMemToUint32(&b[6 * stride]), WebPMemToUint32(&b[2 * stride]), |
| 527 WebPMemToUint32(&b[4 * stride]), WebPMemToUint32(&b[0 * stride])); |
| 528 const __m128i A1 = _mm_set_epi32( |
| 529 WebPMemToUint32(&b[7 * stride]), WebPMemToUint32(&b[3 * stride]), |
| 530 WebPMemToUint32(&b[5 * stride]), WebPMemToUint32(&b[1 * stride])); |
529 | 531 |
530 // Load 0th, 1st, 4th and 5th rows | 532 // B0 = 53 43 52 42 51 41 50 40 13 03 12 02 11 01 10 00 |
531 __m128i r0 = _mm_cvtsi32_si128(*((int*)&b[0 * stride])); // 03 02 01 00 | 533 // B1 = 73 63 72 62 71 61 70 60 33 23 32 22 31 21 30 20 |
532 __m128i r1 = _mm_cvtsi32_si128(*((int*)&b[1 * stride])); // 13 12 11 10 | 534 const __m128i B0 = _mm_unpacklo_epi8(A0, A1); |
533 __m128i r4 = _mm_cvtsi32_si128(*((int*)&b[4 * stride])); // 43 42 41 40 | 535 const __m128i B1 = _mm_unpackhi_epi8(A0, A1); |
534 __m128i r5 = _mm_cvtsi32_si128(*((int*)&b[5 * stride])); // 53 52 51 50 | |
535 | 536 |
536 r0 = _mm_unpacklo_epi32(r0, r4); // 43 42 41 40 03 02 01 00 | 537 // C0 = 33 23 13 03 32 22 12 02 31 21 11 01 30 20 10 00 |
537 r1 = _mm_unpacklo_epi32(r1, r5); // 53 52 51 50 13 12 11 10 | 538 // C1 = 73 63 53 43 72 62 52 42 71 61 51 41 70 60 50 40 |
538 | 539 const __m128i C0 = _mm_unpacklo_epi16(B0, B1); |
539 // t1 = 53 43 52 42 51 41 50 40 13 03 12 02 11 01 10 00 | 540 const __m128i C1 = _mm_unpackhi_epi16(B0, B1); |
540 t1 = _mm_unpacklo_epi8(r0, r1); | |
541 | |
542 // Load 2nd, 3rd, 6th and 7th rows | |
543 r0 = _mm_cvtsi32_si128(*((int*)&b[2 * stride])); // 23 22 21 22 | |
544 r1 = _mm_cvtsi32_si128(*((int*)&b[3 * stride])); // 33 32 31 30 | |
545 r4 = _mm_cvtsi32_si128(*((int*)&b[6 * stride])); // 63 62 61 60 | |
546 r5 = _mm_cvtsi32_si128(*((int*)&b[7 * stride])); // 73 72 71 70 | |
547 | |
548 r0 = _mm_unpacklo_epi32(r0, r4); // 63 62 61 60 23 22 21 20 | |
549 r1 = _mm_unpacklo_epi32(r1, r5); // 73 72 71 70 33 32 31 30 | |
550 | |
551 // t2 = 73 63 72 62 71 61 70 60 33 23 32 22 31 21 30 20 | |
552 t2 = _mm_unpacklo_epi8(r0, r1); | |
553 | |
554 // t1 = 33 23 13 03 32 22 12 02 31 21 11 01 30 20 10 00 | |
555 // t2 = 73 63 53 43 72 62 52 42 71 61 51 41 70 60 50 40 | |
556 r0 = t1; | |
557 t1 = _mm_unpacklo_epi16(t1, t2); | |
558 t2 = _mm_unpackhi_epi16(r0, t2); | |
559 | 541 |
560 // *p = 71 61 51 41 31 21 11 01 70 60 50 40 30 20 10 00 | 542 // *p = 71 61 51 41 31 21 11 01 70 60 50 40 30 20 10 00 |
561 // *q = 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02 | 543 // *q = 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02 |
562 *p = _mm_unpacklo_epi32(t1, t2); | 544 *p = _mm_unpacklo_epi32(C0, C1); |
563 *q = _mm_unpackhi_epi32(t1, t2); | 545 *q = _mm_unpackhi_epi32(C0, C1); |
564 } | 546 } |
565 | 547 |
566 static WEBP_INLINE void Load16x4(const uint8_t* const r0, | 548 static WEBP_INLINE void Load16x4(const uint8_t* const r0, |
567 const uint8_t* const r8, | 549 const uint8_t* const r8, |
568 int stride, | 550 int stride, |
569 __m128i* const p1, __m128i* const p0, | 551 __m128i* const p1, __m128i* const p0, |
570 __m128i* const q0, __m128i* const q1) { | 552 __m128i* const q0, __m128i* const q1) { |
571 __m128i t1, t2; | |
572 // Assume the pixels around the edge (|) are numbered as follows | 553 // Assume the pixels around the edge (|) are numbered as follows |
573 // 00 01 | 02 03 | 554 // 00 01 | 02 03 |
574 // 10 11 | 12 13 | 555 // 10 11 | 12 13 |
575 // ... | ... | 556 // ... | ... |
576 // e0 e1 | e2 e3 | 557 // e0 e1 | e2 e3 |
577 // f0 f1 | f2 f3 | 558 // f0 f1 | f2 f3 |
578 // | 559 // |
579 // r0 is pointing to the 0th row (00) | 560 // r0 is pointing to the 0th row (00) |
580 // r8 is pointing to the 8th row (80) | 561 // r8 is pointing to the 8th row (80) |
581 | 562 |
582 // Load | 563 // Load |
583 // p1 = 71 61 51 41 31 21 11 01 70 60 50 40 30 20 10 00 | 564 // p1 = 71 61 51 41 31 21 11 01 70 60 50 40 30 20 10 00 |
584 // q0 = 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02 | 565 // q0 = 73 63 53 43 33 23 13 03 72 62 52 42 32 22 12 02 |
585 // p0 = f1 e1 d1 c1 b1 a1 91 81 f0 e0 d0 c0 b0 a0 90 80 | 566 // p0 = f1 e1 d1 c1 b1 a1 91 81 f0 e0 d0 c0 b0 a0 90 80 |
586 // q1 = f3 e3 d3 c3 b3 a3 93 83 f2 e2 d2 c2 b2 a2 92 82 | 567 // q1 = f3 e3 d3 c3 b3 a3 93 83 f2 e2 d2 c2 b2 a2 92 82 |
587 Load8x4(r0, stride, p1, q0); | 568 Load8x4(r0, stride, p1, q0); |
588 Load8x4(r8, stride, p0, q1); | 569 Load8x4(r8, stride, p0, q1); |
589 | 570 |
590 t1 = *p1; | 571 { |
591 t2 = *q0; | 572 // p1 = f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00 |
592 // p1 = f0 e0 d0 c0 b0 a0 90 80 70 60 50 40 30 20 10 00 | 573 // p0 = f1 e1 d1 c1 b1 a1 91 81 71 61 51 41 31 21 11 01 |
593 // p0 = f1 e1 d1 c1 b1 a1 91 81 71 61 51 41 31 21 11 01 | 574 // q0 = f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02 |
594 // q0 = f2 e2 d2 c2 b2 a2 92 82 72 62 52 42 32 22 12 02 | 575 // q1 = f3 e3 d3 c3 b3 a3 93 83 73 63 53 43 33 23 13 03 |
595 // q1 = f3 e3 d3 c3 b3 a3 93 83 73 63 53 43 33 23 13 03 | 576 const __m128i t1 = *p1; |
596 *p1 = _mm_unpacklo_epi64(t1, *p0); | 577 const __m128i t2 = *q0; |
597 *p0 = _mm_unpackhi_epi64(t1, *p0); | 578 *p1 = _mm_unpacklo_epi64(t1, *p0); |
598 *q0 = _mm_unpacklo_epi64(t2, *q1); | 579 *p0 = _mm_unpackhi_epi64(t1, *p0); |
599 *q1 = _mm_unpackhi_epi64(t2, *q1); | 580 *q0 = _mm_unpacklo_epi64(t2, *q1); |
| 581 *q1 = _mm_unpackhi_epi64(t2, *q1); |
| 582 } |
600 } | 583 } |
601 | 584 |
602 static WEBP_INLINE void Store4x4(__m128i* const x, uint8_t* dst, int stride) { | 585 static WEBP_INLINE void Store4x4(__m128i* const x, uint8_t* dst, int stride) { |
603 int i; | 586 int i; |
604 for (i = 0; i < 4; ++i, dst += stride) { | 587 for (i = 0; i < 4; ++i, dst += stride) { |
605 *((int32_t*)dst) = _mm_cvtsi128_si32(*x); | 588 WebPUint32ToMem(dst, _mm_cvtsi128_si32(*x)); |
606 *x = _mm_srli_si128(*x, 4); | 589 *x = _mm_srli_si128(*x, 4); |
607 } | 590 } |
608 } | 591 } |
609 | 592 |
610 // Transpose back and store | 593 // Transpose back and store |
611 static WEBP_INLINE void Store16x4(const __m128i* const p1, | 594 static WEBP_INLINE void Store16x4(const __m128i* const p1, |
612 const __m128i* const p0, | 595 const __m128i* const p0, |
613 const __m128i* const q0, | 596 const __m128i* const q0, |
614 const __m128i* const q1, | 597 const __m128i* const q1, |
615 uint8_t* r0, uint8_t* r8, | 598 uint8_t* r0, uint8_t* r8, |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 MAX_DIFF2(t2, t1, q1, q0, mask); | 923 MAX_DIFF2(t2, t1, q1, q0, mask); |
941 | 924 |
942 ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); | 925 ComplexMask(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); |
943 DoFilter4(&p1, &p0, &q0, &q1, &mask, hev_thresh); | 926 DoFilter4(&p1, &p0, &q0, &q1, &mask, hev_thresh); |
944 | 927 |
945 u -= 2; // beginning of p1 | 928 u -= 2; // beginning of p1 |
946 v -= 2; | 929 v -= 2; |
947 Store16x4(&p1, &p0, &q0, &q1, u, v, stride); | 930 Store16x4(&p1, &p0, &q0, &q1, u, v, stride); |
948 } | 931 } |
949 | 932 |
950 #endif // WEBP_USE_SSE2 | 933 //------------------------------------------------------------------------------ |
| 934 // 4x4 predictions |
| 935 |
| 936 #define DST(x, y) dst[(x) + (y) * BPS] |
| 937 #define AVG3(a, b, c) (((a) + 2 * (b) + (c) + 2) >> 2) |
| 938 |
| 939 // We use the following 8b-arithmetic tricks: |
| 940 // (a + 2 * b + c + 2) >> 2 = (AC + b + 1) >> 1 |
| 941 // where: AC = (a + c) >> 1 = [(a + c + 1) >> 1] - [(a^c) & 1] |
| 942 // and: |
| 943 // (a + 2 * b + c + 2) >> 2 = (AB + BC + 1) >> 1 - (ab|bc)&lsb |
| 944 // where: AC = (a + b + 1) >> 1, BC = (b + c + 1) >> 1 |
| 945 // and ab = a ^ b, bc = b ^ c, lsb = (AC^BC)&1 |
| 946 |
| 947 static void VE4(uint8_t* dst) { // vertical |
| 948 const __m128i one = _mm_set1_epi8(1); |
| 949 const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS - 1)); |
| 950 const __m128i BCDEFGH0 = _mm_srli_si128(ABCDEFGH, 1); |
| 951 const __m128i CDEFGH00 = _mm_srli_si128(ABCDEFGH, 2); |
| 952 const __m128i a = _mm_avg_epu8(ABCDEFGH, CDEFGH00); |
| 953 const __m128i lsb = _mm_and_si128(_mm_xor_si128(ABCDEFGH, CDEFGH00), one); |
| 954 const __m128i b = _mm_subs_epu8(a, lsb); |
| 955 const __m128i avg = _mm_avg_epu8(b, BCDEFGH0); |
| 956 const uint32_t vals = _mm_cvtsi128_si32(avg); |
| 957 int i; |
| 958 for (i = 0; i < 4; ++i) { |
| 959 WebPUint32ToMem(dst + i * BPS, vals); |
| 960 } |
| 961 } |
| 962 |
| 963 static void LD4(uint8_t* dst) { // Down-Left |
| 964 const __m128i one = _mm_set1_epi8(1); |
| 965 const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS)); |
| 966 const __m128i BCDEFGH0 = _mm_srli_si128(ABCDEFGH, 1); |
| 967 const __m128i CDEFGH00 = _mm_srli_si128(ABCDEFGH, 2); |
| 968 const __m128i CDEFGHH0 = _mm_insert_epi16(CDEFGH00, dst[-BPS + 7], 3); |
| 969 const __m128i avg1 = _mm_avg_epu8(ABCDEFGH, CDEFGHH0); |
| 970 const __m128i lsb = _mm_and_si128(_mm_xor_si128(ABCDEFGH, CDEFGHH0), one); |
| 971 const __m128i avg2 = _mm_subs_epu8(avg1, lsb); |
| 972 const __m128i abcdefg = _mm_avg_epu8(avg2, BCDEFGH0); |
| 973 WebPUint32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32( abcdefg )); |
| 974 WebPUint32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 1))); |
| 975 WebPUint32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 2))); |
| 976 WebPUint32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 3))); |
| 977 } |
| 978 |
| 979 static void VR4(uint8_t* dst) { // Vertical-Right |
| 980 const __m128i one = _mm_set1_epi8(1); |
| 981 const int I = dst[-1 + 0 * BPS]; |
| 982 const int J = dst[-1 + 1 * BPS]; |
| 983 const int K = dst[-1 + 2 * BPS]; |
| 984 const int X = dst[-1 - BPS]; |
| 985 const __m128i XABCD = _mm_loadl_epi64((__m128i*)(dst - BPS - 1)); |
| 986 const __m128i ABCD0 = _mm_srli_si128(XABCD, 1); |
| 987 const __m128i abcd = _mm_avg_epu8(XABCD, ABCD0); |
| 988 const __m128i _XABCD = _mm_slli_si128(XABCD, 1); |
| 989 const __m128i IXABCD = _mm_insert_epi16(_XABCD, I | (X << 8), 0); |
| 990 const __m128i avg1 = _mm_avg_epu8(IXABCD, ABCD0); |
| 991 const __m128i lsb = _mm_and_si128(_mm_xor_si128(IXABCD, ABCD0), one); |
| 992 const __m128i avg2 = _mm_subs_epu8(avg1, lsb); |
| 993 const __m128i efgh = _mm_avg_epu8(avg2, XABCD); |
| 994 WebPUint32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32( abcd )); |
| 995 WebPUint32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32( efgh )); |
| 996 WebPUint32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_slli_si128(abcd, 1))); |
| 997 WebPUint32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(_mm_slli_si128(efgh, 1))); |
| 998 |
| 999 // these two are hard to implement in SSE2, so we keep the C-version: |
| 1000 DST(0, 2) = AVG3(J, I, X); |
| 1001 DST(0, 3) = AVG3(K, J, I); |
| 1002 } |
| 1003 |
| 1004 static void VL4(uint8_t* dst) { // Vertical-Left |
| 1005 const __m128i one = _mm_set1_epi8(1); |
| 1006 const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS)); |
| 1007 const __m128i BCDEFGH_ = _mm_srli_si128(ABCDEFGH, 1); |
| 1008 const __m128i CDEFGH__ = _mm_srli_si128(ABCDEFGH, 2); |
| 1009 const __m128i avg1 = _mm_avg_epu8(ABCDEFGH, BCDEFGH_); |
| 1010 const __m128i avg2 = _mm_avg_epu8(CDEFGH__, BCDEFGH_); |
| 1011 const __m128i avg3 = _mm_avg_epu8(avg1, avg2); |
| 1012 const __m128i lsb1 = _mm_and_si128(_mm_xor_si128(avg1, avg2), one); |
| 1013 const __m128i ab = _mm_xor_si128(ABCDEFGH, BCDEFGH_); |
| 1014 const __m128i bc = _mm_xor_si128(CDEFGH__, BCDEFGH_); |
| 1015 const __m128i abbc = _mm_or_si128(ab, bc); |
| 1016 const __m128i lsb2 = _mm_and_si128(abbc, lsb1); |
| 1017 const __m128i avg4 = _mm_subs_epu8(avg3, lsb2); |
| 1018 const uint32_t extra_out = _mm_cvtsi128_si32(_mm_srli_si128(avg4, 4)); |
| 1019 WebPUint32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32( avg1 )); |
| 1020 WebPUint32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32( avg4 )); |
| 1021 WebPUint32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(avg1, 1))); |
| 1022 WebPUint32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(avg4, 1))); |
| 1023 |
| 1024 // these two are hard to get and irregular |
| 1025 DST(3, 2) = (extra_out >> 0) & 0xff; |
| 1026 DST(3, 3) = (extra_out >> 8) & 0xff; |
| 1027 } |
| 1028 |
| 1029 static void RD4(uint8_t* dst) { // Down-right |
| 1030 const __m128i one = _mm_set1_epi8(1); |
| 1031 const __m128i XABCD = _mm_loadl_epi64((__m128i*)(dst - BPS - 1)); |
| 1032 const __m128i ____XABCD = _mm_slli_si128(XABCD, 4); |
| 1033 const uint32_t I = dst[-1 + 0 * BPS]; |
| 1034 const uint32_t J = dst[-1 + 1 * BPS]; |
| 1035 const uint32_t K = dst[-1 + 2 * BPS]; |
| 1036 const uint32_t L = dst[-1 + 3 * BPS]; |
| 1037 const __m128i LKJI_____ = |
| 1038 _mm_cvtsi32_si128(L | (K << 8) | (J << 16) | (I << 24)); |
| 1039 const __m128i LKJIXABCD = _mm_or_si128(LKJI_____, ____XABCD); |
| 1040 const __m128i KJIXABCD_ = _mm_srli_si128(LKJIXABCD, 1); |
| 1041 const __m128i JIXABCD__ = _mm_srli_si128(LKJIXABCD, 2); |
| 1042 const __m128i avg1 = _mm_avg_epu8(JIXABCD__, LKJIXABCD); |
| 1043 const __m128i lsb = _mm_and_si128(_mm_xor_si128(JIXABCD__, LKJIXABCD), one); |
| 1044 const __m128i avg2 = _mm_subs_epu8(avg1, lsb); |
| 1045 const __m128i abcdefg = _mm_avg_epu8(avg2, KJIXABCD_); |
| 1046 WebPUint32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32( abcdefg )); |
| 1047 WebPUint32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 1))); |
| 1048 WebPUint32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 2))); |
| 1049 WebPUint32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 3))); |
| 1050 } |
| 1051 |
| 1052 #undef DST |
| 1053 #undef AVG3 |
| 1054 |
| 1055 //------------------------------------------------------------------------------ |
| 1056 // Luma 16x16 |
| 1057 |
| 1058 static WEBP_INLINE void TrueMotion(uint8_t* dst, int size) { |
| 1059 const uint8_t* top = dst - BPS; |
| 1060 const __m128i zero = _mm_setzero_si128(); |
| 1061 int y; |
| 1062 if (size == 4) { |
| 1063 const __m128i top_values = _mm_cvtsi32_si128(WebPMemToUint32(top)); |
| 1064 const __m128i top_base = _mm_unpacklo_epi8(top_values, zero); |
| 1065 for (y = 0; y < 4; ++y, dst += BPS) { |
| 1066 const int val = dst[-1] - top[-1]; |
| 1067 const __m128i base = _mm_set1_epi16(val); |
| 1068 const __m128i out = _mm_packus_epi16(_mm_add_epi16(base, top_base), zero); |
| 1069 WebPUint32ToMem(dst, _mm_cvtsi128_si32(out)); |
| 1070 } |
| 1071 } else if (size == 8) { |
| 1072 const __m128i top_values = _mm_loadl_epi64((const __m128i*)top); |
| 1073 const __m128i top_base = _mm_unpacklo_epi8(top_values, zero); |
| 1074 for (y = 0; y < 8; ++y, dst += BPS) { |
| 1075 const int val = dst[-1] - top[-1]; |
| 1076 const __m128i base = _mm_set1_epi16(val); |
| 1077 const __m128i out = _mm_packus_epi16(_mm_add_epi16(base, top_base), zero); |
| 1078 _mm_storel_epi64((__m128i*)dst, out); |
| 1079 } |
| 1080 } else { |
| 1081 const __m128i top_values = _mm_loadu_si128((const __m128i*)top); |
| 1082 const __m128i top_base_0 = _mm_unpacklo_epi8(top_values, zero); |
| 1083 const __m128i top_base_1 = _mm_unpackhi_epi8(top_values, zero); |
| 1084 for (y = 0; y < 16; ++y, dst += BPS) { |
| 1085 const int val = dst[-1] - top[-1]; |
| 1086 const __m128i base = _mm_set1_epi16(val); |
| 1087 const __m128i out_0 = _mm_add_epi16(base, top_base_0); |
| 1088 const __m128i out_1 = _mm_add_epi16(base, top_base_1); |
| 1089 const __m128i out = _mm_packus_epi16(out_0, out_1); |
| 1090 _mm_storeu_si128((__m128i*)dst, out); |
| 1091 } |
| 1092 } |
| 1093 } |
| 1094 |
| 1095 static void TM4(uint8_t* dst) { TrueMotion(dst, 4); } |
| 1096 static void TM8uv(uint8_t* dst) { TrueMotion(dst, 8); } |
| 1097 static void TM16(uint8_t* dst) { TrueMotion(dst, 16); } |
| 1098 |
| 1099 static void VE16(uint8_t* dst) { |
| 1100 const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS)); |
| 1101 int j; |
| 1102 for (j = 0; j < 16; ++j) { |
| 1103 _mm_storeu_si128((__m128i*)(dst + j * BPS), top); |
| 1104 } |
| 1105 } |
| 1106 |
| 1107 static void HE16(uint8_t* dst) { // horizontal |
| 1108 int j; |
| 1109 for (j = 16; j > 0; --j) { |
| 1110 const __m128i values = _mm_set1_epi8(dst[-1]); |
| 1111 _mm_storeu_si128((__m128i*)dst, values); |
| 1112 dst += BPS; |
| 1113 } |
| 1114 } |
| 1115 |
| 1116 static WEBP_INLINE void Put16(uint8_t v, uint8_t* dst) { |
| 1117 int j; |
| 1118 const __m128i values = _mm_set1_epi8(v); |
| 1119 for (j = 0; j < 16; ++j) { |
| 1120 _mm_storeu_si128((__m128i*)(dst + j * BPS), values); |
| 1121 } |
| 1122 } |
| 1123 |
| 1124 static void DC16(uint8_t* dst) { // DC |
| 1125 const __m128i zero = _mm_setzero_si128(); |
| 1126 const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS)); |
| 1127 const __m128i sad8x2 = _mm_sad_epu8(top, zero); |
| 1128 // sum the two sads: sad8x2[0:1] + sad8x2[8:9] |
| 1129 const __m128i sum = _mm_add_epi16(sad8x2, _mm_shuffle_epi32(sad8x2, 2)); |
| 1130 int left = 0; |
| 1131 int j; |
| 1132 for (j = 0; j < 16; ++j) { |
| 1133 left += dst[-1 + j * BPS]; |
| 1134 } |
| 1135 { |
| 1136 const int DC = _mm_cvtsi128_si32(sum) + left + 16; |
| 1137 Put16(DC >> 5, dst); |
| 1138 } |
| 1139 } |
| 1140 |
| 1141 static void DC16NoTop(uint8_t* dst) { // DC with top samples not available |
| 1142 int DC = 8; |
| 1143 int j; |
| 1144 for (j = 0; j < 16; ++j) { |
| 1145 DC += dst[-1 + j * BPS]; |
| 1146 } |
| 1147 Put16(DC >> 4, dst); |
| 1148 } |
| 1149 |
| 1150 static void DC16NoLeft(uint8_t* dst) { // DC with left samples not available |
| 1151 const __m128i zero = _mm_setzero_si128(); |
| 1152 const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS)); |
| 1153 const __m128i sad8x2 = _mm_sad_epu8(top, zero); |
| 1154 // sum the two sads: sad8x2[0:1] + sad8x2[8:9] |
| 1155 const __m128i sum = _mm_add_epi16(sad8x2, _mm_shuffle_epi32(sad8x2, 2)); |
| 1156 const int DC = _mm_cvtsi128_si32(sum) + 8; |
| 1157 Put16(DC >> 4, dst); |
| 1158 } |
| 1159 |
| 1160 static void DC16NoTopLeft(uint8_t* dst) { // DC with no top and left samples |
| 1161 Put16(0x80, dst); |
| 1162 } |
| 1163 |
| 1164 //------------------------------------------------------------------------------ |
| 1165 // Chroma |
| 1166 |
| 1167 static void VE8uv(uint8_t* dst) { // vertical |
| 1168 int j; |
| 1169 const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS)); |
| 1170 for (j = 0; j < 8; ++j) { |
| 1171 _mm_storel_epi64((__m128i*)(dst + j * BPS), top); |
| 1172 } |
| 1173 } |
| 1174 |
| 1175 static void HE8uv(uint8_t* dst) { // horizontal |
| 1176 int j; |
| 1177 for (j = 0; j < 8; ++j) { |
| 1178 const __m128i values = _mm_set1_epi8(dst[-1]); |
| 1179 _mm_storel_epi64((__m128i*)dst, values); |
| 1180 dst += BPS; |
| 1181 } |
| 1182 } |
| 1183 |
| 1184 // helper for chroma-DC predictions |
| 1185 static WEBP_INLINE void Put8x8uv(uint8_t v, uint8_t* dst) { |
| 1186 int j; |
| 1187 const __m128i values = _mm_set1_epi8(v); |
| 1188 for (j = 0; j < 8; ++j) { |
| 1189 _mm_storel_epi64((__m128i*)(dst + j * BPS), values); |
| 1190 } |
| 1191 } |
| 1192 |
| 1193 static void DC8uv(uint8_t* dst) { // DC |
| 1194 const __m128i zero = _mm_setzero_si128(); |
| 1195 const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS)); |
| 1196 const __m128i sum = _mm_sad_epu8(top, zero); |
| 1197 int left = 0; |
| 1198 int j; |
| 1199 for (j = 0; j < 8; ++j) { |
| 1200 left += dst[-1 + j * BPS]; |
| 1201 } |
| 1202 { |
| 1203 const int DC = _mm_cvtsi128_si32(sum) + left + 8; |
| 1204 Put8x8uv(DC >> 4, dst); |
| 1205 } |
| 1206 } |
| 1207 |
| 1208 static void DC8uvNoLeft(uint8_t* dst) { // DC with no left samples |
| 1209 const __m128i zero = _mm_setzero_si128(); |
| 1210 const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS)); |
| 1211 const __m128i sum = _mm_sad_epu8(top, zero); |
| 1212 const int DC = _mm_cvtsi128_si32(sum) + 4; |
| 1213 Put8x8uv(DC >> 3, dst); |
| 1214 } |
| 1215 |
| 1216 static void DC8uvNoTop(uint8_t* dst) { // DC with no top samples |
| 1217 int dc0 = 4; |
| 1218 int i; |
| 1219 for (i = 0; i < 8; ++i) { |
| 1220 dc0 += dst[-1 + i * BPS]; |
| 1221 } |
| 1222 Put8x8uv(dc0 >> 3, dst); |
| 1223 } |
| 1224 |
| 1225 static void DC8uvNoTopLeft(uint8_t* dst) { // DC with nothing |
| 1226 Put8x8uv(0x80, dst); |
| 1227 } |
951 | 1228 |
952 //------------------------------------------------------------------------------ | 1229 //------------------------------------------------------------------------------ |
953 // Entry point | 1230 // Entry point |
954 | 1231 |
955 extern void VP8DspInitSSE2(void); | 1232 extern void VP8DspInitSSE2(void); |
956 | 1233 |
957 void VP8DspInitSSE2(void) { | 1234 WEBP_TSAN_IGNORE_FUNCTION void VP8DspInitSSE2(void) { |
958 #if defined(WEBP_USE_SSE2) | |
959 VP8Transform = Transform; | 1235 VP8Transform = Transform; |
960 #if defined(USE_TRANSFORM_AC3) | 1236 #if defined(USE_TRANSFORM_AC3) |
961 VP8TransformAC3 = TransformAC3; | 1237 VP8TransformAC3 = TransformAC3; |
962 #endif | 1238 #endif |
963 | 1239 |
964 VP8VFilter16 = VFilter16; | 1240 VP8VFilter16 = VFilter16; |
965 VP8HFilter16 = HFilter16; | 1241 VP8HFilter16 = HFilter16; |
966 VP8VFilter8 = VFilter8; | 1242 VP8VFilter8 = VFilter8; |
967 VP8HFilter8 = HFilter8; | 1243 VP8HFilter8 = HFilter8; |
968 VP8VFilter16i = VFilter16i; | 1244 VP8VFilter16i = VFilter16i; |
969 VP8HFilter16i = HFilter16i; | 1245 VP8HFilter16i = HFilter16i; |
970 VP8VFilter8i = VFilter8i; | 1246 VP8VFilter8i = VFilter8i; |
971 VP8HFilter8i = HFilter8i; | 1247 VP8HFilter8i = HFilter8i; |
972 | 1248 |
973 VP8SimpleVFilter16 = SimpleVFilter16; | 1249 VP8SimpleVFilter16 = SimpleVFilter16; |
974 VP8SimpleHFilter16 = SimpleHFilter16; | 1250 VP8SimpleHFilter16 = SimpleHFilter16; |
975 VP8SimpleVFilter16i = SimpleVFilter16i; | 1251 VP8SimpleVFilter16i = SimpleVFilter16i; |
976 VP8SimpleHFilter16i = SimpleHFilter16i; | 1252 VP8SimpleHFilter16i = SimpleHFilter16i; |
977 #endif // WEBP_USE_SSE2 | 1253 |
| 1254 VP8PredLuma4[1] = TM4; |
| 1255 VP8PredLuma4[2] = VE4; |
| 1256 VP8PredLuma4[4] = RD4; |
| 1257 VP8PredLuma4[5] = VR4; |
| 1258 VP8PredLuma4[6] = LD4; |
| 1259 VP8PredLuma4[7] = VL4; |
| 1260 |
| 1261 VP8PredLuma16[0] = DC16; |
| 1262 VP8PredLuma16[1] = TM16; |
| 1263 VP8PredLuma16[2] = VE16; |
| 1264 VP8PredLuma16[3] = HE16; |
| 1265 VP8PredLuma16[4] = DC16NoTop; |
| 1266 VP8PredLuma16[5] = DC16NoLeft; |
| 1267 VP8PredLuma16[6] = DC16NoTopLeft; |
| 1268 |
| 1269 VP8PredChroma8[0] = DC8uv; |
| 1270 VP8PredChroma8[1] = TM8uv; |
| 1271 VP8PredChroma8[2] = VE8uv; |
| 1272 VP8PredChroma8[3] = HE8uv; |
| 1273 VP8PredChroma8[4] = DC8uvNoTop; |
| 1274 VP8PredChroma8[5] = DC8uvNoLeft; |
| 1275 VP8PredChroma8[6] = DC8uvNoTopLeft; |
978 } | 1276 } |
| 1277 |
| 1278 #else // !WEBP_USE_SSE2 |
| 1279 |
| 1280 WEBP_DSP_INIT_STUB(VP8DspInitSSE2) |
| 1281 |
| 1282 #endif // WEBP_USE_SSE2 |
OLD | NEW |