Coverage Report

Created: 2025-12-31 07:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwebp/src/dsp/lossless_sse2.c
Line
Count
Source
1
// Copyright 2014 Google Inc. All Rights Reserved.
2
//
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
5
// tree. An additional intellectual property rights grant can be found
6
// in the file PATENTS. All contributing project authors may
7
// be found in the AUTHORS file in the root of the source tree.
8
// -----------------------------------------------------------------------------
9
//
10
// SSE2 variant of methods for lossless decoder
11
//
12
// Author: Skal (pascal.massimino@gmail.com)
13
14
#include "src/dsp/dsp.h"
15
16
#if defined(WEBP_USE_SSE2)
17
18
#include <emmintrin.h>
19
#include <string.h>
20
21
#include "src/dsp/common_sse2.h"
22
#include "src/dsp/cpu.h"
23
#include "src/dsp/lossless.h"
24
#include "src/dsp/lossless_common.h"
25
#include "src/webp/format_constants.h"
26
#include "src/webp/types.h"
27
28
//------------------------------------------------------------------------------
29
// Predictor Transform
30
31
static WEBP_INLINE uint32_t ClampedAddSubtractFull_SSE2(uint32_t c0,
32
                                                        uint32_t c1,
33
0
                                                        uint32_t c2) {
34
0
  const __m128i zero = _mm_setzero_si128();
35
0
  const __m128i C0 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)c0), zero);
36
0
  const __m128i C1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)c1), zero);
37
0
  const __m128i C2 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)c2), zero);
38
0
  const __m128i V1 = _mm_add_epi16(C0, C1);
39
0
  const __m128i V2 = _mm_sub_epi16(V1, C2);
40
0
  const __m128i b = _mm_packus_epi16(V2, V2);
41
0
  return (uint32_t)_mm_cvtsi128_si32(b);
42
0
}
43
44
static WEBP_INLINE uint32_t ClampedAddSubtractHalf_SSE2(uint32_t c0,
45
                                                        uint32_t c1,
46
41.8M
                                                        uint32_t c2) {
47
41.8M
  const __m128i zero = _mm_setzero_si128();
48
41.8M
  const __m128i C0 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)c0), zero);
49
41.8M
  const __m128i C1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)c1), zero);
50
41.8M
  const __m128i B0 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)c2), zero);
51
41.8M
  const __m128i avg = _mm_add_epi16(C1, C0);
52
41.8M
  const __m128i A0 = _mm_srli_epi16(avg, 1);
53
41.8M
  const __m128i A1 = _mm_sub_epi16(A0, B0);
54
41.8M
  const __m128i BgtA = _mm_cmpgt_epi16(B0, A0);
55
41.8M
  const __m128i A2 = _mm_sub_epi16(A1, BgtA);
56
41.8M
  const __m128i A3 = _mm_srai_epi16(A2, 1);
57
41.8M
  const __m128i A4 = _mm_add_epi16(A0, A3);
58
41.8M
  const __m128i A5 = _mm_packus_epi16(A4, A4);
59
41.8M
  return (uint32_t)_mm_cvtsi128_si32(A5);
60
41.8M
}
61
62
0
static WEBP_INLINE uint32_t Select_SSE2(uint32_t a, uint32_t b, uint32_t c) {
63
0
  int pa_minus_pb;
64
0
  const __m128i zero = _mm_setzero_si128();
65
0
  const __m128i A0 = _mm_cvtsi32_si128((int)a);
66
0
  const __m128i B0 = _mm_cvtsi32_si128((int)b);
67
0
  const __m128i C0 = _mm_cvtsi32_si128((int)c);
68
0
  const __m128i AC0 = _mm_subs_epu8(A0, C0);
69
0
  const __m128i CA0 = _mm_subs_epu8(C0, A0);
70
0
  const __m128i BC0 = _mm_subs_epu8(B0, C0);
71
0
  const __m128i CB0 = _mm_subs_epu8(C0, B0);
72
0
  const __m128i AC = _mm_or_si128(AC0, CA0);
73
0
  const __m128i BC = _mm_or_si128(BC0, CB0);
74
0
  const __m128i pa = _mm_unpacklo_epi8(AC, zero);  // |a - c|
75
0
  const __m128i pb = _mm_unpacklo_epi8(BC, zero);  // |b - c|
76
0
  const __m128i diff = _mm_sub_epi16(pb, pa);
77
0
  {
78
0
    int16_t out[8];
79
0
    _mm_storeu_si128((__m128i*)out, diff);
80
0
    pa_minus_pb = out[0] + out[1] + out[2] + out[3];
81
0
  }
82
0
  return (pa_minus_pb <= 0) ? a : b;
83
0
}
84
85
static WEBP_INLINE void Average2_m128i(const __m128i* const a0,
86
                                       const __m128i* const a1,
87
231M
                                       __m128i* const avg) {
88
  // (a + b) >> 1 = ((a + b + 1) >> 1) - ((a ^ b) & 1)
89
231M
  const __m128i ones = _mm_set1_epi8(1);
90
231M
  const __m128i avg1 = _mm_avg_epu8(*a0, *a1);
91
231M
  const __m128i one = _mm_and_si128(_mm_xor_si128(*a0, *a1), ones);
92
231M
  *avg = _mm_sub_epi8(avg1, one);
93
231M
}
94
95
static WEBP_INLINE void Average2_uint32_SSE2(const uint32_t a0,
96
                                             const uint32_t a1,
97
27.7M
                                             __m128i* const avg) {
98
  // (a + b) >> 1 = ((a + b + 1) >> 1) - ((a ^ b) & 1)
99
27.7M
  const __m128i ones = _mm_set1_epi8(1);
100
27.7M
  const __m128i A0 = _mm_cvtsi32_si128((int)a0);
101
27.7M
  const __m128i A1 = _mm_cvtsi32_si128((int)a1);
102
27.7M
  const __m128i avg1 = _mm_avg_epu8(A0, A1);
103
27.7M
  const __m128i one = _mm_and_si128(_mm_xor_si128(A0, A1), ones);
104
27.7M
  *avg = _mm_sub_epi8(avg1, one);
105
27.7M
}
106
107
15.6M
static WEBP_INLINE __m128i Average2_uint32_16_SSE2(uint32_t a0, uint32_t a1) {
108
15.6M
  const __m128i zero = _mm_setzero_si128();
109
15.6M
  const __m128i A0 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)a0), zero);
110
15.6M
  const __m128i A1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)a1), zero);
111
15.6M
  const __m128i sum = _mm_add_epi16(A1, A0);
112
15.6M
  return _mm_srli_epi16(sum, 1);
