| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "src/dsp/dsp.h" |
| 16 |
|
| 17 |
#if defined(WEBP_USE_SSE2) |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#if !defined(USE_TRANSFORM_AC3) |
| 22 |
#define USE_TRANSFORM_AC3 0 // ALTERNATE_CODE |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <emmintrin.h> |
| 26 |
#include "src/dsp/common_sse2.h" |
| 27 |
#include "src/dec/vp8i_dec.h" |
| 28 |
#include "src/utils/utils.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
static void Transform_SSE2(const int16_t* in, uint8_t* dst, int do_two) { |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
const __m128i k1 = _mm_set1_epi16(20091); |
| 51 |
const __m128i k2 = _mm_set1_epi16(-30068); |
| 52 |
__m128i T0, T1, T2, T3; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
__m128i in0, in1, in2, in3; |
| 58 |
{ |
| 59 |
in0 = _mm_loadl_epi64((const __m128i*)&in[0]); |
| 60 |
in1 = _mm_loadl_epi64((const __m128i*)&in[4]); |
| 61 |
in2 = _mm_loadl_epi64((const __m128i*)&in[8]); |
| 62 |
in3 = _mm_loadl_epi64((const __m128i*)&in[12]); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if (do_two) { |
| 68 |
const __m128i inB0 = _mm_loadl_epi64((const __m128i*)&in[16]); |
| 69 |
const __m128i inB1 = _mm_loadl_epi64((const __m128i*)&in[20]); |
| 70 |
const __m128i inB2 = _mm_loadl_epi64((const __m128i*)&in[24]); |
| 71 |
const __m128i inB3 = _mm_loadl_epi64((const __m128i*)&in[28]); |
| 72 |
in0 = _mm_unpacklo_epi64(in0, inB0); |
| 73 |
in1 = _mm_unpacklo_epi64(in1, inB1); |
| 74 |
in2 = _mm_unpacklo_epi64(in2, inB2); |
| 75 |
in3 = _mm_unpacklo_epi64(in3, inB3); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
{ |
| 85 |
|
| 86 |
|
| 87 |
const __m128i a = _mm_add_epi16(in0, in2); |
| 88 |
const __m128i b = _mm_sub_epi16(in0, in2); |
| 89 |
|
| 90 |
const __m128i c1 = _mm_mulhi_epi16(in1, k2); |
| 91 |
const __m128i c2 = _mm_mulhi_epi16(in3, k1); |
| 92 |
const __m128i c3 = _mm_sub_epi16(in1, in3); |
| 93 |
const __m128i c4 = _mm_sub_epi16(c1, c2); |
| 94 |
const __m128i c = _mm_add_epi16(c3, c4); |
| 95 |
|
| 96 |
const __m128i d1 = _mm_mulhi_epi16(in1, k1); |
| 97 |
const __m128i d2 = _mm_mulhi_epi16(in3, k2); |
| 98 |
const __m128i d3 = _mm_add_epi16(in1, in3); |
| 99 |
const __m128i d4 = _mm_add_epi16(d1, d2); |
| 100 |
const __m128i d = _mm_add_epi16(d3, d4); |
| 101 |
|
| 102 |
|
| 103 |
const __m128i tmp0 = _mm_add_epi16(a, d); |
| 104 |
const __m128i tmp1 = _mm_add_epi16(b, c); |
| 105 |
const __m128i tmp2 = _mm_sub_epi16(b, c); |
| 106 |
const __m128i tmp3 = _mm_sub_epi16(a, d); |
| 107 |
|
| 108 |
|
| 109 |
VP8Transpose_2_4x4_16b(&tmp0, &tmp1, &tmp2, &tmp3, &T0, &T1, &T2, &T3); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
{ |
| 114 |
|
| 115 |
|
| 116 |
const __m128i four = _mm_set1_epi16(4); |
| 117 |
const __m128i dc = _mm_add_epi16(T0, four); |
| 118 |
const __m128i a = _mm_add_epi16(dc, T2); |
| 119 |
const __m128i b = _mm_sub_epi16(dc, T2); |
| 120 |
|
| 121 |
const __m128i c1 = _mm_mulhi_epi16(T1, k2); |
| 122 |
const __m128i c2 = _mm_mulhi_epi16(T3, k1); |
| 123 |
const __m128i c3 = _mm_sub_epi16(T1, T3); |
| 124 |
const __m128i c4 = _mm_sub_epi16(c1, c2); |
| 125 |
const __m128i c = _mm_add_epi16(c3, c4); |
| 126 |
|
| 127 |
const __m128i d1 = _mm_mulhi_epi16(T1, k1); |
| 128 |
const __m128i d2 = _mm_mulhi_epi16(T3, k2); |
| 129 |
const __m128i d3 = _mm_add_epi16(T1, T3); |
| 130 |
const __m128i d4 = _mm_add_epi16(d1, d2); |
| 131 |
const __m128i d = _mm_add_epi16(d3, d4); |
| 132 |
|
| 133 |
|
| 134 |
const __m128i tmp0 = _mm_add_epi16(a, d); |
| 135 |
const __m128i tmp1 = _mm_add_epi16(b, c); |
| 136 |
const __m128i tmp2 = _mm_sub_epi16(b, c); |
| 137 |
const __m128i tmp3 = _mm_sub_epi16(a, d); |
| 138 |
const __m128i shifted0 = _mm_srai_epi16(tmp0, 3); |
| 139 |
const __m128i shifted1 = _mm_srai_epi16(tmp1, 3); |
| 140 |
const __m128i shifted2 = _mm_srai_epi16(tmp2, 3); |
| 141 |
const __m128i shifted3 = _mm_srai_epi16(tmp3, 3); |
| 142 |
|
| 143 |
|
| 144 |
VP8Transpose_2_4x4_16b(&shifted0, &shifted1, &shifted2, &shifted3, &T0, &T1, |
| 145 |
&T2, &T3); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
{ |
| 150 |
const __m128i zero = _mm_setzero_si128(); |
| 151 |
|
| 152 |
__m128i dst0, dst1, dst2, dst3; |
| 153 |
if (do_two) { |
| 154 |
|
| 155 |
dst0 = _mm_loadl_epi64((__m128i*)(dst + 0 * BPS)); |
| 156 |
dst1 = _mm_loadl_epi64((__m128i*)(dst + 1 * BPS)); |
| 157 |
dst2 = _mm_loadl_epi64((__m128i*)(dst + 2 * BPS)); |
| 158 |
dst3 = _mm_loadl_epi64((__m128i*)(dst + 3 * BPS)); |
| 159 |
} else { |
| 160 |
|
| 161 |
dst0 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 0 * BPS)); |
| 162 |
dst1 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 1 * BPS)); |
| 163 |
dst2 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 2 * BPS)); |
| 164 |
dst3 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 3 * BPS)); |
| 165 |
} |
| 166 |
|
| 167 |
dst0 = _mm_unpacklo_epi8(dst0, zero); |
| 168 |
dst1 = _mm_unpacklo_epi8(dst1, zero); |
| 169 |
dst2 = _mm_unpacklo_epi8(dst2, zero); |
| 170 |
dst3 = _mm_unpacklo_epi8(dst3, zero); |
| 171 |
|
| 172 |
dst0 = _mm_add_epi16(dst0, T0); |
| 173 |
dst1 = _mm_add_epi16(dst1, T1); |
| 174 |
dst2 = _mm_add_epi16(dst2, T2); |
| 175 |
dst3 = _mm_add_epi16(dst3, T3); |
| 176 |
|
| 177 |
dst0 = _mm_packus_epi16(dst0, dst0); |
| 178 |
dst1 = _mm_packus_epi16(dst1, dst1); |
| 179 |
dst2 = _mm_packus_epi16(dst2, dst2); |
| 180 |
dst3 = _mm_packus_epi16(dst3, dst3); |
| 181 |
|
| 182 |
if (do_two) { |
| 183 |
|
| 184 |
_mm_storel_epi64((__m128i*)(dst + 0 * BPS), dst0); |
| 185 |
_mm_storel_epi64((__m128i*)(dst + 1 * BPS), dst1); |
| 186 |
_mm_storel_epi64((__m128i*)(dst + 2 * BPS), dst2); |
| 187 |
_mm_storel_epi64((__m128i*)(dst + 3 * BPS), dst3); |
| 188 |
} else { |
| 189 |
|
| 190 |
WebPInt32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32(dst0)); |
| 191 |
WebPInt32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(dst1)); |
| 192 |
WebPInt32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(dst2)); |
| 193 |
WebPInt32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(dst3)); |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
#if (USE_TRANSFORM_AC3 == 1) |
| 199 |
|
| 200 |
static void TransformAC3(const int16_t* in, uint8_t* dst) { |
| 201 |
const __m128i A = _mm_set1_epi16(in[0] + 4); |
| 202 |
const __m128i c4 = _mm_set1_epi16(WEBP_TRANSFORM_AC3_MUL2(in[4])); |
| 203 |
const __m128i d4 = _mm_set1_epi16(WEBP_TRANSFORM_AC3_MUL1(in[4])); |
| 204 |
const int c1 = WEBP_TRANSFORM_AC3_MUL2(in[1]); |
| 205 |
const int d1 = WEBP_TRANSFORM_AC3_MUL1(in[1]); |
| 206 |
const __m128i CD = _mm_set_epi16(0, 0, 0, 0, -d1, -c1, c1, d1); |
| 207 |
const __m128i B = _mm_adds_epi16(A, CD); |
| 208 |
const __m128i m0 = _mm_adds_epi16(B, d4); |
| 209 |
const __m128i m1 = _mm_adds_epi16(B, c4); |
| 210 |
const __m128i m2 = _mm_subs_epi16(B, c4); |
| 211 |
const __m128i m3 = _mm_subs_epi16(B, d4); |
| 212 |
const __m128i zero = _mm_setzero_si128(); |
| 213 |
|
| 214 |
__m128i dst0 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 0 * BPS)); |
| 215 |
__m128i dst1 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 1 * BPS)); |
| 216 |
__m128i dst2 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 2 * BPS)); |
| 217 |
__m128i dst3 = _mm_cvtsi32_si128(WebPMemToInt32(dst + 3 * BPS)); |
| 218 |
|
| 219 |
dst0 = _mm_unpacklo_epi8(dst0, zero); |
| 220 |
dst1 = _mm_unpacklo_epi8(dst1, zero); |
| 221 |
dst2 = _mm_unpacklo_epi8(dst2, zero); |
| 222 |
dst3 = _mm_unpacklo_epi8(dst3, zero); |
| 223 |
|
| 224 |
dst0 = _mm_adds_epi16(dst0, _mm_srai_epi16(m0, 3)); |
| 225 |
dst1 = _mm_adds_epi16(dst1, _mm_srai_epi16(m1, 3)); |
| 226 |
dst2 = _mm_adds_epi16(dst2, _mm_srai_epi16(m2, 3)); |
| 227 |
dst3 = _mm_adds_epi16(dst3, _mm_srai_epi16(m3, 3)); |
| 228 |
|
| 229 |
dst0 = _mm_packus_epi16(dst0, dst0); |
| 230 |
dst1 = _mm_packus_epi16(dst1, dst1); |
| 231 |
dst2 = _mm_packus_epi16(dst2, dst2); |
| 232 |
dst3 = _mm_packus_epi16(dst3, dst3); |
| 233 |
|
| 234 |
WebPInt32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32(dst0)); |
| 235 |
WebPInt32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(dst1)); |
| 236 |
WebPInt32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(dst2)); |
| 237 |
WebPInt32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(dst3)); |
| 238 |
} |
| 239 |
|
| 240 |
#endif |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
#define MM_ABS(p, q) _mm_or_si128( \ |
| 247 |
_mm_subs_epu8((q), (p)), \ |
| 248 |
_mm_subs_epu8((p), (q))) |
| 249 |
|
| 250 |
|
| 251 |
static WEBP_INLINE void SignedShift8b_SSE2(__m128i* const x) { |
| 252 |
const __m128i zero = _mm_setzero_si128(); |
| 253 |
const __m128i lo_0 = _mm_unpacklo_epi8(zero, *x); |
| 254 |
const __m128i hi_0 = _mm_unpackhi_epi8(zero, *x); |
| 255 |
const __m128i lo_1 = _mm_srai_epi16(lo_0, 3 + 8); |
| 256 |
const __m128i hi_1 = _mm_srai_epi16(hi_0, 3 + 8); |
| 257 |
*x = _mm_packs_epi16(lo_1, hi_1); |
| 258 |
} |
| 259 |
|
| 260 |
#define FLIP_SIGN_BIT2(a, b) do { \ |
| 261 |
(a) = _mm_xor_si128(a, sign_bit); \ |
| 262 |
(b) = _mm_xor_si128(b, sign_bit); \ |
| 263 |
} while (0) |
| 264 |
|
| 265 |
#define FLIP_SIGN_BIT4(a, b, c, d) do { \ |
| 266 |
FLIP_SIGN_BIT2(a, b); \ |
| 267 |
FLIP_SIGN_BIT2(c, d); \ |
| 268 |
} while (0) |
| 269 |
|
| 270 |
|
| 271 |
static WEBP_INLINE void GetNotHEV_SSE2(const __m128i* const p1, |
| 272 |
const __m128i* const p0, |
| 273 |
const __m128i* const q0, |
| 274 |
const __m128i* const q1, |
| 275 |
int hev_thresh, __m128i* const not_hev) { |
| 276 |
const __m128i zero = _mm_setzero_si128(); |
| 277 |
const __m128i t_1 = MM_ABS(*p1, *p0); |
| 278 |
const __m128i t_2 = MM_ABS(*q1, *q0); |
| 279 |
|
| 280 |
const __m128i h = _mm_set1_epi8(hev_thresh); |
| 281 |
const __m128i t_max = _mm_max_epu8(t_1, t_2); |
| 282 |
|
| 283 |
const __m128i t_max_h = _mm_subs_epu8(t_max, h); |
| 284 |
*not_hev = _mm_cmpeq_epi8(t_max_h, zero); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
static WEBP_INLINE void GetBaseDelta_SSE2(const __m128i* const p1, |
| 289 |
const __m128i* const p0, |
| 290 |
const __m128i* const q0, |
| 291 |
const __m128i* const q1, |
| 292 |
__m128i* const delta) { |
| 293 |
|
| 294 |
const __m128i p1_q1 = _mm_subs_epi8(*p1, *q1); |
| 295 |
const __m128i q0_p0 = _mm_subs_epi8(*q0, *p0); |
| 296 |
const __m128i s1 = _mm_adds_epi8(p1_q1, q0_p0); |
| 297 |
const __m128i s2 = _mm_adds_epi8(q0_p0, s1); |
| 298 |
const __m128i s3 = _mm_adds_epi8(q0_p0, s2); |
| 299 |
*delta = s3; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
static WEBP_INLINE void DoSimpleFilter_SSE2(__m128i* const p0, |
| 304 |
__m128i* const q0, |
| 305 |
const __m128i* const fl) { |
| 306 |
const __m128i k3 = _mm_set1_epi8(3); |
| 307 |
const __m128i k4 = _mm_set1_epi8(4); |
| 308 |
__m128i v3 = _mm_adds_epi8(*fl, k3); |
| 309 |
__m128i v4 = _mm_adds_epi8(*fl, k4); |
| 310 |
|
| 311 |
SignedShift8b_SSE2(&v4); |
| 312 |
SignedShift8b_SSE2(&v3); |
| 313 |
*q0 = _mm_subs_epi8(*q0, v4); |
| 314 |
*p0 = _mm_adds_epi8(*p0, v3); |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
static WEBP_INLINE void Update2Pixels_SSE2(__m128i* const pi, __m128i* const qi, |
| 322 |
const __m128i* const a0_lo, |
| 323 |
const __m128i* const a0_hi) { |
| 324 |
const __m128i a1_lo = _mm_srai_epi16(*a0_lo, 7); |
| 325 |
const __m128i a1_hi = _mm_srai_epi16(*a0_hi, 7); |
| 326 |
const __m128i delta = _mm_packs_epi16(a1_lo, a1_hi); |
| 327 |
const __m128i sign_bit = _mm_set1_epi8((char)0x80); |
| 328 |
*pi = _mm_adds_epi8(*pi, delta); |
| 329 |
*qi = _mm_subs_epi8(*qi, delta); |
| 330 |
FLIP_SIGN_BIT2(*pi, *qi); |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
static WEBP_INLINE void NeedsFilter_SSE2(const __m128i* const p1, |
| 335 |
const __m128i* const p0, |
| 336 |
const __m128i* const q0, |
| 337 |
const __m128i* const q1, |
| 338 |
int thresh, __m128i* const mask) { |
| 339 |
const __m128i m_thresh = _mm_set1_epi8((char)thresh); |
| 340 |
const __m128i t1 = MM_ABS(*p1, *q1); |
| 341 |
const __m128i kFE = _mm_set1_epi8((char)0xFE); |
| 342 |
const __m128i t2 = _mm_and_si128(t1, kFE); |
| 343 |
const __m128i t3 = _mm_srli_epi16(t2, 1); |
| 344 |
|
| 345 |
const __m128i t4 = MM_ABS(*p0, *q0); |
| 346 |
const __m128i t5 = _mm_adds_epu8(t4, t4); |
| 347 |
const __m128i t6 = _mm_adds_epu8(t5, t3); |
| 348 |
|
| 349 |
const __m128i t7 = _mm_subs_epu8(t6, m_thresh); |
| 350 |
*mask = _mm_cmpeq_epi8(t7, _mm_setzero_si128()); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
static WEBP_INLINE void DoFilter2_SSE2(__m128i* const p1, __m128i* const p0, |
| 358 |
__m128i* const q0, __m128i* const q1, |
| 359 |
int thresh) { |
| 360 |
__m128i a, mask; |
| 361 |
const __m128i sign_bit = _mm_set1_epi8((char)0x80); |
| 362 |
|
| 363 |
const __m128i p1s = _mm_xor_si128(*p1, sign_bit); |
| 364 |
const __m128i q1s = _mm_xor_si128(*q1, sign_bit); |
| 365 |
|
| 366 |
NeedsFilter_SSE2(p1, p0, q0, q1, thresh, &mask); |
| 367 |
|
| 368 |
FLIP_SIGN_BIT2(*p0, *q0); |
| 369 |
GetBaseDelta_SSE2(&p1s, p0, q0, &q1s, &a); |
| 370 |
a = _mm_and_si128(a, mask); |
| 371 |
DoSimpleFilter_SSE2(p0, q0, &a); |
| 372 |
FLIP_SIGN_BIT2(*p0, *q0); |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
static WEBP_INLINE void DoFilter4_SSE2(__m128i* const p1, __m128i* const p0, |
| 377 |
__m128i* const q0, __m128i* const q1, |
| 378 |
const __m128i* const mask, |
| 379 |
int hev_thresh) { |
| 380 |
const __m128i zero = _mm_setzero_si128(); |
| 381 |
const __m128i sign_bit = _mm_set1_epi8((char)0x80); |
| 382 |
const __m128i k64 = _mm_set1_epi8(64); |
| 383 |
const __m128i k3 = _mm_set1_epi8(3); |
| 384 |
const __m128i k4 = _mm_set1_epi8(4); |
| 385 |
__m128i not_hev; |
| 386 |
__m128i t1, t2, t3; |
| 387 |
|
| 388 |
|
| 389 |
GetNotHEV_SSE2(p1, p0, q0, q1, hev_thresh, ¬_hev); |
| 390 |
|
| 391 |
|
| 392 |
FLIP_SIGN_BIT4(*p1, *p0, *q0, *q1); |
| 393 |
|
| 394 |
t1 = _mm_subs_epi8(*p1, *q1); |
| 395 |
t1 = _mm_andnot_si128(not_hev, t1); |
| 396 |
t2 = _mm_subs_epi8(*q0, *p0); |
| 397 |
t1 = _mm_adds_epi8(t1, t2); |
| 398 |
t1 = _mm_adds_epi8(t1, t2); |
| 399 |
t1 = _mm_adds_epi8(t1, t2); |
| 400 |
t1 = _mm_and_si128(t1, *mask); |
| 401 |
|
| 402 |
t2 = _mm_adds_epi8(t1, k3); |
| 403 |
t3 = _mm_adds_epi8(t1, k4); |
| 404 |
SignedShift8b_SSE2(&t2); |
| 405 |
SignedShift8b_SSE2(&t3); |
| 406 |
*p0 = _mm_adds_epi8(*p0, t2); |
| 407 |
*q0 = _mm_subs_epi8(*q0, t3); |
| 408 |
FLIP_SIGN_BIT2(*p0, *q0); |
| 409 |
|
| 410 |
|
| 411 |
t2 = _mm_add_epi8(t3, sign_bit); |
| 412 |
t3 = _mm_avg_epu8(t2, zero); |
| 413 |
t3 = _mm_sub_epi8(t3, k64); |
| 414 |
|
| 415 |
t3 = _mm_and_si128(not_hev, t3); |
| 416 |
*q1 = _mm_subs_epi8(*q1, t3); |
| 417 |
*p1 = _mm_adds_epi8(*p1, t3); |
| 418 |
FLIP_SIGN_BIT2(*p1, *q1); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
static WEBP_INLINE void DoFilter6_SSE2(__m128i* const p2, __m128i* const p1, |
| 423 |
__m128i* const p0, __m128i* const q0, |
| 424 |
__m128i* const q1, __m128i* const q2, |
| 425 |
const __m128i* const mask, |
| 426 |
int hev_thresh) { |
| 427 |
const __m128i zero = _mm_setzero_si128(); |
| 428 |
const __m128i sign_bit = _mm_set1_epi8((char)0x80); |
| 429 |
__m128i a, not_hev; |
| 430 |
|
| 431 |
|
| 432 |
GetNotHEV_SSE2(p1, p0, q0, q1, hev_thresh, ¬_hev); |
| 433 |
|
| 434 |
FLIP_SIGN_BIT4(*p1, *p0, *q0, *q1); |
| 435 |
FLIP_SIGN_BIT2(*p2, *q2); |
| 436 |
GetBaseDelta_SSE2(p1, p0, q0, q1, &a); |
| 437 |
|
| 438 |
{ |
| 439 |
const __m128i m = _mm_andnot_si128(not_hev, *mask); |
| 440 |
const __m128i f = _mm_and_si128(a, m); |
| 441 |
DoSimpleFilter_SSE2(p0, q0, &f); |
| 442 |
} |
| 443 |
|
| 444 |
{ |
| 445 |
const __m128i k9 = _mm_set1_epi16(0x0900); |
| 446 |
const __m128i k63 = _mm_set1_epi16(63); |
| 447 |
|
| 448 |
const __m128i m = _mm_and_si128(not_hev, *mask); |
| 449 |
const __m128i f = _mm_and_si128(a, m); |
| 450 |
|
| 451 |
const __m128i f_lo = _mm_unpacklo_epi8(zero, f); |
| 452 |
const __m128i f_hi = _mm_unpackhi_epi8(zero, f); |
| 453 |
|
| 454 |
const __m128i f9_lo = _mm_mulhi_epi16(f_lo, k9); |
| 455 |
const __m128i f9_hi = _mm_mulhi_epi16(f_hi, k9); |
| 456 |
|
| 457 |
const __m128i a2_lo = _mm_add_epi16(f9_lo, k63); |
| 458 |
const __m128i a2_hi = _mm_add_epi16(f9_hi, k63); |
| 459 |
|
| 460 |
const __m128i a1_lo = _mm_add_epi16(a2_lo, f9_lo); |
| 461 |
const __m128i a1_hi = _mm_add_epi16(a2_hi, f9_hi); |
| 462 |
|
| 463 |
const __m128i a0_lo = _mm_add_epi16(a1_lo, f9_lo); |
| 464 |
const __m128i a0_hi = _mm_add_epi16(a1_hi, f9_hi); |
| 465 |
|
| 466 |
Update2Pixels_SSE2(p2, q2, &a2_lo, &a2_hi); |
| 467 |
Update2Pixels_SSE2(p1, q1, &a1_lo, &a1_hi); |
| 468 |
Update2Pixels_SSE2(p0, q0, &a0_lo, &a0_hi); |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
static WEBP_INLINE void Load8x4_SSE2(const uint8_t* const b, int stride, |
| 474 |
__m128i* const p, __m128i* const q) { |
| 475 |
|
| 476 |
|
| 477 |
const __m128i A0 = _mm_set_epi32( |
| 478 |
WebPMemToInt32(&b[6 * stride]), WebPMemToInt32(&b[2 * stride]), |
| 479 |
WebPMemToInt32(&b[4 * stride]), WebPMemToInt32(&b[0 * stride])); |
| 480 |
const __m128i A1 = _mm_set_epi32( |
| 481 |
WebPMemToInt32(&b[7 * stride]), WebPMemToInt32(&b[3 * stride]), |
| 482 |
WebPMemToInt32(&b[5 * stride]), WebPMemToInt32(&b[1 * stride])); |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
const __m128i B0 = _mm_unpacklo_epi8(A0, A1); |
| 487 |
const __m128i B1 = _mm_unpackhi_epi8(A0, A1); |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
const __m128i C0 = _mm_unpacklo_epi16(B0, B1); |
| 492 |
const __m128i C1 = _mm_unpackhi_epi16(B0, B1); |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
*p = _mm_unpacklo_epi32(C0, C1); |
| 497 |
*q = _mm_unpackhi_epi32(C0, C1); |
| 498 |
} |
| 499 |
|
| 500 |
static WEBP_INLINE void Load16x4_SSE2(const uint8_t* const r0, |
| 501 |
const uint8_t* const r8, |
| 502 |
int stride, |
| 503 |
__m128i* const p1, __m128i* const p0, |
| 504 |
__m128i* const q0, __m128i* const q1) { |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
Load8x4_SSE2(r0, stride, p1, q0); |
| 521 |
Load8x4_SSE2(r8, stride, p0, q1); |
| 522 |
|
| 523 |
{ |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
const __m128i t1 = *p1; |
| 529 |
const __m128i t2 = *q0; |
| 530 |
*p1 = _mm_unpacklo_epi64(t1, *p0); |
| 531 |
*p0 = _mm_unpackhi_epi64(t1, *p0); |
| 532 |
*q0 = _mm_unpacklo_epi64(t2, *q1); |
| 533 |
*q1 = _mm_unpackhi_epi64(t2, *q1); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
static WEBP_INLINE void Store4x4_SSE2(__m128i* const x, |
| 538 |
uint8_t* dst, int stride) { |
| 539 |
int i; |
| 540 |
for (i = 0; i < 4; ++i, dst += stride) { |
| 541 |
WebPInt32ToMem(dst, _mm_cvtsi128_si32(*x)); |
| 542 |
*x = _mm_srli_si128(*x, 4); |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
static WEBP_INLINE void Store16x4_SSE2(const __m128i* const p1, |
| 548 |
const __m128i* const p0, |
| 549 |
const __m128i* const q0, |
| 550 |
const __m128i* const q1, |
| 551 |
uint8_t* r0, uint8_t* r8, |
| 552 |
int stride) { |
| 553 |
__m128i t1, p1_s, p0_s, q0_s, q1_s; |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
t1 = *p0; |
| 558 |
p0_s = _mm_unpacklo_epi8(*p1, t1); |
| 559 |
p1_s = _mm_unpackhi_epi8(*p1, t1); |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
t1 = *q0; |
| 564 |
q0_s = _mm_unpacklo_epi8(t1, *q1); |
| 565 |
q1_s = _mm_unpackhi_epi8(t1, *q1); |
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
t1 = p0_s; |
| 570 |
p0_s = _mm_unpacklo_epi16(t1, q0_s); |
| 571 |
q0_s = _mm_unpackhi_epi16(t1, q0_s); |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
t1 = p1_s; |
| 576 |
p1_s = _mm_unpacklo_epi16(t1, q1_s); |
| 577 |
q1_s = _mm_unpackhi_epi16(t1, q1_s); |
| 578 |
|
| 579 |
Store4x4_SSE2(&p0_s, r0, stride); |
| 580 |
r0 += 4 * stride; |
| 581 |
Store4x4_SSE2(&q0_s, r0, stride); |
| 582 |
|
| 583 |
Store4x4_SSE2(&p1_s, r8, stride); |
| 584 |
r8 += 4 * stride; |
| 585 |
Store4x4_SSE2(&q1_s, r8, stride); |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
static void SimpleVFilter16_SSE2(uint8_t* p, int stride, int thresh) { |
| 592 |
|
| 593 |
__m128i p1 = _mm_loadu_si128((__m128i*)&p[-2 * stride]); |
| 594 |
__m128i p0 = _mm_loadu_si128((__m128i*)&p[-stride]); |
| 595 |
__m128i q0 = _mm_loadu_si128((__m128i*)&p[0]); |
| 596 |
__m128i q1 = _mm_loadu_si128((__m128i*)&p[stride]); |
| 597 |
|
| 598 |
DoFilter2_SSE2(&p1, &p0, &q0, &q1, thresh); |
| 599 |
|
| 600 |
|
| 601 |
_mm_storeu_si128((__m128i*)&p[-stride], p0); |
| 602 |
_mm_storeu_si128((__m128i*)&p[0], q0); |
| 603 |
} |
| 604 |
|
| 605 |
static void SimpleHFilter16_SSE2(uint8_t* p, int stride, int thresh) { |
| 606 |
__m128i p1, p0, q0, q1; |
| 607 |
|
| 608 |
p -= 2; |
| 609 |
|
| 610 |
Load16x4_SSE2(p, p + 8 * stride, stride, &p1, &p0, &q0, &q1); |
| 611 |
DoFilter2_SSE2(&p1, &p0, &q0, &q1, thresh); |
| 612 |
Store16x4_SSE2(&p1, &p0, &q0, &q1, p, p + 8 * stride, stride); |
| 613 |
} |
| 614 |
|
| 615 |
static void SimpleVFilter16i_SSE2(uint8_t* p, int stride, int thresh) { |
| 616 |
int k; |
| 617 |
for (k = 3; k > 0; --k) { |
| 618 |
p += 4 * stride; |
| 619 |
SimpleVFilter16_SSE2(p, stride, thresh); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
static void SimpleHFilter16i_SSE2(uint8_t* p, int stride, int thresh) { |
| 624 |
int k; |
| 625 |
for (k = 3; k > 0; --k) { |
| 626 |
p += 4; |
| 627 |
SimpleHFilter16_SSE2(p, stride, thresh); |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
#define MAX_DIFF1(p3, p2, p1, p0, m) do { \ |
| 635 |
(m) = MM_ABS(p1, p0); \ |
| 636 |
(m) = _mm_max_epu8(m, MM_ABS(p3, p2)); \ |
| 637 |
(m) = _mm_max_epu8(m, MM_ABS(p2, p1)); \ |
| 638 |
} while (0) |
| 639 |
|
| 640 |
#define MAX_DIFF2(p3, p2, p1, p0, m) do { \ |
| 641 |
(m) = _mm_max_epu8(m, MM_ABS(p1, p0)); \ |
| 642 |
(m) = _mm_max_epu8(m, MM_ABS(p3, p2)); \ |
| 643 |
(m) = _mm_max_epu8(m, MM_ABS(p2, p1)); \ |
| 644 |
} while (0) |
| 645 |
|
| 646 |
#define LOAD_H_EDGES4(p, stride, e1, e2, e3, e4) do { \ |
| 647 |
(e1) = _mm_loadu_si128((__m128i*)&(p)[0 * (stride)]); \ |
| 648 |
(e2) = _mm_loadu_si128((__m128i*)&(p)[1 * (stride)]); \ |
| 649 |
(e3) = _mm_loadu_si128((__m128i*)&(p)[2 * (stride)]); \ |
| 650 |
(e4) = _mm_loadu_si128((__m128i*)&(p)[3 * (stride)]); \ |
| 651 |
} while (0) |
| 652 |
|
| 653 |
#define LOADUV_H_EDGE(p, u, v, stride) do { \ |
| 654 |
const __m128i U = _mm_loadl_epi64((__m128i*)&(u)[(stride)]); \ |
| 655 |
const __m128i V = _mm_loadl_epi64((__m128i*)&(v)[(stride)]); \ |
| 656 |
(p) = _mm_unpacklo_epi64(U, V); \ |
| 657 |
} while (0) |
| 658 |
|
| 659 |
#define LOADUV_H_EDGES4(u, v, stride, e1, e2, e3, e4) do { \ |
| 660 |
LOADUV_H_EDGE(e1, u, v, 0 * (stride)); \ |
| 661 |
LOADUV_H_EDGE(e2, u, v, 1 * (stride)); \ |
| 662 |
LOADUV_H_EDGE(e3, u, v, 2 * (stride)); \ |
| 663 |
LOADUV_H_EDGE(e4, u, v, 3 * (stride)); \ |
| 664 |
} while (0) |
| 665 |
|
| 666 |
#define STOREUV(p, u, v, stride) do { \ |
| 667 |
_mm_storel_epi64((__m128i*)&(u)[(stride)], p); \ |
| 668 |
(p) = _mm_srli_si128(p, 8); \ |
| 669 |
_mm_storel_epi64((__m128i*)&(v)[(stride)], p); \ |
| 670 |
} while (0) |
| 671 |
|
| 672 |
static WEBP_INLINE void ComplexMask_SSE2(const __m128i* const p1, |
| 673 |
const __m128i* const p0, |
| 674 |
const __m128i* const q0, |
| 675 |
const __m128i* const q1, |
| 676 |
int thresh, int ithresh, |
| 677 |
__m128i* const mask) { |
| 678 |
const __m128i it = _mm_set1_epi8(ithresh); |
| 679 |
const __m128i diff = _mm_subs_epu8(*mask, it); |
| 680 |
const __m128i thresh_mask = _mm_cmpeq_epi8(diff, _mm_setzero_si128()); |
| 681 |
__m128i filter_mask; |
| 682 |
NeedsFilter_SSE2(p1, p0, q0, q1, thresh, &filter_mask); |
| 683 |
*mask = _mm_and_si128(thresh_mask, filter_mask); |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
static void VFilter16_SSE2(uint8_t* p, int stride, |
| 688 |
int thresh, int ithresh, int hev_thresh) { |
| 689 |
__m128i t1; |
| 690 |
__m128i mask; |
| 691 |
__m128i p2, p1, p0, q0, q1, q2; |
| 692 |
|
| 693 |
|
| 694 |
LOAD_H_EDGES4(p - 4 * stride, stride, t1, p2, p1, p0); |
| 695 |
MAX_DIFF1(t1, p2, p1, p0, mask); |
| 696 |
|
| 697 |
|
| 698 |
LOAD_H_EDGES4(p, stride, q0, q1, q2, t1); |
| 699 |
MAX_DIFF2(t1, q2, q1, q0, mask); |
| 700 |
|
| 701 |
ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); |
| 702 |
DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh); |
| 703 |
|
| 704 |
|
| 705 |
_mm_storeu_si128((__m128i*)&p[-3 * stride], p2); |
| 706 |
_mm_storeu_si128((__m128i*)&p[-2 * stride], p1); |
| 707 |
_mm_storeu_si128((__m128i*)&p[-1 * stride], p0); |
| 708 |
_mm_storeu_si128((__m128i*)&p[+0 * stride], q0); |
| 709 |
_mm_storeu_si128((__m128i*)&p[+1 * stride], q1); |
| 710 |
_mm_storeu_si128((__m128i*)&p[+2 * stride], q2); |
| 711 |
} |
| 712 |
|
| 713 |
static void HFilter16_SSE2(uint8_t* p, int stride, |
| 714 |
int thresh, int ithresh, int hev_thresh) { |
| 715 |
__m128i mask; |
| 716 |
__m128i p3, p2, p1, p0, q0, q1, q2, q3; |
| 717 |
|
| 718 |
uint8_t* const b = p - 4; |
| 719 |
Load16x4_SSE2(b, b + 8 * stride, stride, &p3, &p2, &p1, &p0); |
| 720 |
MAX_DIFF1(p3, p2, p1, p0, mask); |
| 721 |
|
| 722 |
Load16x4_SSE2(p, p + 8 * stride, stride, &q0, &q1, &q2, &q3); |
| 723 |
MAX_DIFF2(q3, q2, q1, q0, mask); |
| 724 |
|
| 725 |
ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); |
| 726 |
DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh); |
| 727 |
|
| 728 |
Store16x4_SSE2(&p3, &p2, &p1, &p0, b, b + 8 * stride, stride); |
| 729 |
Store16x4_SSE2(&q0, &q1, &q2, &q3, p, p + 8 * stride, stride); |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
static void VFilter16i_SSE2(uint8_t* p, int stride, |
| 734 |
int thresh, int ithresh, int hev_thresh) { |
| 735 |
int k; |
| 736 |
__m128i p3, p2, p1, p0; |
| 737 |
|
| 738 |
LOAD_H_EDGES4(p, stride, p3, p2, p1, p0); |
| 739 |
|
| 740 |
for (k = 3; k > 0; --k) { |
| 741 |
__m128i mask, tmp1, tmp2; |
| 742 |
uint8_t* const b = p + 2 * stride; |
| 743 |
p += 4 * stride; |
| 744 |
|
| 745 |
MAX_DIFF1(p3, p2, p1, p0, mask); |
| 746 |
LOAD_H_EDGES4(p, stride, p3, p2, tmp1, tmp2); |
| 747 |
MAX_DIFF2(p3, p2, tmp1, tmp2, mask); |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
ComplexMask_SSE2(&p1, &p0, &p3, &p2, thresh, ithresh, &mask); |
| 752 |
DoFilter4_SSE2(&p1, &p0, &p3, &p2, &mask, hev_thresh); |
| 753 |
|
| 754 |
|
| 755 |
_mm_storeu_si128((__m128i*)&b[0 * stride], p1); |
| 756 |
_mm_storeu_si128((__m128i*)&b[1 * stride], p0); |
| 757 |
_mm_storeu_si128((__m128i*)&b[2 * stride], p3); |
| 758 |
_mm_storeu_si128((__m128i*)&b[3 * stride], p2); |
| 759 |
|
| 760 |
|
| 761 |
p1 = tmp1; |
| 762 |
p0 = tmp2; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
static void HFilter16i_SSE2(uint8_t* p, int stride, |
| 767 |
int thresh, int ithresh, int hev_thresh) { |
| 768 |
int k; |
| 769 |
__m128i p3, p2, p1, p0; |
| 770 |
|
| 771 |
Load16x4_SSE2(p, p + 8 * stride, stride, &p3, &p2, &p1, &p0); |
| 772 |
|
| 773 |
for (k = 3; k > 0; --k) { |
| 774 |
__m128i mask, tmp1, tmp2; |
| 775 |
uint8_t* const b = p + 2; |
| 776 |
|
| 777 |
p += 4; |
| 778 |
|
| 779 |
MAX_DIFF1(p3, p2, p1, p0, mask); |
| 780 |
Load16x4_SSE2(p, p + 8 * stride, stride, &p3, &p2, &tmp1, &tmp2); |
| 781 |
MAX_DIFF2(p3, p2, tmp1, tmp2, mask); |
| 782 |
|
| 783 |
ComplexMask_SSE2(&p1, &p0, &p3, &p2, thresh, ithresh, &mask); |
| 784 |
DoFilter4_SSE2(&p1, &p0, &p3, &p2, &mask, hev_thresh); |
| 785 |
|
| 786 |
Store16x4_SSE2(&p1, &p0, &p3, &p2, b, b + 8 * stride, stride); |
| 787 |
|
| 788 |
|
| 789 |
p1 = tmp1; |
| 790 |
p0 = tmp2; |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
static void VFilter8_SSE2(uint8_t* u, uint8_t* v, int stride, |
| 796 |
int thresh, int ithresh, int hev_thresh) { |
| 797 |
__m128i mask; |
| 798 |
__m128i t1, p2, p1, p0, q0, q1, q2; |
| 799 |
|
| 800 |
|
| 801 |
LOADUV_H_EDGES4(u - 4 * stride, v - 4 * stride, stride, t1, p2, p1, p0); |
| 802 |
MAX_DIFF1(t1, p2, p1, p0, mask); |
| 803 |
|
| 804 |
|
| 805 |
LOADUV_H_EDGES4(u, v, stride, q0, q1, q2, t1); |
| 806 |
MAX_DIFF2(t1, q2, q1, q0, mask); |
| 807 |
|
| 808 |
ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); |
| 809 |
DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh); |
| 810 |
|
| 811 |
|
| 812 |
STOREUV(p2, u, v, -3 * stride); |
| 813 |
STOREUV(p1, u, v, -2 * stride); |
| 814 |
STOREUV(p0, u, v, -1 * stride); |
| 815 |
STOREUV(q0, u, v, 0 * stride); |
| 816 |
STOREUV(q1, u, v, 1 * stride); |
| 817 |
STOREUV(q2, u, v, 2 * stride); |
| 818 |
} |
| 819 |
|
| 820 |
static void HFilter8_SSE2(uint8_t* u, uint8_t* v, int stride, |
| 821 |
int thresh, int ithresh, int hev_thresh) { |
| 822 |
__m128i mask; |
| 823 |
__m128i p3, p2, p1, p0, q0, q1, q2, q3; |
| 824 |
|
| 825 |
uint8_t* const tu = u - 4; |
| 826 |
uint8_t* const tv = v - 4; |
| 827 |
Load16x4_SSE2(tu, tv, stride, &p3, &p2, &p1, &p0); |
| 828 |
MAX_DIFF1(p3, p2, p1, p0, mask); |
| 829 |
|
| 830 |
Load16x4_SSE2(u, v, stride, &q0, &q1, &q2, &q3); |
| 831 |
MAX_DIFF2(q3, q2, q1, q0, mask); |
| 832 |
|
| 833 |
ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); |
| 834 |
DoFilter6_SSE2(&p2, &p1, &p0, &q0, &q1, &q2, &mask, hev_thresh); |
| 835 |
|
| 836 |
Store16x4_SSE2(&p3, &p2, &p1, &p0, tu, tv, stride); |
| 837 |
Store16x4_SSE2(&q0, &q1, &q2, &q3, u, v, stride); |
| 838 |
} |
| 839 |
|
| 840 |
static void VFilter8i_SSE2(uint8_t* u, uint8_t* v, int stride, |
| 841 |
int thresh, int ithresh, int hev_thresh) { |
| 842 |
__m128i mask; |
| 843 |
__m128i t1, t2, p1, p0, q0, q1; |
| 844 |
|
| 845 |
|
| 846 |
LOADUV_H_EDGES4(u, v, stride, t2, t1, p1, p0); |
| 847 |
MAX_DIFF1(t2, t1, p1, p0, mask); |
| 848 |
|
| 849 |
u += 4 * stride; |
| 850 |
v += 4 * stride; |
| 851 |
|
| 852 |
|
| 853 |
LOADUV_H_EDGES4(u, v, stride, q0, q1, t1, t2); |
| 854 |
MAX_DIFF2(t2, t1, q1, q0, mask); |
| 855 |
|
| 856 |
ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); |
| 857 |
DoFilter4_SSE2(&p1, &p0, &q0, &q1, &mask, hev_thresh); |
| 858 |
|
| 859 |
|
| 860 |
STOREUV(p1, u, v, -2 * stride); |
| 861 |
STOREUV(p0, u, v, -1 * stride); |
| 862 |
STOREUV(q0, u, v, 0 * stride); |
| 863 |
STOREUV(q1, u, v, 1 * stride); |
| 864 |
} |
| 865 |
|
| 866 |
static void HFilter8i_SSE2(uint8_t* u, uint8_t* v, int stride, |
| 867 |
int thresh, int ithresh, int hev_thresh) { |
| 868 |
__m128i mask; |
| 869 |
__m128i t1, t2, p1, p0, q0, q1; |
| 870 |
Load16x4_SSE2(u, v, stride, &t2, &t1, &p1, &p0); |
| 871 |
MAX_DIFF1(t2, t1, p1, p0, mask); |
| 872 |
|
| 873 |
u += 4; |
| 874 |
v += 4; |
| 875 |
Load16x4_SSE2(u, v, stride, &q0, &q1, &t1, &t2); |
| 876 |
MAX_DIFF2(t2, t1, q1, q0, mask); |
| 877 |
|
| 878 |
ComplexMask_SSE2(&p1, &p0, &q0, &q1, thresh, ithresh, &mask); |
| 879 |
DoFilter4_SSE2(&p1, &p0, &q0, &q1, &mask, hev_thresh); |
| 880 |
|
| 881 |
u -= 2; |
| 882 |
v -= 2; |
| 883 |
Store16x4_SSE2(&p1, &p0, &q0, &q1, u, v, stride); |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
#define DST(x, y) dst[(x) + (y) * BPS] |
| 890 |
#define AVG3(a, b, c) (((a) + 2 * (b) + (c) + 2) >> 2) |
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
static void VE4_SSE2(uint8_t* dst) { |
| 901 |
const __m128i one = _mm_set1_epi8(1); |
| 902 |
const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS - 1)); |
| 903 |
const __m128i BCDEFGH0 = _mm_srli_si128(ABCDEFGH, 1); |
| 904 |
const __m128i CDEFGH00 = _mm_srli_si128(ABCDEFGH, 2); |
| 905 |
const __m128i a = _mm_avg_epu8(ABCDEFGH, CDEFGH00); |
| 906 |
const __m128i lsb = _mm_and_si128(_mm_xor_si128(ABCDEFGH, CDEFGH00), one); |
| 907 |
const __m128i b = _mm_subs_epu8(a, lsb); |
| 908 |
const __m128i avg = _mm_avg_epu8(b, BCDEFGH0); |
| 909 |
const int vals = _mm_cvtsi128_si32(avg); |
| 910 |
int i; |
| 911 |
for (i = 0; i < 4; ++i) { |
| 912 |
WebPInt32ToMem(dst + i * BPS, vals); |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
static void LD4_SSE2(uint8_t* dst) { |
| 917 |
const __m128i one = _mm_set1_epi8(1); |
| 918 |
const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS)); |
| 919 |
const __m128i BCDEFGH0 = _mm_srli_si128(ABCDEFGH, 1); |
| 920 |
const __m128i CDEFGH00 = _mm_srli_si128(ABCDEFGH, 2); |
| 921 |
const __m128i CDEFGHH0 = _mm_insert_epi16(CDEFGH00, dst[-BPS + 7], 3); |
| 922 |
const __m128i avg1 = _mm_avg_epu8(ABCDEFGH, CDEFGHH0); |
| 923 |
const __m128i lsb = _mm_and_si128(_mm_xor_si128(ABCDEFGH, CDEFGHH0), one); |
| 924 |
const __m128i avg2 = _mm_subs_epu8(avg1, lsb); |
| 925 |
const __m128i abcdefg = _mm_avg_epu8(avg2, BCDEFGH0); |
| 926 |
WebPInt32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32( abcdefg )); |
| 927 |
WebPInt32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 1))); |
| 928 |
WebPInt32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 2))); |
| 929 |
WebPInt32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 3))); |
| 930 |
} |
| 931 |
|
| 932 |
static void VR4_SSE2(uint8_t* dst) { |
| 933 |
const __m128i one = _mm_set1_epi8(1); |
| 934 |
const int I = dst[-1 + 0 * BPS]; |
| 935 |
const int J = dst[-1 + 1 * BPS]; |
| 936 |
const int K = dst[-1 + 2 * BPS]; |
| 937 |
const int X = dst[-1 - BPS]; |
| 938 |
const __m128i XABCD = _mm_loadl_epi64((__m128i*)(dst - BPS - 1)); |
| 939 |
const __m128i ABCD0 = _mm_srli_si128(XABCD, 1); |
| 940 |
const __m128i abcd = _mm_avg_epu8(XABCD, ABCD0); |
| 941 |
const __m128i _XABCD = _mm_slli_si128(XABCD, 1); |
| 942 |
const __m128i IXABCD = _mm_insert_epi16(_XABCD, (short)(I | (X << 8)), 0); |
| 943 |
const __m128i avg1 = _mm_avg_epu8(IXABCD, ABCD0); |
| 944 |
const __m128i lsb = _mm_and_si128(_mm_xor_si128(IXABCD, ABCD0), one); |
| 945 |
const __m128i avg2 = _mm_subs_epu8(avg1, lsb); |
| 946 |
const __m128i efgh = _mm_avg_epu8(avg2, XABCD); |
| 947 |
WebPInt32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32( abcd )); |
| 948 |
WebPInt32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32( efgh )); |
| 949 |
WebPInt32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_slli_si128(abcd, 1))); |
| 950 |
WebPInt32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(_mm_slli_si128(efgh, 1))); |
| 951 |
|
| 952 |
|
| 953 |
DST(0, 2) = AVG3(J, I, X); |
| 954 |
DST(0, 3) = AVG3(K, J, I); |
| 955 |
} |
| 956 |
|
| 957 |
static void VL4_SSE2(uint8_t* dst) { |
| 958 |
const __m128i one = _mm_set1_epi8(1); |
| 959 |
const __m128i ABCDEFGH = _mm_loadl_epi64((__m128i*)(dst - BPS)); |
| 960 |
const __m128i BCDEFGH_ = _mm_srli_si128(ABCDEFGH, 1); |
| 961 |
const __m128i CDEFGH__ = _mm_srli_si128(ABCDEFGH, 2); |
| 962 |
const __m128i avg1 = _mm_avg_epu8(ABCDEFGH, BCDEFGH_); |
| 963 |
const __m128i avg2 = _mm_avg_epu8(CDEFGH__, BCDEFGH_); |
| 964 |
const __m128i avg3 = _mm_avg_epu8(avg1, avg2); |
| 965 |
const __m128i lsb1 = _mm_and_si128(_mm_xor_si128(avg1, avg2), one); |
| 966 |
const __m128i ab = _mm_xor_si128(ABCDEFGH, BCDEFGH_); |
| 967 |
const __m128i bc = _mm_xor_si128(CDEFGH__, BCDEFGH_); |
| 968 |
const __m128i abbc = _mm_or_si128(ab, bc); |
| 969 |
const __m128i lsb2 = _mm_and_si128(abbc, lsb1); |
| 970 |
const __m128i avg4 = _mm_subs_epu8(avg3, lsb2); |
| 971 |
const uint32_t extra_out = |
| 972 |
(uint32_t)_mm_cvtsi128_si32(_mm_srli_si128(avg4, 4)); |
| 973 |
WebPInt32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32( avg1 )); |
| 974 |
WebPInt32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32( avg4 )); |
| 975 |
WebPInt32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(avg1, 1))); |
| 976 |
WebPInt32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(avg4, 1))); |
| 977 |
|
| 978 |
|
| 979 |
DST(3, 2) = (extra_out >> 0) & 0xff; |
| 980 |
DST(3, 3) = (extra_out >> 8) & 0xff; |
| 981 |
} |
| 982 |
|
| 983 |
static void RD4_SSE2(uint8_t* dst) { |
| 984 |
const __m128i one = _mm_set1_epi8(1); |
| 985 |
const __m128i XABCD = _mm_loadl_epi64((__m128i*)(dst - BPS - 1)); |
| 986 |
const __m128i ____XABCD = _mm_slli_si128(XABCD, 4); |
| 987 |
const uint32_t I = dst[-1 + 0 * BPS]; |
| 988 |
const uint32_t J = dst[-1 + 1 * BPS]; |
| 989 |
const uint32_t K = dst[-1 + 2 * BPS]; |
| 990 |
const uint32_t L = dst[-1 + 3 * BPS]; |
| 991 |
const __m128i LKJI_____ = |
| 992 |
_mm_cvtsi32_si128((int)(L | (K << 8) | (J << 16) | (I << 24))); |
| 993 |
const __m128i LKJIXABCD = _mm_or_si128(LKJI_____, ____XABCD); |
| 994 |
const __m128i KJIXABCD_ = _mm_srli_si128(LKJIXABCD, 1); |
| 995 |
const __m128i JIXABCD__ = _mm_srli_si128(LKJIXABCD, 2); |
| 996 |
const __m128i avg1 = _mm_avg_epu8(JIXABCD__, LKJIXABCD); |
| 997 |
const __m128i lsb = _mm_and_si128(_mm_xor_si128(JIXABCD__, LKJIXABCD), one); |
| 998 |
const __m128i avg2 = _mm_subs_epu8(avg1, lsb); |
| 999 |
const __m128i abcdefg = _mm_avg_epu8(avg2, KJIXABCD_); |
| 1000 |
WebPInt32ToMem(dst + 3 * BPS, _mm_cvtsi128_si32( abcdefg )); |
| 1001 |
WebPInt32ToMem(dst + 2 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 1))); |
| 1002 |
WebPInt32ToMem(dst + 1 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 2))); |
| 1003 |
WebPInt32ToMem(dst + 0 * BPS, _mm_cvtsi128_si32(_mm_srli_si128(abcdefg, 3))); |
| 1004 |
} |
| 1005 |
|
| 1006 |
#undef DST |
| 1007 |
#undef AVG3 |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
static WEBP_INLINE void TrueMotion_SSE2(uint8_t* dst, int size) { |
| 1013 |
const uint8_t* top = dst - BPS; |
| 1014 |
const __m128i zero = _mm_setzero_si128(); |
| 1015 |
int y; |
| 1016 |
if (size == 4) { |
| 1017 |
const __m128i top_values = _mm_cvtsi32_si128(WebPMemToInt32(top)); |
| 1018 |
const __m128i top_base = _mm_unpacklo_epi8(top_values, zero); |
| 1019 |
for (y = 0; y < 4; ++y, dst += BPS) { |
| 1020 |
const int val = dst[-1] - top[-1]; |
| 1021 |
const __m128i base = _mm_set1_epi16(val); |
| 1022 |
const __m128i out = _mm_packus_epi16(_mm_add_epi16(base, top_base), zero); |
| 1023 |
WebPInt32ToMem(dst, _mm_cvtsi128_si32(out)); |
| 1024 |
} |
| 1025 |
} else if (size == 8) { |
| 1026 |
const __m128i top_values = _mm_loadl_epi64((const __m128i*)top); |
| 1027 |
const __m128i top_base = _mm_unpacklo_epi8(top_values, zero); |
| 1028 |
for (y = 0; y < 8; ++y, dst += BPS) { |
| 1029 |
const int val = dst[-1] - top[-1]; |
| 1030 |
const __m128i base = _mm_set1_epi16(val); |
| 1031 |
const __m128i out = _mm_packus_epi16(_mm_add_epi16(base, top_base), zero); |
| 1032 |
_mm_storel_epi64((__m128i*)dst, out); |
| 1033 |
} |
| 1034 |
} else { |
| 1035 |
const __m128i top_values = _mm_loadu_si128((const __m128i*)top); |
| 1036 |
const __m128i top_base_0 = _mm_unpacklo_epi8(top_values, zero); |
| 1037 |
const __m128i top_base_1 = _mm_unpackhi_epi8(top_values, zero); |
| 1038 |
for (y = 0; y < 16; ++y, dst += BPS) { |
| 1039 |
const int val = dst[-1] - top[-1]; |
| 1040 |
const __m128i base = _mm_set1_epi16(val); |
| 1041 |
const __m128i out_0 = _mm_add_epi16(base, top_base_0); |
| 1042 |
const __m128i out_1 = _mm_add_epi16(base, top_base_1); |
| 1043 |
const __m128i out = _mm_packus_epi16(out_0, out_1); |
| 1044 |
_mm_storeu_si128((__m128i*)dst, out); |
| 1045 |
} |
| 1046 |
} |
| 1047 |
} |
| 1048 |
|
| 1049 |
static void TM4_SSE2(uint8_t* dst) { TrueMotion_SSE2(dst, 4); } |
| 1050 |
static void TM8uv_SSE2(uint8_t* dst) { TrueMotion_SSE2(dst, 8); } |
| 1051 |
static void TM16_SSE2(uint8_t* dst) { TrueMotion_SSE2(dst, 16); } |
| 1052 |
|
| 1053 |
static void VE16_SSE2(uint8_t* dst) { |
| 1054 |
const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS)); |
| 1055 |
int j; |
| 1056 |
for (j = 0; j < 16; ++j) { |
| 1057 |
_mm_storeu_si128((__m128i*)(dst + j * BPS), top); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
static void HE16_SSE2(uint8_t* dst) { |
| 1062 |
int j; |
| 1063 |
for (j = 16; j > 0; --j) { |
| 1064 |
const __m128i values = _mm_set1_epi8((char)dst[-1]); |
| 1065 |
_mm_storeu_si128((__m128i*)dst, values); |
| 1066 |
dst += BPS; |
| 1067 |
} |
| 1068 |
} |
| 1069 |
|
| 1070 |
static WEBP_INLINE void Put16_SSE2(uint8_t v, uint8_t* dst) { |
| 1071 |
int j; |
| 1072 |
const __m128i values = _mm_set1_epi8((char)v); |
| 1073 |
for (j = 0; j < 16; ++j) { |
| 1074 |
_mm_storeu_si128((__m128i*)(dst + j * BPS), values); |
| 1075 |
} |
| 1076 |
} |
| 1077 |
|
| 1078 |
static void DC16_SSE2(uint8_t* dst) { |
| 1079 |
const __m128i zero = _mm_setzero_si128(); |
| 1080 |
const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS)); |
| 1081 |
const __m128i sad8x2 = _mm_sad_epu8(top, zero); |
| 1082 |
|
| 1083 |
const __m128i sum = _mm_add_epi16(sad8x2, _mm_shuffle_epi32(sad8x2, 2)); |
| 1084 |
int left = 0; |
| 1085 |
int j; |
| 1086 |
for (j = 0; j < 16; ++j) { |
| 1087 |
left += dst[-1 + j * BPS]; |
| 1088 |
} |
| 1089 |
{ |
| 1090 |
const int DC = _mm_cvtsi128_si32(sum) + left + 16; |
| 1091 |
Put16_SSE2(DC >> 5, dst); |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
static void DC16NoTop_SSE2(uint8_t* dst) { |
| 1096 |
int DC = 8; |
| 1097 |
int j; |
| 1098 |
for (j = 0; j < 16; ++j) { |
| 1099 |
DC += dst[-1 + j * BPS]; |
| 1100 |
} |
| 1101 |
Put16_SSE2(DC >> 4, dst); |
| 1102 |
} |
| 1103 |
|
| 1104 |
static void DC16NoLeft_SSE2(uint8_t* dst) { |
| 1105 |
const __m128i zero = _mm_setzero_si128(); |
| 1106 |
const __m128i top = _mm_loadu_si128((const __m128i*)(dst - BPS)); |
| 1107 |
const __m128i sad8x2 = _mm_sad_epu8(top, zero); |
| 1108 |
|
| 1109 |
const __m128i sum = _mm_add_epi16(sad8x2, _mm_shuffle_epi32(sad8x2, 2)); |
| 1110 |
const int DC = _mm_cvtsi128_si32(sum) + 8; |
| 1111 |
Put16_SSE2(DC >> 4, dst); |
| 1112 |
} |
| 1113 |
|
| 1114 |
static void DC16NoTopLeft_SSE2(uint8_t* dst) { |
| 1115 |
Put16_SSE2(0x80, dst); |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
static void VE8uv_SSE2(uint8_t* dst) { |
| 1122 |
int j; |
| 1123 |
const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS)); |
| 1124 |
for (j = 0; j < 8; ++j) { |
| 1125 |
_mm_storel_epi64((__m128i*)(dst + j * BPS), top); |
| 1126 |
} |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
static WEBP_INLINE void Put8x8uv_SSE2(uint8_t v, uint8_t* dst) { |
| 1131 |
int j; |
| 1132 |
const __m128i values = _mm_set1_epi8((char)v); |
| 1133 |
for (j = 0; j < 8; ++j) { |
| 1134 |
_mm_storel_epi64((__m128i*)(dst + j * BPS), values); |
| 1135 |
} |
| 1136 |
} |
| 1137 |
|
| 1138 |
static void DC8uv_SSE2(uint8_t* dst) { |
| 1139 |
const __m128i zero = _mm_setzero_si128(); |
| 1140 |
const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS)); |
| 1141 |
const __m128i sum = _mm_sad_epu8(top, zero); |
| 1142 |
int left = 0; |
| 1143 |
int j; |
| 1144 |
for (j = 0; j < 8; ++j) { |
| 1145 |
left += dst[-1 + j * BPS]; |
| 1146 |
} |
| 1147 |
{ |
| 1148 |
const int DC = _mm_cvtsi128_si32(sum) + left + 8; |
| 1149 |
Put8x8uv_SSE2(DC >> 4, dst); |
| 1150 |
} |
| 1151 |
} |
| 1152 |
|
| 1153 |
static void DC8uvNoLeft_SSE2(uint8_t* dst) { |
| 1154 |
const __m128i zero = _mm_setzero_si128(); |
| 1155 |
const __m128i top = _mm_loadl_epi64((const __m128i*)(dst - BPS)); |
| 1156 |
const __m128i sum = _mm_sad_epu8(top, zero); |
| 1157 |
const int DC = _mm_cvtsi128_si32(sum) + 4; |
| 1158 |
Put8x8uv_SSE2(DC >> 3, dst); |
| 1159 |
} |
| 1160 |
|
| 1161 |
static void DC8uvNoTop_SSE2(uint8_t* dst) { |
| 1162 |
int dc0 = 4; |
| 1163 |
int i; |
| 1164 |
for (i = 0; i < 8; ++i) { |
| 1165 |
dc0 += dst[-1 + i * BPS]; |
| 1166 |
} |
| 1167 |
Put8x8uv_SSE2(dc0 >> 3, dst); |
| 1168 |
} |
| 1169 |
|
| 1170 |
static void DC8uvNoTopLeft_SSE2(uint8_t* dst) { |
| 1171 |
Put8x8uv_SSE2(0x80, dst); |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
extern void VP8DspInitSSE2(void); |
| 1178 |
|
| 1179 |
WEBP_TSAN_IGNORE_FUNCTION void VP8DspInitSSE2(void) { |
| 1180 |
VP8Transform = Transform_SSE2; |
| 1181 |
#if (USE_TRANSFORM_AC3 == 1) |
| 1182 |
VP8TransformAC3 = TransformAC3_SSE2; |
| 1183 |
#endif |
| 1184 |
|
| 1185 |
VP8VFilter16 = VFilter16_SSE2; |
| 1186 |
VP8HFilter16 = HFilter16_SSE2; |
| 1187 |
VP8VFilter8 = VFilter8_SSE2; |
| 1188 |
VP8HFilter8 = HFilter8_SSE2; |
| 1189 |
VP8VFilter16i = VFilter16i_SSE2; |
| 1190 |
VP8HFilter16i = HFilter16i_SSE2; |
| 1191 |
VP8VFilter8i = VFilter8i_SSE2; |
| 1192 |
VP8HFilter8i = HFilter8i_SSE2; |
| 1193 |
|
| 1194 |
VP8SimpleVFilter16 = SimpleVFilter16_SSE2; |
| 1195 |
VP8SimpleHFilter16 = SimpleHFilter16_SSE2; |
| 1196 |
VP8SimpleVFilter16i = SimpleVFilter16i_SSE2; |
| 1197 |
VP8SimpleHFilter16i = SimpleHFilter16i_SSE2; |
| 1198 |
|
| 1199 |
VP8PredLuma4[1] = TM4_SSE2; |
| 1200 |
VP8PredLuma4[2] = VE4_SSE2; |
| 1201 |
VP8PredLuma4[4] = RD4_SSE2; |
| 1202 |
VP8PredLuma4[5] = VR4_SSE2; |
| 1203 |
VP8PredLuma4[6] = LD4_SSE2; |
| 1204 |
VP8PredLuma4[7] = VL4_SSE2; |
| 1205 |
|
| 1206 |
VP8PredLuma16[0] = DC16_SSE2; |
| 1207 |
VP8PredLuma16[1] = TM16_SSE2; |
| 1208 |
VP8PredLuma16[2] = VE16_SSE2; |
| 1209 |
VP8PredLuma16[3] = HE16_SSE2; |
| 1210 |
VP8PredLuma16[4] = DC16NoTop_SSE2; |
| 1211 |
VP8PredLuma16[5] = DC16NoLeft_SSE2; |
| 1212 |
VP8PredLuma16[6] = DC16NoTopLeft_SSE2; |
| 1213 |
|
| 1214 |
VP8PredChroma8[0] = DC8uv_SSE2; |
| 1215 |
VP8PredChroma8[1] = TM8uv_SSE2; |
| 1216 |
VP8PredChroma8[2] = VE8uv_SSE2; |
| 1217 |
VP8PredChroma8[4] = DC8uvNoTop_SSE2; |
| 1218 |
VP8PredChroma8[5] = DC8uvNoLeft_SSE2; |
| 1219 |
VP8PredChroma8[6] = DC8uvNoTopLeft_SSE2; |
| 1220 |
} |
| 1221 |
|
| 1222 |
#else |
| 1223 |
|
| 1224 |
WEBP_DSP_INIT_STUB(VP8DspInitSSE2) |
| 1225 |
|
| 1226 |
#endif |