113
15.6M
}
114
115
27.7M
static WEBP_INLINE uint32_t Average2_SSE2(uint32_t a0, uint32_t a1) {
116
27.7M
  __m128i output;
117
27.7M
  Average2_uint32_SSE2(a0, a1, &output);
118
27.7M
  return (uint32_t)_mm_cvtsi128_si32(output);
119
27.7M
}
120
121
static WEBP_INLINE uint32_t Average3_SSE2(uint32_t a0, uint32_t a1,
122
15.6M
                                          uint32_t a2) {
123
15.6M
  const __m128i zero = _mm_setzero_si128();
124
15.6M
  const __m128i avg1 = Average2_uint32_16_SSE2(a0, a2);
125
15.6M
  const __m128i A1 = _mm_unpacklo_epi8(_mm_cvtsi32_si128((int)a1), zero);
126
15.6M
  const __m128i sum = _mm_add_epi16(avg1, A1);
127
15.6M
  const __m128i avg2 = _mm_srli_epi16(sum, 1);
128
15.6M
  const __m128i A2 = _mm_packus_epi16(avg2, avg2);
129
15.6M
  return (uint32_t)_mm_cvtsi128_si32(A2);
130
15.6M
}
131
132
static WEBP_INLINE uint32_t Average4_SSE2(uint32_t a0, uint32_t a1, uint32_t a2,
133
0
                                          uint32_t a3) {
134
0
  const __m128i avg1 = Average2_uint32_16_SSE2(a0, a1);
135
0
  const __m128i avg2 = Average2_uint32_16_SSE2(a2, a3);
136
0
  const __m128i sum = _mm_add_epi16(avg2, avg1);
137
0
  const __m128i avg3 = _mm_srli_epi16(sum, 1);
138
0
  const __m128i A0 = _mm_packus_epi16(avg3, avg3);
139
0
  return (uint32_t)_mm_cvtsi128_si32(A0);
140
0
}
141
142
static uint32_t Predictor5_SSE2(const uint32_t* const left,
143
15.6M
                                const uint32_t* const top) {
144
15.6M
  const uint32_t pred = Average3_SSE2(*left, top[0], top[1]);
145
15.6M
  return pred;
146
15.6M
}
147
static uint32_t Predictor6_SSE2(const uint32_t* const left,
148
24.6M
                                const uint32_t* const top) {
149
24.6M
  const uint32_t pred = Average2_SSE2(*left, top[-1]);
150
24.6M
  return pred;
151
24.6M
}
152
static uint32_t Predictor7_SSE2(const uint32_t* const left,
153
3.14M
                                const uint32_t* const top) {
154
3.14M
  const uint32_t pred = Average2_SSE2(*left, top[0]);
155
3.14M
  return pred;
156
3.14M
}
157
static uint32_t Predictor8_SSE2(const uint32_t* const left,
158
0
                                const uint32_t* const top) {
159
0
  const uint32_t pred = Average2_SSE2(top[-1], top[0]);
160
0
  (void)left;
161
0
  return pred;
162
0
}
163
static uint32_t Predictor9_SSE2(const uint32_t* const left,
164
0
                                const uint32_t* const top) {
165
0
  const uint32_t pred = Average2_SSE2(top[0], top[1]);
166
0
  (void)left;
167
0
  return pred;
168
0
}
169
static uint32_t Predictor10_SSE2(const uint32_t* const left,
170
0
                                 const uint32_t* const top) {
171
0
  const uint32_t pred = Average4_SSE2(*left, top[-1], top[0], top[1]);
172
0
  return pred;
173
0
}
174
static uint32_t Predictor11_SSE2(const uint32_t* const left,
175
0
                                 const uint32_t* const top) {
176
0
  const uint32_t pred = Select_SSE2(top[0], *left, top[-1]);
177
0
  return pred;
178
0
}
179
static uint32_t Predictor12_SSE2(const uint32_t* const left,
180
0
                                 const uint32_t* const top) {
181
0
  const uint32_t pred = ClampedAddSubtractFull_SSE2(*left, top[0], top[-1]);
182
0
  return pred;
183
0
}
184
static uint32_t Predictor13_SSE2(const uint32_t* const left,
185
41.8M
                                 const uint32_t* const top) {
186
41.8M
  const uint32_t pred = ClampedAddSubtractHalf_SSE2(*left, top[0], top[-1]);
187
41.8M
  return pred;
188
41.8M
}
189
190
// Batch versions of those functions.
191
192
// Predictor0: ARGB_BLACK.
193
static void PredictorAdd0_SSE2(const uint32_t* in, const uint32_t* upper,
194
2.16M
                               int num_pixels, uint32_t* WEBP_RESTRICT out) {
195
2.16M
  int i;
196
2.16M
  const __m128i black = _mm_set1_epi32((int)ARGB_BLACK);
197
60.9M
  for (i = 0; i + 4 <= num_pixels; i += 4) {
198
58.7M
    const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);
199
58.7M
    const __m128i res = _mm_add_epi8(src, black);
200
58.7M
    _mm_storeu_si128((__m128i*)&out[i], res);
201
58.7M
  }
202
2.16M
  if (i != num_pixels) {
203
367k
    VP8LPredictorsAdd_C[0](in + i, NULL, num_pixels - i, out + i);
204
367k
  }
205
2.16M
  (void)upper;
206
2.16M
}
207
208
// Predictor1: left.
209
static void PredictorAdd1_SSE2(const uint32_t* in, const uint32_t* upper,
210
2.40M
                               int num_pixels, uint32_t* WEBP_RESTRICT out) {
211
2.40M
  int i;
212
2.40M
  __m128i prev = _mm_set1_epi32((int)out[-1]);
213
78.0M
  for (i = 0; i + 4 <= num_pixels; i += 4) {
214
    // a | b | c | d
215
75.6M
    const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);
216
    // 0 | a | b | c
217
75.6M
    const __m128i shift0 = _mm_slli_si128(src, 4);
218
    // a | a + b | b + c | c + d
219
75.6M
    const __m128i sum0 = _mm_add_epi8(src, shift0);
220
    // 0 | 0 | a | a + b
221
75.6M
    const __m128i shift1 = _mm_slli_si128(sum0, 8);
222
    // a | a + b | a + b + c | a + b + c + d
223
75.6M
    const __m128i sum1 = _mm_add_epi8(sum0, shift1);
224
75.6M
    const __m128i res = _mm_add_epi8(sum1, prev);
225
75.6M
    _mm_storeu_si128((__m128i*)&out[i], res);
226
    // replicate prev output on the four lanes
227
75.6M
    prev = _mm_shuffle_epi32(res, (3 << 0) | (3 << 2) | (3 << 4) | (3 << 6));
228
75.6M
  }
229
2.40M
  if (i != num_pixels) {
230
377k
    VP8LPredictorsAdd_C[1](in + i, upper + i, num_pixels - i, out + i);
231
377k
  }
232
2.40M
}
233
234
// Macro that adds 32-bit integers from IN using mod 256 arithmetic
235
// per 8 bit channel.
236
#define GENERATE_PREDICTOR_1(X, IN)                                         \
237
  static void PredictorAdd##X##_SSE2(const uint32_t* in,                    \
238
                                     const uint32_t* upper, int num_pixels, \
239
1.19M
                                     uint32_t* WEBP_RESTRICT out) {         \
240
1.19M
    int i;                                                                  \
241
29.4M
    for (i = 0; i + 4 <= num_pixels; i += 4) {                              \
242
28.2M
      const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);          \
243
28.2M
      const __m128i other = _mm_loadu_si128((const __m128i*)&(IN));         \
244
28.2M
      const __m128i res = _mm_add_epi8(src, other);                         \
245
28.2M
      _mm_storeu_si128((__m128i*)&out[i], res);                             \
246
28.2M
    }                                                                       \
247
1.19M
    if (i != num_pixels) {                                                  \
248
188k
      VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
249
188k
    }                                                                       \
250
1.19M
  }
lossless_sse2.c:PredictorAdd2_SSE2
Line
Count
Source
239
154k
                                     uint32_t* WEBP_RESTRICT out) {         \
240
154k
    int i;                                                                  \
241
6.13M
    for (i = 0; i + 4 <= num_pixels; i += 4) {                              \
242
5.97M
      const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);          \
243
5.97M
      const __m128i other = _mm_loadu_si128((const __m128i*)&(IN));         \
244
5.97M
      const __m128i res = _mm_add_epi8(src, other);                         \
245
5.97M
      _mm_storeu_si128((__m128i*)&out[i], res);                             \
246
5.97M
    }                                                                       \
247
154k
    if (i != num_pixels) {                                                  \
248
71.0k
      VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
249
71.0k
    }                                                                       \
250
154k
  }
lossless_sse2.c:PredictorAdd3_SSE2
Line
Count
Source
239
88.9k
                                     uint32_t* WEBP_RESTRICT out) {         \
240
88.9k
    int i;                                                                  \
241
4.53M
    for (i = 0; i + 4 <= num_pixels; i += 4) {                              \
242
4.45M
      const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);          \
243
4.45M
      const __m128i other = _mm_loadu_si128((const __m128i*)&(IN));         \
244
4.45M
      const __m128i res = _mm_add_epi8(src, other);                         \
245
4.45M
      _mm_storeu_si128((__m128i*)&out[i], res);                             \
246
4.45M
    }                                                                       \
247
88.9k
    if (i != num_pixels) {                                                  \
248
24.6k
      VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
249
24.6k
    }                                                                       \
250
88.9k
  }
lossless_sse2.c:PredictorAdd4_SSE2
Line
Count
Source
239
954k
                                     uint32_t* WEBP_RESTRICT out) {         \
240
954k
    int i;                                                                  \
241
18.7M
    for (i = 0; i + 4 <= num_pixels; i += 4) {                              \
242
17.7M
      const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);          \
243
17.7M
      const __m128i other = _mm_loadu_si128((const __m128i*)&(IN));         \
244
17.7M
      const __m128i res = _mm_add_epi8(src, other);                         \
245
17.7M
      _mm_storeu_si128((__m128i*)&out[i], res);                             \
246
17.7M
    }                                                                       \
247
954k
    if (i != num_pixels) {                                                  \
248
92.7k
      VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
249
92.7k
    }                                                                       \
250
954k
  }
251
252
// Predictor2: Top.
253
GENERATE_PREDICTOR_1(2, upper[i])
254
// Predictor3: Top-right.
255
GENERATE_PREDICTOR_1(3, upper[i + 1])
256
// Predictor4: Top-left.
257
GENERATE_PREDICTOR_1(4, upper[i - 1])
258
#undef GENERATE_PREDICTOR_1
259
260
// Due to averages with integers, values cannot be accumulated in parallel for
261
// predictors 5 to 7.
262
927k
GENERATE_PREDICTOR_ADD(Predictor5_SSE2, PredictorAdd5_SSE2)
263
708k
GENERATE_PREDICTOR_ADD(Predictor6_SSE2, PredictorAdd6_SSE2)
264
58.5k
GENERATE_PREDICTOR_ADD(Predictor7_SSE2, PredictorAdd7_SSE2)
265
266
#define GENERATE_PREDICTOR_2(X, IN)                                         \
267
  static void PredictorAdd##X##_SSE2(const uint32_t* in,                    \
268
                                     const uint32_t* upper, int num_pixels, \
269
2.57M
                                     uint32_t* WEBP_RESTRICT out) {         \
270
2.57M
    int i;                                                                  \
271
14.4M
    for (i = 0; i + 4 <= num_pixels; i += 4) {                              \
272
11.8M
      const __m128i Tother = _mm_loadu_si128((const __m128i*)&(IN));        \
273
11.8M
      const __m128i T = _mm_loadu_si128((const __m128i*)&upper[i]);         \
274
11.8M
      const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);          \
275
11.8M
      __m128i avg, res;                                                     \
276
11.8M
      Average2_m128i(&T, &Tother, &avg);                                    \
277
11.8M
      res = _mm_add_epi8(avg, src);                                         \
278
11.8M
      _mm_storeu_si128((__m128i*)&out[i], res);                             \
279
11.8M
    }                                                                       \
280
2.57M
    if (i != num_pixels) {                                                  \
281
106k
      VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
282
106k
    }                                                                       \
283
2.57M
  }
lossless_sse2.c:PredictorAdd8_SSE2
Line
Count
Source
269
488k
                                     uint32_t* WEBP_RESTRICT out) {         \
270
488k
    int i;                                                                  \
271
6.94M
    for (i = 0; i + 4 <= num_pixels; i += 4) {                              \
272
6.45M
      const __m128i Tother = _mm_loadu_si128((const __m128i*)&(IN));        \
273
6.45M
      const __m128i T = _mm_loadu_si128((const __m128i*)&upper[i]);         \
274
6.45M
      const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);          \
275
6.45M
      __m128i avg, res;                                                     \
276
6.45M
      Average2_m128i(&T, &Tother, &avg);                                    \
277
6.45M
      res = _mm_add_epi8(avg, src);                                         \
278
6.45M
      _mm_storeu_si128((__m128i*)&out[i], res);                             \
279
6.45M
    }                                                                       \
280
488k
    if (i != num_pixels) {                                                  \
281
58.7k
      VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
282
58.7k
    }                                                                       \
283
488k
  }
lossless_sse2.c:PredictorAdd9_SSE2
Line
Count
Source
269
2.08M
                                     uint32_t* WEBP_RESTRICT out) {         \
270
2.08M
    int i;                                                                  \
271
7.47M
    for (i = 0; i + 4 <= num_pixels; i += 4) {                              \
272
5.38M
      const __m128i Tother = _mm_loadu_si128((const __m128i*)&(IN));        \
273
5.38M
      const __m128i T = _mm_loadu_si128((const __m128i*)&upper[i]);         \
274
5.38M
      const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);          \
275
5.38M
      __m128i avg, res;                                                     \
276
5.38M
      Average2_m128i(&T, &Tother, &avg);                                    \
277
5.38M
      res = _mm_add_epi8(avg, src);                                         \
278
5.38M
      _mm_storeu_si128((__m128i*)&out[i], res);                             \
279
5.38M
    }                                                                       \
280
2.08M
    if (i != num_pixels) {                                                  \
281
47.5k
      VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
282
47.5k
    }                                                                       \
283
2.08M
  }
284
// Predictor8: average TL T.
285
GENERATE_PREDICTOR_2(8, upper[i - 1])
286
// Predictor9: average T TR.
287
GENERATE_PREDICTOR_2(9, upper[i + 1])
288
#undef GENERATE_PREDICTOR_2
289
290
// Predictor10: average of (average of (L,TL), average of (T, TR)).
291
#define DO_PRED10(OUT)                               \
292
97.8M
  do {                                               \
293
97.8M
    __m128i avgLTL, avg;                             \
294
97.8M
    Average2_m128i(&L, &TL, &avgLTL);                \
295
97.8M
    Average2_m128i(&avgTTR, &avgLTL, &avg);          \
296
97.8M
    L = _mm_add_epi8(avg, src);                      \
297
97.8M
    out[i + (OUT)] = (uint32_t)_mm_cvtsi128_si32(L); \
298
97.8M
  } while (0)
299
300
#define DO_PRED10_SHIFT                                         \
301
73.3M
  do {                                                          \
302
73.3M
    /* Rotate the pre-computed values for the next iteration.*/ \
303
73.3M
    avgTTR = _mm_srli_si128(avgTTR, 4);                         \
304
73.3M
    TL = _mm_srli_si128(TL, 4);                                 \
305
73.3M
    src = _mm_srli_si128(src, 4);                               \
306
73.3M
  } while (0)
307
308
static void PredictorAdd10_SSE2(const uint32_t* in, const uint32_t* upper,
309
591k
                                int num_pixels, uint32_t* WEBP_RESTRICT out) {
310
591k
  int i;
311
591k
  __m128i L = _mm_cvtsi32_si128((int)out[-1]);
312
25.0M
  for (i = 0; i + 4 <= num_pixels; i += 4) {
313
24.4M
    __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);
314
24.4M
    __m128i TL = _mm_loadu_si128((const __m128i*)&upper[i - 1]);
315
24.4M
    const __m128i T = _mm_loadu_si128((const __m128i*)&upper[i]);
316
24.4M
    const __m128i TR = _mm_loadu_si128((const __m128i*)&upper[i + 1]);
317
24.4M
    __m128i avgTTR;
318
24.4M
    Average2_m128i(&T, &TR, &avgTTR);
319
24.4M
    DO_PRED10(0);
320
24.4M
    DO_PRED10_SHIFT;
321
24.4M
    DO_PRED10(1);
322
24.4M
    DO_PRED10_SHIFT;
323
24.4M
    DO_PRED10(2);
324
24.4M
    DO_PRED10_SHIFT;
325
24.4M
    DO_PRED10(3);
326
24.4M
  }
327
591k
  if (i != num_pixels) {
328
148k
    VP8LPredictorsAdd_C[10](in + i, upper + i, num_pixels - i, out + i);
329
148k
  }
330
591k
}
331
#undef DO_PRED10
332
#undef DO_PRED10_SHIFT
333
334
// Predictor11: select.
335
#define DO_PRED11(OUT)                                                   \
336
51.9M
  do {                                                                   \
337
51.9M
    const __m128i L_lo = _mm_unpacklo_epi32(L, T);                       \
338
51.9M
    const __m128i TL_lo = _mm_unpacklo_epi32(TL, T);                     \
339
51.9M
    const __m128i pb = _mm_sad_epu8(L_lo, TL_lo); /* pb = sum |L-TL|*/   \
340
51.9M
    const __m128i mask = _mm_cmpgt_epi32(pb, pa);                        \
341
51.9M
    const __m128i A = _mm_and_si128(mask, L);                            \
342
51.9M
    const __m128i B = _mm_andnot_si128(mask, T);                         \
343
51.9M
    const __m128i pred = _mm_or_si128(A, B); /* pred = (pa > b)? L : T*/ \
344
51.9M
    L = _mm_add_epi8(src, pred);                                         \
345
51.9M
    out[i + (OUT)] = (uint32_t)_mm_cvtsi128_si32(L);                     \
346
51.9M
  } while (0)
347
348
#define DO_PRED11_SHIFT                                       \
349
38.9M
  do {                                                        \
350
38.9M
    /* Shift the pre-computed value for the next iteration.*/ \
351
38.9M
    T = _mm_srli_si128(T, 4);                                 \
352
38.9M
    TL = _mm_srli_si128(TL, 4);                               \
353
38.9M
    src = _mm_srli_si128(src, 4);                             \
354
38.9M
    pa = _mm_srli_si128(pa, 4);                               \
355
38.9M
  } while (0)
356
357
static void PredictorAdd11_SSE2(const uint32_t* in, const uint32_t* upper,
358
4.25M
                                int num_pixels, uint32_t* WEBP_RESTRICT out) {
359
4.25M
  int i;
360
4.25M
  __m128i pa;
361
4.25M
  __m128i L = _mm_cvtsi32_si128((int)out[-1]);
362
17.2M
  for (i = 0; i + 4 <= num_pixels; i += 4) {
363
12.9M
    __m128i T = _mm_loadu_si128((const __m128i*)&upper[i]);
364
12.9M
    __m128i TL = _mm_loadu_si128((const __m128i*)&upper[i - 1]);
365
12.9M
    __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);
366
12.9M
    {
367
      // We can unpack with any value on the upper 32 bits, provided it's the
368
      // same on both operands (so that their sum of abs diff is zero). Here we
369
      // use T.
370
12.9M
      const __m128i T_lo = _mm_unpacklo_epi32(T, T);
371
12.9M
      const __m128i TL_lo = _mm_unpacklo_epi32(TL, T);
372
12.9M
      const __m128i T_hi = _mm_unpackhi_epi32(T, T);
373
12.9M
      const __m128i TL_hi = _mm_unpackhi_epi32(TL, T);
374
12.9M
      const __m128i s_lo = _mm_sad_epu8(T_lo, TL_lo);
375
12.9M
      const __m128i s_hi = _mm_sad_epu8(T_hi, TL_hi);
376
12.9M
      pa = _mm_packs_epi32(s_lo, s_hi);  // pa = sum |T-TL|
377
12.9M
    }
378
12.9M
    DO_PRED11(0);
379
12.9M
    DO_PRED11_SHIFT;
380
12.9M
    DO_PRED11(1);
381
12.9M
    DO_PRED11_SHIFT;
382
12.9M
    DO_PRED11(2);
383
12.9M
    DO_PRED11_SHIFT;
384
12.9M
    DO_PRED11(3);
385
12.9M
  }
386
4.25M
  if (i != num_pixels) {
387
76.2k
    VP8LPredictorsAdd_C[11](in + i, upper + i, num_pixels - i, out + i);
388
76.2k
  }
389
4.25M
}
390
#undef DO_PRED11
391
#undef DO_PRED11_SHIFT
392
393
// Predictor12: ClampedAddSubtractFull.
394
#define DO_PRED12(DIFF, LANE, OUT)                     \
395
138M
  do {                                                 \
396
138M
    const __m128i all = _mm_add_epi16(L, (DIFF));      \
397
138M
    const __m128i alls = _mm_packus_epi16(all, all);   \
398
138M
    const __m128i res = _mm_add_epi8(src, alls);       \
399
138M
    out[i + (OUT)] = (uint32_t)_mm_cvtsi128_si32(res); \
400
138M
    L = _mm_unpacklo_epi8(res, zero);                  \
401
138M
  } while (0)
402
403
#define DO_PRED12_SHIFT(DIFF, LANE)                           \
404
103M
  do {                                                        \
405
103M
    /* Shift the pre-computed value for the next iteration.*/ \
406
103M
    if ((LANE) == 0) (DIFF) = _mm_srli_si128((DIFF), 8);      \
407
103M
    src = _mm_srli_si128(src, 4);                             \
408
103M
  } while (0)
409
410
static void PredictorAdd12_SSE2(const uint32_t* in, const uint32_t* upper,
411
1.73M
                                int num_pixels, uint32_t* WEBP_RESTRICT out) {
412
1.73M
  int i;
413
1.73M
  const __m128i zero = _mm_setzero_si128();
414
1.73M
  const __m128i L8 = _mm_cvtsi32_si128((int)out[-1]);
415
1.73M
  __m128i L = _mm_unpacklo_epi8(L8, zero);
416
36.3M
  for (i = 0; i + 4 <= num_pixels; i += 4) {
417
    // Load 4 pixels at a time.
418
34.6M
    __m128i src = _mm_loadu_si128((const __m128i*)&in[i]);
419
34.6M
    const __m128i T = _mm_loadu_si128((const __m128i*)&upper[i]);
420
34.6M
    const __m128i T_lo = _mm_unpacklo_epi8(T, zero);
421
34.6M
    const __m128i T_hi = _mm_unpackhi_epi8(T, zero);
422
34.6M
    const __m128i TL = _mm_loadu_si128((const __m128i*)&upper[i - 1]);
423
34.6M
    const __m128i TL_lo = _mm_unpacklo_epi8(TL, zero);
424
34.6M
    const __m128i TL_hi = _mm_unpackhi_epi8(TL, zero);
425
34.6M
    __m128i diff_lo = _mm_sub_epi16(T_lo, TL_lo);
426
34.6M
    __m128i diff_hi = _mm_sub_epi16(T_hi, TL_hi);
427
34.6M
    DO_PRED12(diff_lo, 0, 0);
428
34.6M
    DO_PRED12_SHIFT(diff_lo, 0);
429
34.6M
    DO_PRED12(diff_lo, 1, 1);
430
34.6M
    DO_PRED12_SHIFT(diff_lo, 1);
431
34.6M
    DO_PRED12(diff_hi, 0, 2);
432
34.6M
    DO_PRED12_SHIFT(diff_hi, 0);
433
34.6M
    DO_PRED12(diff_hi, 1, 3);
434
34.6M
  }
435
1.73M
  if (i != num_pixels) {
436
218k
    VP8LPredictorsAdd_C[12](in + i, upper + i, num_pixels - i, out + i);
437
218k
  }
438
1.73M
}
439
#undef DO_PRED12
440
#undef DO_PRED12_SHIFT
441
442
// Due to averages with integers, values cannot be accumulated in parallel for
443
// predictors 13.
444
482k
GENERATE_PREDICTOR_ADD(Predictor13_SSE2, PredictorAdd13_SSE2)
445
446
//------------------------------------------------------------------------------
447
// Subtract-Green Transform
448
449
static void AddGreenToBlueAndRed_SSE2(const uint32_t* const src, int num_pixels,
450
16.8k
                                      uint32_t* dst) {
451
16.8k
  int i;
452
9.37M
  for (i = 0; i + 4 <= num_pixels; i += 4) {
453
9.35M
    const __m128i in = _mm_loadu_si128((const __m128i*)&src[i]);  // argb
454
9.35M
    const __m128i A = _mm_srli_epi16(in, 8);                      // 0 a 0 g
455
9.35M
    const __m128i B = _mm_shufflelo_epi16(A, _MM_SHUFFLE(2, 2, 0, 0));
456
9.35M
    const __m128i C = _mm_shufflehi_epi16(B, _MM_SHUFFLE(2, 2, 0, 0));  // 0g0g
457
9.35M
    const __m128i out = _mm_add_epi8(in, C);
458
9.35M
    _mm_storeu_si128((__m128i*)&dst[i], out);
459
9.35M
  }
460
  // fallthrough and finish off with plain-C
461
16.8k
  if (i != num_pixels) {
462
7.25k
    VP8LAddGreenToBlueAndRed_C(src + i, num_pixels - i, dst + i);
463
7.25k
  }
464
16.8k
}
465
466
//------------------------------------------------------------------------------
467
// Color Transform
468
469
static void TransformColorInverse_SSE2(const VP8LMultipliers* const m,
470
                                       const uint32_t* const src,
471
0
                                       int num_pixels, uint32_t* dst) {
472
// sign-extended multiplying constants, pre-shifted by 5.
473
0
#define CST(X) (((int16_t)(m->X << 8)) >> 5)  // sign-extend
474
0
#define MK_CST_16(HI, LO) \
475
0
  _mm_set1_epi32((int)(((uint32_t)(HI) << 16) | ((LO) & 0xffff)))
476
0
  const __m128i mults_rb = MK_CST_16(CST(green_to_red), CST(green_to_blue));
477
0
  const __m128i mults_b2 = MK_CST_16(CST(red_to_blue), 0);
478
0
#undef MK_CST_16
479
0
#undef CST
480
0
  const __m128i mask_ag = _mm_set1_epi32((int)0xff00ff00);  // alpha-green masks
481
0
  int i;
482
0
  for (i = 0; i + 4 <= num_pixels; i += 4) {
483
0
    const __m128i in = _mm_loadu_si128((const __m128i*)&src[i]);  // argb
484
0
    const __m128i A = _mm_and_si128(in, mask_ag);  // a   0   g   0
485
0
    const __m128i B = _mm_shufflelo_epi16(A, _MM_SHUFFLE(2, 2, 0, 0));
486
0
    const __m128i C = _mm_shufflehi_epi16(B, _MM_SHUFFLE(2, 2, 0, 0));  // g0g0
487
0
    const __m128i D = _mm_mulhi_epi16(C, mults_rb);  // x dr  x db1
488
0
    const __m128i E = _mm_add_epi8(in, D);           // x r'  x   b'
489
0
    const __m128i F = _mm_slli_epi16(E, 8);          // r' 0   b' 0
490
0
    const __m128i G = _mm_mulhi_epi16(F, mults_b2);  // x db2  0  0
491
0
    const __m128i H = _mm_srli_epi32(G, 8);          // 0  x db2  0
492
0
    const __m128i I = _mm_add_epi8(H, F);            // r' x  b'' 0
493
0
    const __m128i J = _mm_srli_epi16(I, 8);          // 0  r'  0  b''
494
0
    const __m128i out = _mm_or_si128(J, A);
495
0
    _mm_storeu_si128((__m128i*)&dst[i], out);
496
0
  }
497
  // Fall-back to C-version for left-overs.
498
0
  if (i != num_pixels) {
499
0
    VP8LTransformColorInverse_C(m, src + i, num_pixels - i, dst + i);
500
0
  }
501
0
}
502
503
//------------------------------------------------------------------------------
504
// Color-space conversion functions
505
506
static void ConvertBGRAToRGB_SSE2(const uint32_t* WEBP_RESTRICT src,
507
0
                                  int num_pixels, uint8_t* WEBP_RESTRICT dst) {
508
0
  const __m128i* in = (const __m128i*)src;
509
0
  __m128i* out = (__m128i*)dst;
510
511
0
  while (num_pixels >= 32) {
512
    // Load the BGRA buffers.
513
0
    __m128i in0 = _mm_loadu_si128(in + 0);
514
0
    __m128i in1 = _mm_loadu_si128(in + 1);
515
0
    __m128i in2 = _mm_loadu_si128(in + 2);
516
0
    __m128i in3 = _mm_loadu_si128(in + 3);
517
0
    __m128i in4 = _mm_loadu_si128(in + 4);
518
0
    __m128i in5 = _mm_loadu_si128(in + 5);
519
0
    __m128i in6 = _mm_loadu_si128(in + 6);
520
0
    __m128i in7 = _mm_loadu_si128(in + 7);
521
0
    VP8L32bToPlanar_SSE2(&in0, &in1, &in2, &in3);
522
0
    VP8L32bToPlanar_SSE2(&in4, &in5, &in6, &in7);
523
    // At this points, in1/in5 contains red only, in2/in6 green only ...
524
    // Pack the colors in 24b RGB.
525
0
    VP8PlanarTo24b_SSE2(&in1, &in5, &in2, &in6, &in3, &in7);
526
0
    _mm_storeu_si128(out + 0, in1);
527
0
    _mm_storeu_si128(out + 1, in5);
528
0
    _mm_storeu_si128(out + 2, in2);
529
0
    _mm_storeu_si128(out + 3, in6);
530
0
    _mm_storeu_si128(out + 4, in3);
531
0
    _mm_storeu_si128(out + 5, in7);
532
0
    in += 8;
533
0
    out += 6;
534
0
    num_pixels -= 32;
535
0
  }
536
  // left-overs
537
0
  if (num_pixels > 0) {
538
0
    VP8LConvertBGRAToRGB_C((const uint32_t*)in, num_pixels, (uint8_t*)out);
539
0
  }
540
0
}
541
542
static void ConvertBGRAToRGBA_SSE2(const uint32_t* WEBP_RESTRICT src,
543
2.58M
                                   int num_pixels, uint8_t* WEBP_RESTRICT dst) {
544
2.58M
  const __m128i red_blue_mask = _mm_set1_epi32(0x00ff00ff);
545
2.58M
  const __m128i* in = (const __m128i*)src;
546
2.58M
  __m128i* out = (__m128i*)dst;
547
290M
  while (num_pixels >= 8) {
548
287M
    const __m128i A1 = _mm_loadu_si128(in++);
549
287M
    const __m128i A2 = _mm_loadu_si128(in++);
550
287M
    const __m128i B1 = _mm_and_si128(A1, red_blue_mask);     // R 0 B 0
551
287M
    const __m128i B2 = _mm_and_si128(A2, red_blue_mask);     // R 0 B 0
552
287M
    const __m128i C1 = _mm_andnot_si128(red_blue_mask, A1);  // 0 G 0 A
553
287M
    const __m128i C2 = _mm_andnot_si128(red_blue_mask, A2);  // 0 G 0 A
554
287M
    const __m128i D1 = _mm_shufflelo_epi16(B1, _MM_SHUFFLE(2, 3, 0, 1));
555
287M
    const __m128i D2 = _mm_shufflelo_epi16(B2, _MM_SHUFFLE(2, 3, 0, 1));
556
287M
    const __m128i E1 = _mm_shufflehi_epi16(D1, _MM_SHUFFLE(2, 3, 0, 1));
557
287M
    const __m128i E2 = _mm_shufflehi_epi16(D2, _MM_SHUFFLE(2, 3, 0, 1));
558
287M
    const __m128i F1 = _mm_or_si128(E1, C1);
559
287M
    const __m128i F2 = _mm_or_si128(E2, C2);
560
287M
    _mm_storeu_si128(out++, F1);
561
287M
    _mm_storeu_si128(out++, F2);
562
287M
    num_pixels -= 8;
563
287M
  }
564
  // left-overs
565
2.58M
  if (num_pixels > 0) {
566
2.21M
    VP8LConvertBGRAToRGBA_C((const uint32_t*)in, num_pixels, (uint8_t*)out);
567
2.21M
  }
568
2.58M
}
569
570
static void ConvertBGRAToRGBA4444_SSE2(const uint32_t* WEBP_RESTRICT src,
571
                                       int num_pixels,
572
0
                                       uint8_t* WEBP_RESTRICT dst) {
573
0
  const __m128i mask_0x0f = _mm_set1_epi8(0x0f);
574
0
  const __m128i mask_0xf0 = _mm_set1_epi8((char)0xf0);
575
0
  const __m128i* in = (const __m128i*)src;
576
0
  __m128i* out = (__m128i*)dst;
577
0
  while (num_pixels >= 8) {
578
0
    const __m128i bgra0 = _mm_loadu_si128(in++);  // bgra0|bgra1|bgra2|bgra3
579
0
    const __m128i bgra4 = _mm_loadu_si128(in++);  // bgra4|bgra5|bgra6|bgra7
580
0
    const __m128i v0l = _mm_unpacklo_epi8(bgra0, bgra4);  // b0b4g0g4r0r4a0a4...
581
0
    const __m128i v0h = _mm_unpackhi_epi8(bgra0, bgra4);  // b2b6g2g6r2r6a2a6...
582
0
    const __m128i v1l = _mm_unpacklo_epi8(v0l, v0h);      // b0b2b4b6g0g2g4g6...
583
0
    const __m128i v1h = _mm_unpackhi_epi8(v0l, v0h);      // b1b3b5b7g1g3g5g7...
584
0
    const __m128i v2l = _mm_unpacklo_epi8(v1l, v1h);      // b0...b7 | g0...g7
585
0
    const __m128i v2h = _mm_unpackhi_epi8(v1l, v1h);      // r0...r7 | a0...a7
586
0
    const __m128i ga0 = _mm_unpackhi_epi64(v2l, v2h);     // g0...g7 | a0...a7
587
0
    const __m128i rb0 = _mm_unpacklo_epi64(v2h, v2l);     // r0...r7 | b0...b7
588
0
    const __m128i ga1 = _mm_srli_epi16(ga0, 4);           // g0-|g1-|...|a6-|a7-
589
0
    const __m128i rb1 = _mm_and_si128(rb0, mask_0xf0);    // -r0|-r1|...|-b6|-a7
590
0
    const __m128i ga2 = _mm_and_si128(ga1, mask_0x0f);    // g0-|g1-|...|a6-|a7-
591
0
    const __m128i rgba0 = _mm_or_si128(ga2, rb1);         // rg0..rg7 | ba0..ba7
592
0
    const __m128i rgba1 = _mm_srli_si128(rgba0, 8);       // ba0..ba7 | 0
593
#if (WEBP_SWAP_16BIT_CSP == 1)
594
    const __m128i rgba = _mm_unpacklo_epi8(rgba1, rgba0);  // barg0...barg7
595
#else
596
0
    const __m128i rgba = _mm_unpacklo_epi8(rgba0, rgba1);  // rgba0...rgba7
597
0
#endif
598
0
    _mm_storeu_si128(out++, rgba);
599
0
    num_pixels -= 8;
600
0
  }
601
  // left-overs
602
0
  if (num_pixels > 0) {
603
0
    VP8LConvertBGRAToRGBA4444_C((const uint32_t*)in, num_pixels, (uint8_t*)out);
604
0
  }
605
0
}
606
607
static void ConvertBGRAToRGB565_SSE2(const uint32_t* WEBP_RESTRICT src,
608
                                     int num_pixels,
609
0
                                     uint8_t* WEBP_RESTRICT dst) {
610
0
  const __m128i mask_0xe0 = _mm_set1_epi8((char)0xe0);
611
0
  const __m128i mask_0xf8 = _mm_set1_epi8((char)0xf8);
612
0
  const __m128i mask_0x07 = _mm_set1_epi8(0x07);
613
0
  const __m128i* in = (const __m128i*)src;
614
0
  __m128i* out = (__m128i*)dst;
615
0
  while (num_pixels >= 8) {
616
0
    const __m128i bgra0 = _mm_loadu_si128(in++);  // bgra0|bgra1|bgra2|bgra3
617
0
    const __m128i bgra4 = _mm_loadu_si128(in++);  // bgra4|bgra5|bgra6|bgra7
618
0
    const __m128i v0l = _mm_unpacklo_epi8(bgra0, bgra4);  // b0b4g0g4r0r4a0a4...
619
0
    const __m128i v0h = _mm_unpackhi_epi8(bgra0, bgra4);  // b2b6g2g6r2r6a2a6...
620
0
    const __m128i v1l = _mm_unpacklo_epi8(v0l, v0h);      // b0b2b4b6g0g2g4g6...
621
0
    const __m128i v1h = _mm_unpackhi_epi8(v0l, v0h);      // b1b3b5b7g1g3g5g7...
622
0
    const __m128i v2l = _mm_unpacklo_epi8(v1l, v1h);      // b0...b7 | g0...g7
623
0
    const __m128i v2h = _mm_unpackhi_epi8(v1l, v1h);      // r0...r7 | a0...a7
624
0
    const __m128i ga0 = _mm_unpackhi_epi64(v2l, v2h);     // g0...g7 | a0...a7
625
0
    const __m128i rb0 = _mm_unpacklo_epi64(v2h, v2l);     // r0...r7 | b0...b7
626
0
    const __m128i rb1 = _mm_and_si128(rb0, mask_0xf8);    // -r0..-r7|-b0..-b7
627
0
    const __m128i g_lo1 = _mm_srli_epi16(ga0, 5);
628
0
    const __m128i g_lo2 = _mm_and_si128(g_lo1, mask_0x07);  // g0-...g7-|xx (3b)
629
0
    const __m128i g_hi1 = _mm_slli_epi16(ga0, 3);
630
0
    const __m128i g_hi2 = _mm_and_si128(g_hi1, mask_0xe0);  // -g0...-g7|xx (3b)
631
0
    const __m128i b0 = _mm_srli_si128(rb1, 8);              // -b0...-b7|0
632
0
    const __m128i rg1 = _mm_or_si128(rb1, g_lo2);           // gr0...gr7|xx
633
0
    const __m128i b1 = _mm_srli_epi16(b0, 3);
634
0
    const __m128i gb1 = _mm_or_si128(b1, g_hi2);  // bg0...bg7|xx
635
#if (WEBP_SWAP_16BIT_CSP == 1)
636
    const __m128i rgba = _mm_unpacklo_epi8(gb1, rg1);  // rggb0...rggb7
637
#else
638
0
    const __m128i rgba = _mm_unpacklo_epi8(rg1, gb1);  // bgrb0...bgrb7
639
0
#endif
640
0
    _mm_storeu_si128(out++, rgba);
641
0
    num_pixels -= 8;
642
0
  }
643
  // left-overs
644
0
  if (num_pixels > 0) {
645
0
    VP8LConvertBGRAToRGB565_C((const uint32_t*)in, num_pixels, (uint8_t*)out);
646
0
  }
647
0
}
648
649
static void ConvertBGRAToBGR_SSE2(const uint32_t* WEBP_RESTRICT src,
650
0
                                  int num_pixels, uint8_t* WEBP_RESTRICT dst) {
651
0
  const __m128i mask_l = _mm_set_epi32(0, 0x00ffffff, 0, 0x00ffffff);
652
0
  const __m128i mask_h = _mm_set_epi32(0x00ffffff, 0, 0x00ffffff, 0);
653
0
  const __m128i* in = (const __m128i*)src;
654
0
  const uint8_t* const end = dst + num_pixels * 3;
655
  // the last storel_epi64 below writes 8 bytes starting at offset 18
656
0
  while (dst + 26 <= end) {
657
0
    const __m128i bgra0 = _mm_loadu_si128(in++);  // bgra0|bgra1|bgra2|bgra3
658
0
    const __m128i bgra4 = _mm_loadu_si128(in++);  // bgra4|bgra5|bgra6|bgra7
659
0
    const __m128i a0l = _mm_and_si128(bgra0, mask_l);  // bgr0|0|bgr0|0
660
0
    const __m128i a4l = _mm_and_si128(bgra4, mask_l);  // bgr0|0|bgr0|0
661
0
    const __m128i a0h = _mm_and_si128(bgra0, mask_h);  // 0|bgr0|0|bgr0
662
0
    const __m128i a4h = _mm_and_si128(bgra4, mask_h);  // 0|bgr0|0|bgr0
663
0
    const __m128i b0h = _mm_srli_epi64(a0h, 8);        // 000b|gr00|000b|gr00
664
0
    const __m128i b4h = _mm_srli_epi64(a4h, 8);        // 000b|gr00|000b|gr00
665
0
    const __m128i c0 = _mm_or_si128(a0l, b0h);         // rgbrgb00|rgbrgb00
666
0
    const __m128i c4 = _mm_or_si128(a4l, b4h);         // rgbrgb00|rgbrgb00
667
0
    const __m128i c2 = _mm_srli_si128(c0, 8);
668
0
    const __m128i c6 = _mm_srli_si128(c4, 8);
669
0
    _mm_storel_epi64((__m128i*)(dst + 0), c0);
670
0
    _mm_storel_epi64((__m128i*)(dst + 6), c2);
671
0
    _mm_storel_epi64((__m128i*)(dst + 12), c4);
672
0
    _mm_storel_epi64((__m128i*)(dst + 18), c6);
673
0
    dst += 24;
674
0
    num_pixels -= 8;
675
0
  }
676
  // left-overs
677
0
  if (num_pixels > 0) {
678
0
    VP8LConvertBGRAToBGR_C((const uint32_t*)in, num_pixels, dst);
679
0
  }
680
0
}
681
682
//------------------------------------------------------------------------------
683
// Entry point
684
685
extern void VP8LDspInitSSE2(void);
686
687
7
WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInitSSE2(void) {
688
7
  VP8LPredictors[5] = Predictor5_SSE2;
689
7
  VP8LPredictors[6] = Predictor6_SSE2;
690
7
  VP8LPredictors[7] = Predictor7_SSE2;
691
7
  VP8LPredictors[8] = Predictor8_SSE2;
692
7
  VP8LPredictors[9] = Predictor9_SSE2;
693
7
  VP8LPredictors[10] = Predictor10_SSE2;
694
7
  VP8LPredictors[11] = Predictor11_SSE2;
695
7
  VP8LPredictors[12] = Predictor12_SSE2;
696
7
  VP8LPredictors[13] = Predictor13_SSE2;
697
698
  // SSE exports for AVX and above.
699
7
  VP8LPredictorsAdd_SSE[0] = PredictorAdd0_SSE2;
700
7
  VP8LPredictorsAdd_SSE[1] = PredictorAdd1_SSE2;
701
7
  VP8LPredictorsAdd_SSE[2] = PredictorAdd2_SSE2;
702
7
  VP8LPredictorsAdd_SSE[3] = PredictorAdd3_SSE2;
703
7
  VP8LPredictorsAdd_SSE[4] = PredictorAdd4_SSE2;
704
7
  VP8LPredictorsAdd_SSE[5] = PredictorAdd5_SSE2;
705
7
  VP8LPredictorsAdd_SSE[6] = PredictorAdd6_SSE2;
706
7
  VP8LPredictorsAdd_SSE[7] = PredictorAdd7_SSE2;
707
7
  VP8LPredictorsAdd_SSE[8] = PredictorAdd8_SSE2;
708
7
  VP8LPredictorsAdd_SSE[9] = PredictorAdd9_SSE2;
709
7
  VP8LPredictorsAdd_SSE[10] = PredictorAdd10_SSE2;
710
7
  VP8LPredictorsAdd_SSE[11] = PredictorAdd11_SSE2;
711
7
  VP8LPredictorsAdd_SSE[12] = PredictorAdd12_SSE2;
712
7
  VP8LPredictorsAdd_SSE[13] = PredictorAdd13_SSE2;
713
  // padding security sentinels
714
7
  VP8LPredictorsAdd_SSE[14] = PredictorAdd0_SSE2;
715
7
  VP8LPredictorsAdd_SSE[15] = PredictorAdd0_SSE2;
716
7
  memcpy(VP8LPredictorsAdd, VP8LPredictorsAdd_SSE, sizeof(VP8LPredictorsAdd));
717
718
  // SSE exports for AVX and above.
719
7
  VP8LAddGreenToBlueAndRed_SSE = AddGreenToBlueAndRed_SSE2;
720
7
  VP8LTransformColorInverse_SSE = TransformColorInverse_SSE2;
721
7
  VP8LAddGreenToBlueAndRed = VP8LAddGreenToBlueAndRed_SSE;
722
7
  VP8LTransformColorInverse = VP8LTransformColorInverse_SSE;
723
724
7
  VP8LConvertBGRAToRGB = ConvertBGRAToRGB_SSE2;
725
7
  VP8LConvertBGRAToRGBA = ConvertBGRAToRGBA_SSE2;
726
7
  VP8LConvertBGRAToRGBA4444 = ConvertBGRAToRGBA4444_SSE2;
727
7
  VP8LConvertBGRAToRGB565 = ConvertBGRAToRGB565_SSE2;
728
7
  VP8LConvertBGRAToBGR = ConvertBGRAToBGR_SSE2;
729
730
7
  VP8LConvertBGRAToRGB_SSE = ConvertBGRAToRGB_SSE2;
731
7
  VP8LConvertBGRAToRGBA_SSE = ConvertBGRAToRGBA_SSE2;
732
7
}
733
734
#else  // !WEBP_USE_SSE2
735
736
WEBP_DSP_INIT_STUB(VP8LDspInitSSE2)
737
738
#endif  // WEBP_USE_SSE2