11#if defined(QT_COMPILER_SUPPORTS_AVX2)
23inline static void Q_DECL_VECTORCALL
24BYTE_MUL_AVX2(__m256i &pixelVector, __m256i alphaChannel, __m256i colorMask, __m256i half)
26 __m256i pixelVectorAG = _mm256_srli_epi16(pixelVector, 8);
27 __m256i pixelVectorRB = _mm256_and_si256(pixelVector, colorMask);
29 pixelVectorAG = _mm256_mullo_epi16(pixelVectorAG, alphaChannel);
30 pixelVectorRB = _mm256_mullo_epi16(pixelVectorRB, alphaChannel);
32 pixelVectorRB = _mm256_add_epi16(pixelVectorRB, _mm256_srli_epi16(pixelVectorRB, 8));
33 pixelVectorAG = _mm256_add_epi16(pixelVectorAG, _mm256_srli_epi16(pixelVectorAG, 8));
34 pixelVectorRB = _mm256_add_epi16(pixelVectorRB, half);
35 pixelVectorAG = _mm256_add_epi16(pixelVectorAG, half);
37 pixelVectorRB = _mm256_srli_epi16(pixelVectorRB, 8);
38 pixelVector = _mm256_blendv_epi8(pixelVectorAG, pixelVectorRB, colorMask);
41inline static void Q_DECL_VECTORCALL
42BYTE_MUL_RGB64_AVX2(__m256i &pixelVector, __m256i alphaChannel, __m256i colorMask, __m256i half)
44 __m256i pixelVectorAG = _mm256_srli_epi32(pixelVector, 16);
45 __m256i pixelVectorRB = _mm256_and_si256(pixelVector, colorMask);
47 pixelVectorAG = _mm256_mullo_epi32(pixelVectorAG, alphaChannel);
48 pixelVectorRB = _mm256_mullo_epi32(pixelVectorRB, alphaChannel);
50 pixelVectorRB = _mm256_add_epi32(pixelVectorRB, _mm256_srli_epi32(pixelVectorRB, 16));
51 pixelVectorAG = _mm256_add_epi32(pixelVectorAG, _mm256_srli_epi32(pixelVectorAG, 16));
52 pixelVectorRB = _mm256_add_epi32(pixelVectorRB, half);
53 pixelVectorAG = _mm256_add_epi32(pixelVectorAG, half);
55 pixelVectorRB = _mm256_srli_epi32(pixelVectorRB, 16);
56 pixelVector = _mm256_blendv_epi8(pixelVectorAG, pixelVectorRB, colorMask);
60inline static void Q_DECL_VECTORCALL
61INTERPOLATE_PIXEL_255_AVX2(__m256i srcVector, __m256i &dstVector, __m256i alphaChannel, __m256i oneMinusAlphaChannel, __m256i colorMask, __m256i half)
63 const __m256i srcVectorAG = _mm256_srli_epi16(srcVector, 8);
64 const __m256i dstVectorAG = _mm256_srli_epi16(dstVector, 8);
65 const __m256i srcVectorRB = _mm256_and_si256(srcVector, colorMask);
66 const __m256i dstVectorRB = _mm256_and_si256(dstVector, colorMask);
67 const __m256i srcVectorAGalpha = _mm256_mullo_epi16(srcVectorAG, alphaChannel);
68 const __m256i srcVectorRBalpha = _mm256_mullo_epi16(srcVectorRB, alphaChannel);
69 const __m256i dstVectorAGoneMinusAlpha = _mm256_mullo_epi16(dstVectorAG, oneMinusAlphaChannel);
70 const __m256i dstVectorRBoneMinusAlpha = _mm256_mullo_epi16(dstVectorRB, oneMinusAlphaChannel);
71 __m256i finalAG = _mm256_add_epi16(srcVectorAGalpha, dstVectorAGoneMinusAlpha);
72 __m256i finalRB = _mm256_add_epi16(srcVectorRBalpha, dstVectorRBoneMinusAlpha);
73 finalAG = _mm256_add_epi16(finalAG, _mm256_srli_epi16(finalAG, 8));
74 finalRB = _mm256_add_epi16(finalRB, _mm256_srli_epi16(finalRB, 8));
75 finalAG = _mm256_add_epi16(finalAG, half);
76 finalRB = _mm256_add_epi16(finalRB, half);
77 finalRB = _mm256_srli_epi16(finalRB, 8);
79 dstVector = _mm256_blendv_epi8(finalAG, finalRB, colorMask);
82inline static void Q_DECL_VECTORCALL
83INTERPOLATE_PIXEL_RGB64_AVX2(__m256i srcVector, __m256i &dstVector, __m256i alphaChannel, __m256i oneMinusAlphaChannel, __m256i colorMask, __m256i half)
85 const __m256i srcVectorAG = _mm256_srli_epi32(srcVector, 16);
86 const __m256i dstVectorAG = _mm256_srli_epi32(dstVector, 16);
87 const __m256i srcVectorRB = _mm256_and_si256(srcVector, colorMask);
88 const __m256i dstVectorRB = _mm256_and_si256(dstVector, colorMask);
89 const __m256i srcVectorAGalpha = _mm256_mullo_epi32(srcVectorAG, alphaChannel);
90 const __m256i srcVectorRBalpha = _mm256_mullo_epi32(srcVectorRB, alphaChannel);
91 const __m256i dstVectorAGoneMinusAlpha = _mm256_mullo_epi32(dstVectorAG, oneMinusAlphaChannel);
92 const __m256i dstVectorRBoneMinusAlpha = _mm256_mullo_epi32(dstVectorRB, oneMinusAlphaChannel);
93 __m256i finalAG = _mm256_add_epi32(srcVectorAGalpha, dstVectorAGoneMinusAlpha);
94 __m256i finalRB = _mm256_add_epi32(srcVectorRBalpha, dstVectorRBoneMinusAlpha);
95 finalAG = _mm256_add_epi32(finalAG, _mm256_srli_epi32(finalAG, 16));
96 finalRB = _mm256_add_epi32(finalRB, _mm256_srli_epi32(finalRB, 16));
97 finalAG = _mm256_add_epi32(finalAG, half);
98 finalRB = _mm256_add_epi32(finalRB, half);
99 finalRB = _mm256_srli_epi32(finalRB, 16);
100 dstVector = _mm256_blendv_epi8(finalAG, finalRB, colorMask);
104inline static void Q_DECL_VECTORCALL BLEND_SOURCE_OVER_ARGB32_AVX2(quint32 *dst,
const quint32 *src,
const int length)
106 const __m256i half = _mm256_set1_epi16(0x80);
107 const __m256i one = _mm256_set1_epi16(0xff);
108 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
109 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
110 const __m256i offsetMask = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
111 const __m256i alphaShuffleMask = _mm256_set_epi8(
char(0xff),15,
char(0xff),15,
char(0xff),11,
char(0xff),11,
char(0xff),7,
char(0xff),7,
char(0xff),3,
char(0xff),3,
112 char(0xff),15,
char(0xff),15,
char(0xff),11,
char(0xff),11,
char(0xff),7,
char(0xff),7,
char(0xff),3,
char(0xff),3);
114 const int minusOffsetToAlignDstOn32Bytes = (
reinterpret_cast<quintptr>(dst) >> 2) & 0x7;
118 if (minusOffsetToAlignDstOn32Bytes != 0 && x < (length - 7)) {
119 const __m256i prologueMask = _mm256_sub_epi32(_mm256_set1_epi32(minusOffsetToAlignDstOn32Bytes - 1), offsetMask);
120 const __m256i srcVector = _mm256_maskload_epi32((
const int *)&src[x - minusOffsetToAlignDstOn32Bytes], prologueMask);
121 const __m256i prologueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, prologueMask);
122 if (!_mm256_testz_si256(srcVector, prologueAlphaMask)) {
123 if (_mm256_testc_si256(srcVector, prologueAlphaMask)) {
124 _mm256_maskstore_epi32((
int *)&dst[x - minusOffsetToAlignDstOn32Bytes], prologueMask, srcVector);
126 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
127 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
128 __m256i dstVector = _mm256_maskload_epi32((
int *)&dst[x - minusOffsetToAlignDstOn32Bytes], prologueMask);
129 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
130 dstVector = _mm256_add_epi8(dstVector, srcVector);
131 _mm256_maskstore_epi32((
int *)&dst[x - minusOffsetToAlignDstOn32Bytes], prologueMask, dstVector);
134 x += (8 - minusOffsetToAlignDstOn32Bytes);
137 for (; x < (length - 7); x += 8) {
138 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
139 if (!_mm256_testz_si256(srcVector, alphaMask)) {
140 if (_mm256_testc_si256(srcVector, alphaMask)) {
141 _mm256_store_si256((__m256i *)&dst[x], srcVector);
143 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
144 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
145 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
146 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
147 dstVector = _mm256_add_epi8(dstVector, srcVector);
148 _mm256_store_si256((__m256i *)&dst[x], dstVector);
155 const __m256i epilogueMask = _mm256_add_epi32(offsetMask, _mm256_set1_epi32(x - length));
156 const __m256i srcVector = _mm256_maskload_epi32((
const int *)&src[x], epilogueMask);
157 const __m256i epilogueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, epilogueMask);
158 if (!_mm256_testz_si256(srcVector, epilogueAlphaMask)) {
159 if (_mm256_testc_si256(srcVector, epilogueAlphaMask)) {
160 _mm256_maskstore_epi32((
int *)&dst[x], epilogueMask, srcVector);
162 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
163 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
164 __m256i dstVector = _mm256_maskload_epi32((
int *)&dst[x], epilogueMask);
165 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
166 dstVector = _mm256_add_epi8(dstVector, srcVector);
167 _mm256_maskstore_epi32((
int *)&dst[x], epilogueMask, dstVector);
175inline static void Q_DECL_VECTORCALL
176BLEND_SOURCE_OVER_ARGB32_WITH_CONST_ALPHA_AVX2(quint32 *dst,
const quint32 *src,
const int length,
const int const_alpha)
180 ALIGNMENT_PROLOGUE_32BYTES(dst, x, length)
181 blend_pixel(dst[x], src[x], const_alpha);
183 const __m256i half = _mm256_set1_epi16(0x80);
184 const __m256i one = _mm256_set1_epi16(0xff);
185 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
186 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
187 const __m256i alphaShuffleMask = _mm256_set_epi8(
char(0xff),15,
char(0xff),15,
char(0xff),11,
char(0xff),11,
char(0xff),7,
char(0xff),7,
char(0xff),3,
char(0xff),3,
188 char(0xff),15,
char(0xff),15,
char(0xff),11,
char(0xff),11,
char(0xff),7,
char(0xff),7,
char(0xff),3,
char(0xff),3);
189 const __m256i constAlphaVector = _mm256_set1_epi16(const_alpha);
190 for (; x < (length - 7); x += 8) {
191 __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
192 if (!_mm256_testz_si256(srcVector, alphaMask)) {
193 BYTE_MUL_AVX2(srcVector, constAlphaVector, colorMask, half);
195 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
196 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
197 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
198 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
199 dstVector = _mm256_add_epi8(dstVector, srcVector);
200 _mm256_store_si256((__m256i *)&dst[x], dstVector);
203 SIMD_EPILOGUE(x, length, 7)
204 blend_pixel(dst[x], src[x], const_alpha);
207void qt_blend_argb32_on_argb32_avx2(uchar *destPixels,
int dbpl,
208 const uchar *srcPixels,
int sbpl,
212 if (const_alpha == 256) {
213 for (
int y = 0; y < h; ++y) {
214 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
215 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
216 BLEND_SOURCE_OVER_ARGB32_AVX2(dst, src, w);
220 }
else if (const_alpha != 0) {
221 const_alpha = (const_alpha * 255) >> 8;
222 for (
int y = 0; y < h; ++y) {
223 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
224 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
225 BLEND_SOURCE_OVER_ARGB32_WITH_CONST_ALPHA_AVX2(dst, src, w, const_alpha);
232void qt_blend_rgb32_on_rgb32_avx2(uchar *destPixels,
int dbpl,
233 const uchar *srcPixels,
int sbpl,
237 if (const_alpha == 256) {
238 for (
int y = 0; y < h; ++y) {
239 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
240 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
241 ::memcpy(dst, src, w *
sizeof(uint));
247 if (const_alpha == 0)
250 const __m256i half = _mm256_set1_epi16(0x80);
251 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
253 const_alpha = (const_alpha * 255) >> 8;
254 int one_minus_const_alpha = 255 - const_alpha;
255 const __m256i constAlphaVector = _mm256_set1_epi16(const_alpha);
256 const __m256i oneMinusConstAlpha = _mm256_set1_epi16(one_minus_const_alpha);
257 for (
int y = 0; y < h; ++y) {
258 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
259 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
263 ALIGNMENT_PROLOGUE_32BYTES(dst, x, w)
264 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], one_minus_const_alpha);
267 for (; x < (w - 7); x += 8) {
268 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
269 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
270 INTERPOLATE_PIXEL_255_AVX2(srcVector, dstVector, constAlphaVector, oneMinusConstAlpha, colorMask, half);
271 _mm256_store_si256((__m256i *)&dst[x], dstVector);
275 SIMD_EPILOGUE(x, w, 7)
276 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], one_minus_const_alpha);
284void Q_DECL_VECTORCALL qt_memfillXX_avx2(uchar *dest, __m256i value256, qsizetype bytes)
286 __m128i value128 = _mm256_castsi256_si128(value256);
289 __m256i *dst256 =
reinterpret_cast<__m256i *>(dest);
290 uchar *end = dest + bytes;
291 while (
reinterpret_cast<uchar *>(dst256 + 4) <= end) {
292 _mm256_storeu_si256(dst256 + 0, value256);
293 _mm256_storeu_si256(dst256 + 1, value256);
294 _mm256_storeu_si256(dst256 + 2, value256);
295 _mm256_storeu_si256(dst256 + 3, value256);
300 bytes = end -
reinterpret_cast<uchar *>(dst256);
301 switch (bytes /
sizeof(value256)) {
302 case 3: _mm256_storeu_si256(dst256++, value256); Q_FALLTHROUGH();
303 case 2: _mm256_storeu_si256(dst256++, value256); Q_FALLTHROUGH();
304 case 1: _mm256_storeu_si256(dst256++, value256);
308 __m128i *dst128 =
reinterpret_cast<__m128i *>(dst256);
309 if (bytes &
sizeof(value128))
310 _mm_storeu_si128(dst128++, value128);
314 _mm_storel_epi64(
reinterpret_cast<__m128i *>(end - 8), value128);
317void qt_memfill64_avx2(quint64 *dest, quint64 value, qsizetype count)
319#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
321 __m128i value64 = _mm_set_epi64x(0, value);
322# ifdef Q_PROCESSOR_X86_64
323 asm (
"" :
"+x" (value64));
325 __m256i value256 = _mm256_broadcastq_epi64(value64);
327 __m256i value256 = _mm256_set1_epi64x(value);
330 qt_memfillXX_avx2(
reinterpret_cast<uchar *>(dest), value256, count *
sizeof(quint64));
333void qt_memfill32_avx2(quint32 *dest, quint32 value, qsizetype count)
340 qt_memfillXX_avx2(
reinterpret_cast<uchar *>(dest), _mm256_set1_epi32(value), count *
sizeof(quint32));
343void QT_FASTCALL comp_func_SourceOver_avx2(uint *destPixels,
const uint *srcPixels,
int length, uint const_alpha)
345 Q_ASSERT(const_alpha < 256);
347 const quint32 *src = (
const quint32 *) srcPixels;
348 quint32 *dst = (quint32 *) destPixels;
350 if (const_alpha == 255)
351 BLEND_SOURCE_OVER_ARGB32_AVX2(dst, src, length);
353 BLEND_SOURCE_OVER_ARGB32_WITH_CONST_ALPHA_AVX2(dst, src, length, const_alpha);
356#if QT_CONFIG(raster_64bit)
357void QT_FASTCALL comp_func_SourceOver_rgb64_avx2(QRgba64 *dst,
const QRgba64 *src,
int length, uint const_alpha)
359 Q_ASSERT(const_alpha < 256);
360 const __m256i half = _mm256_set1_epi32(0x8000);
361 const __m256i one = _mm256_set1_epi32(0xffff);
362 const __m256i colorMask = _mm256_set1_epi32(0x0000ffff);
363 __m256i alphaMask = _mm256_set1_epi32(0xff000000);
364 alphaMask = _mm256_unpacklo_epi8(alphaMask, alphaMask);
365 const __m256i alphaShuffleMask = _mm256_set_epi8(
char(0xff),
char(0xff),15,14,
char(0xff),
char(0xff),15,14,
char(0xff),
char(0xff),7,6,
char(0xff),
char(0xff),7,6,
366 char(0xff),
char(0xff),15,14,
char(0xff),
char(0xff),15,14,
char(0xff),
char(0xff),7,6,
char(0xff),
char(0xff),7,6);
368 if (const_alpha == 255) {
370 for (; x < length && (quintptr(dst + x) & 31); ++x)
371 blend_pixel(dst[x], src[x]);
372 for (; x < length - 3; x += 4) {
373 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
374 if (!_mm256_testz_si256(srcVector, alphaMask)) {
376 if (_mm256_testc_si256(srcVector, alphaMask)) {
378 _mm256_store_si256((__m256i *)&dst[x], srcVector);
380 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
381 alphaChannel = _mm256_sub_epi32(one, alphaChannel);
382 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
383 BYTE_MUL_RGB64_AVX2(dstVector, alphaChannel, colorMask, half);
384 dstVector = _mm256_add_epi16(dstVector, srcVector);
385 _mm256_store_si256((__m256i *)&dst[x], dstVector);
389 SIMD_EPILOGUE(x, length, 3)
390 blend_pixel(dst[x], src[x]);
392 const __m256i constAlphaVector = _mm256_set1_epi32(const_alpha | (const_alpha << 8));
394 for (; x < length && (quintptr(dst + x) & 31); ++x)
395 blend_pixel(dst[x], src[x], const_alpha);
396 for (; x < length - 3; x += 4) {
397 __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
398 if (!_mm256_testz_si256(srcVector, alphaMask)) {
400 BYTE_MUL_RGB64_AVX2(srcVector, constAlphaVector, colorMask, half);
402 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
403 alphaChannel = _mm256_sub_epi32(one, alphaChannel);
404 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
405 BYTE_MUL_RGB64_AVX2(dstVector, alphaChannel, colorMask, half);
406 dstVector = _mm256_add_epi16(dstVector, srcVector);
407 _mm256_store_si256((__m256i *)&dst[x], dstVector);
410 SIMD_EPILOGUE(x, length, 3)
411 blend_pixel(dst[x], src[x], const_alpha);
416#if QT_CONFIG(raster_fp)
417void QT_FASTCALL comp_func_SourceOver_rgbafp_avx2(QRgbaFloat32 *dst,
const QRgbaFloat32 *src,
int length, uint const_alpha)
419 Q_ASSERT(const_alpha < 256);
421 const float a = const_alpha / 255.0f;
422 const __m128 one = _mm_set1_ps(1.0f);
423 const __m128 constAlphaVector = _mm_set1_ps(a);
424 const __m256 one256 = _mm256_set1_ps(1.0f);
425 const __m256 constAlphaVector256 = _mm256_set1_ps(a);
427 for (; x < length - 1; x += 2) {
428 __m256 srcVector = _mm256_loadu_ps((
const float *)&src[x]);
429 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
430 srcVector = _mm256_mul_ps(srcVector, constAlphaVector256);
431 __m256 alphaChannel = _mm256_permute_ps(srcVector, _MM_SHUFFLE(3, 3, 3, 3));
432 alphaChannel = _mm256_sub_ps(one256, alphaChannel);
433 dstVector = _mm256_mul_ps(dstVector, alphaChannel);
434 dstVector = _mm256_add_ps(dstVector, srcVector);
435 _mm256_storeu_ps((
float *)(dst + x), dstVector);
438 __m128 srcVector = _mm_loadu_ps((
const float *)&src[x]);
439 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
440 srcVector = _mm_mul_ps(srcVector, constAlphaVector);
441 __m128 alphaChannel = _mm_permute_ps(srcVector, _MM_SHUFFLE(3, 3, 3, 3));
442 alphaChannel = _mm_sub_ps(one, alphaChannel);
443 dstVector = _mm_mul_ps(dstVector, alphaChannel);
444 dstVector = _mm_add_ps(dstVector, srcVector);
445 _mm_storeu_ps((
float *)(dst + x), dstVector);
450void QT_FASTCALL comp_func_Source_avx2(uint *dst,
const uint *src,
int length, uint const_alpha)
452 if (const_alpha == 255) {
453 ::memcpy(dst, src, length *
sizeof(uint));
455 const int ialpha = 255 - const_alpha;
460 ALIGNMENT_PROLOGUE_32BYTES(dst, x, length)
461 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], ialpha);
464 const __m256i half = _mm256_set1_epi16(0x80);
465 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
466 const __m256i constAlphaVector = _mm256_set1_epi16(const_alpha);
467 const __m256i oneMinusConstAlpha = _mm256_set1_epi16(ialpha);
468 for (; x < length - 7; x += 8) {
469 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
470 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
471 INTERPOLATE_PIXEL_255_AVX2(srcVector, dstVector, constAlphaVector, oneMinusConstAlpha, colorMask, half);
472 _mm256_store_si256((__m256i *)&dst[x], dstVector);
476 SIMD_EPILOGUE(x, length, 7)
477 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], ialpha);
481#if QT_CONFIG(raster_64bit)
482void QT_FASTCALL comp_func_Source_rgb64_avx2(QRgba64 *dst,
const QRgba64 *src,
int length, uint const_alpha)
484 Q_ASSERT(const_alpha < 256);
485 if (const_alpha == 255) {
486 ::memcpy(dst, src, length *
sizeof(QRgba64));
488 const uint ca = const_alpha | (const_alpha << 8);
489 const uint cia = 65535 - ca;
494 for (; x < length && (quintptr(dst + x) & 31); ++x)
495 dst[x] = interpolate65535(src[x], ca, dst[x], cia);
498 const __m256i half = _mm256_set1_epi32(0x8000);
499 const __m256i colorMask = _mm256_set1_epi32(0x0000ffff);
500 const __m256i constAlphaVector = _mm256_set1_epi32(ca);
501 const __m256i oneMinusConstAlpha = _mm256_set1_epi32(cia);
502 for (; x < length - 3; x += 4) {
503 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
504 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
505 INTERPOLATE_PIXEL_RGB64_AVX2(srcVector, dstVector, constAlphaVector, oneMinusConstAlpha, colorMask, half);
506 _mm256_store_si256((__m256i *)&dst[x], dstVector);
510 SIMD_EPILOGUE(x, length, 3)
511 dst[x] = interpolate65535(src[x], ca, dst[x], cia);
516#if QT_CONFIG(raster_fp)
517void QT_FASTCALL comp_func_Source_rgbafp_avx2(QRgbaFloat32 *dst,
const QRgbaFloat32 *src,
int length, uint const_alpha)
519 Q_ASSERT(const_alpha < 256);
520 if (const_alpha == 255) {
521 ::memcpy(dst, src, length *
sizeof(QRgbaFloat32));
523 const float ca = const_alpha / 255.f;
524 const float cia = 1.0f - ca;
526 const __m128 constAlphaVector = _mm_set1_ps(ca);
527 const __m128 oneMinusConstAlpha = _mm_set1_ps(cia);
528 const __m256 constAlphaVector256 = _mm256_set1_ps(ca);
529 const __m256 oneMinusConstAlpha256 = _mm256_set1_ps(cia);
531 for (; x < length - 1; x += 2) {
532 __m256 srcVector = _mm256_loadu_ps((
const float *)&src[x]);
533 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
534 srcVector = _mm256_mul_ps(srcVector, constAlphaVector256);
535 dstVector = _mm256_mul_ps(dstVector, oneMinusConstAlpha256);
536 dstVector = _mm256_add_ps(dstVector, srcVector);
537 _mm256_storeu_ps((
float *)&dst[x], dstVector);
540 __m128 srcVector = _mm_loadu_ps((
const float *)&src[x]);
541 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
542 srcVector = _mm_mul_ps(srcVector, constAlphaVector);
543 dstVector = _mm_mul_ps(dstVector, oneMinusConstAlpha);
544 dstVector = _mm_add_ps(dstVector, srcVector);
545 _mm_storeu_ps((
float *)&dst[x], dstVector);
551void QT_FASTCALL comp_func_solid_SourceOver_avx2(uint *destPixels,
int length, uint color, uint const_alpha)
553 if ((const_alpha & qAlpha(color)) == 255) {
554 qt_memfill32(destPixels, color, length);
556 if (const_alpha != 255)
557 color = BYTE_MUL(color, const_alpha);
559 const quint32 minusAlphaOfColor = qAlpha(~color);
562 quint32 *dst = (quint32 *) destPixels;
563 const __m256i colorVector = _mm256_set1_epi32(color);
564 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
565 const __m256i half = _mm256_set1_epi16(0x80);
566 const __m256i minusAlphaOfColorVector = _mm256_set1_epi16(minusAlphaOfColor);
568 ALIGNMENT_PROLOGUE_32BYTES(dst, x, length)
569 destPixels[x] = color + BYTE_MUL(destPixels[x], minusAlphaOfColor);
571 for (; x < length - 7; x += 8) {
572 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
573 BYTE_MUL_AVX2(dstVector, minusAlphaOfColorVector, colorMask, half);
574 dstVector = _mm256_add_epi8(colorVector, dstVector);
575 _mm256_store_si256((__m256i *)&dst[x], dstVector);
577 SIMD_EPILOGUE(x, length, 7)
578 destPixels[x] = color + BYTE_MUL(destPixels[x], minusAlphaOfColor);
582#if QT_CONFIG(raster_64bit)
583void QT_FASTCALL comp_func_solid_SourceOver_rgb64_avx2(QRgba64 *destPixels,
int length, QRgba64 color, uint const_alpha)
585 Q_ASSERT(const_alpha < 256);
586 if (const_alpha == 255 && color.isOpaque()) {
587 qt_memfill64((quint64*)destPixels, color, length);
589 if (const_alpha != 255)
590 color = multiplyAlpha255(color, const_alpha);
592 const uint minusAlphaOfColor = 65535 - color.alpha();
594 quint64 *dst = (quint64 *) destPixels;
595 const __m256i colorVector = _mm256_set1_epi64x(color);
596 const __m256i colorMask = _mm256_set1_epi32(0x0000ffff);
597 const __m256i half = _mm256_set1_epi32(0x8000);
598 const __m256i minusAlphaOfColorVector = _mm256_set1_epi32(minusAlphaOfColor);
600 for (; x < length && (quintptr(dst + x) & 31); ++x)
601 destPixels[x] = color + multiplyAlpha65535(destPixels[x], minusAlphaOfColor);
603 for (; x < length - 3; x += 4) {
604 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
605 BYTE_MUL_RGB64_AVX2(dstVector, minusAlphaOfColorVector, colorMask, half);
606 dstVector = _mm256_add_epi16(colorVector, dstVector);
607 _mm256_store_si256((__m256i *)&dst[x], dstVector);
609 SIMD_EPILOGUE(x, length, 3)
610 destPixels[x] = color + multiplyAlpha65535(destPixels[x], minusAlphaOfColor);
615#if QT_CONFIG(raster_fp)
616void QT_FASTCALL comp_func_solid_Source_rgbafp_avx2(QRgbaFloat32 *dst,
int length, QRgbaFloat32 color, uint const_alpha)
618 Q_ASSERT(const_alpha < 256);
619 if (const_alpha == 255) {
620 for (
int i = 0; i < length; ++i)
623 const float a = const_alpha / 255.0f;
624 const __m128 alphaVector = _mm_set1_ps(a);
625 const __m128 minusAlphaVector = _mm_set1_ps(1.0f - a);
626 __m128 colorVector = _mm_loadu_ps((
const float *)&color);
627 colorVector = _mm_mul_ps(colorVector, alphaVector);
628 const __m256 colorVector256 = _mm256_insertf128_ps(_mm256_castps128_ps256(colorVector), colorVector, 1);
629 const __m256 minusAlphaVector256 = _mm256_set1_ps(1.0f - a);
631 for (; x < length - 1; x += 2) {
632 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
633 dstVector = _mm256_mul_ps(dstVector, minusAlphaVector256);
634 dstVector = _mm256_add_ps(dstVector, colorVector256);
635 _mm256_storeu_ps((
float *)&dst[x], dstVector);
638 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
639 dstVector = _mm_mul_ps(dstVector, minusAlphaVector);
640 dstVector = _mm_add_ps(dstVector, colorVector);
641 _mm_storeu_ps((
float *)&dst[x], dstVector);
646void QT_FASTCALL comp_func_solid_SourceOver_rgbafp_avx2(QRgbaFloat32 *dst,
int length, QRgbaFloat32 color, uint const_alpha)
648 Q_ASSERT(const_alpha < 256);
649 if (const_alpha == 255 && color.a >= 1.0f) {
650 for (
int i = 0; i < length; ++i)
653 __m128 colorVector = _mm_loadu_ps((
const float *)&color);
654 if (const_alpha != 255)
655 colorVector = _mm_mul_ps(colorVector, _mm_set1_ps(const_alpha / 255.f));
656 __m128 minusAlphaOfColorVector =
657 _mm_sub_ps(_mm_set1_ps(1.0f), _mm_permute_ps(colorVector, _MM_SHUFFLE(3, 3, 3, 3)));
658 const __m256 colorVector256 = _mm256_insertf128_ps(_mm256_castps128_ps256(colorVector), colorVector, 1);
659 const __m256 minusAlphaVector256 = _mm256_insertf128_ps(_mm256_castps128_ps256(minusAlphaOfColorVector),
660 minusAlphaOfColorVector, 1);
662 for (; x < length - 1; x += 2) {
663 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
664 dstVector = _mm256_mul_ps(dstVector, minusAlphaVector256);
665 dstVector = _mm256_add_ps(dstVector, colorVector256);
666 _mm256_storeu_ps((
float *)&dst[x], dstVector);
669 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
670 dstVector = _mm_mul_ps(dstVector, minusAlphaOfColorVector);
671 dstVector = _mm_add_ps(dstVector, colorVector);
672 _mm_storeu_ps((
float *)&dst[x], dstVector);
678#define interpolate_4_pixels_16_avx2(tlr1, tlr2, blr1, blr2, distx, disty, colorMask, v_256, b) \
679{
681 const __m256i vdistx = _mm256_permute4x64_epi64(distx, _MM_SHUFFLE(3
, 1
, 2
, 0
));
682 const __m256i vdisty = _mm256_permute4x64_epi64(disty, _MM_SHUFFLE(3
, 1
, 2
, 0
));
684 __m256i dxdy = _mm256_mullo_epi16 (vdistx, vdisty);
685 const __m256i distx_ = _mm256_slli_epi16(vdistx, 4
);
686 const __m256i disty_ = _mm256_slli_epi16(vdisty, 4
);
687 __m256i idxidy = _mm256_add_epi16(dxdy, _mm256_sub_epi16(v_256, _mm256_add_epi16(distx_, disty_)));
688 __m256i dxidy = _mm256_sub_epi16(distx_, dxdy);
689 __m256i idxdy = _mm256_sub_epi16(disty_, dxdy);
691 __m256i tlr1AG = _mm256_srli_epi16(tlr1, 8
);
692 __m256i tlr1RB = _mm256_and_si256(tlr1, colorMask);
693 __m256i tlr2AG = _mm256_srli_epi16(tlr2, 8
);
694 __m256i tlr2RB = _mm256_and_si256(tlr2, colorMask);
695 __m256i blr1AG = _mm256_srli_epi16(blr1, 8
);
696 __m256i blr1RB = _mm256_and_si256(blr1, colorMask);
697 __m256i blr2AG = _mm256_srli_epi16(blr2, 8
);
698 __m256i blr2RB = _mm256_and_si256(blr2, colorMask);
700 __m256i odxidy1 = _mm256_unpacklo_epi32(idxidy, dxidy);
701 __m256i odxidy2 = _mm256_unpackhi_epi32(idxidy, dxidy);
702 tlr1AG = _mm256_mullo_epi16(tlr1AG, odxidy1);
703 tlr1RB = _mm256_mullo_epi16(tlr1RB, odxidy1);
704 tlr2AG = _mm256_mullo_epi16(tlr2AG, odxidy2);
705 tlr2RB = _mm256_mullo_epi16(tlr2RB, odxidy2);
706 __m256i odxdy1 = _mm256_unpacklo_epi32(idxdy, dxdy);
707 __m256i odxdy2 = _mm256_unpackhi_epi32(idxdy, dxdy);
708 blr1AG = _mm256_mullo_epi16(blr1AG, odxdy1);
709 blr1RB = _mm256_mullo_epi16(blr1RB, odxdy1);
710 blr2AG = _mm256_mullo_epi16(blr2AG, odxdy2);
711 blr2RB = _mm256_mullo_epi16(blr2RB, odxdy2);
714 __m256i topAG = _mm256_hadd_epi32(tlr1AG, tlr2AG);
715 __m256i topRB = _mm256_hadd_epi32(tlr1RB, tlr2RB);
716 __m256i botAG = _mm256_hadd_epi32(blr1AG, blr2AG);
717 __m256i botRB = _mm256_hadd_epi32(blr1RB, blr2RB);
718 __m256i rAG = _mm256_add_epi16(topAG, botAG);
719 __m256i rRB = _mm256_add_epi16(topRB, botRB);
720 rRB = _mm256_srli_epi16(rRB, 8
);
722 rAG = _mm256_permute4x64_epi64(rAG, _MM_SHUFFLE(3
, 1
, 2
, 0
));
723 rRB = _mm256_permute4x64_epi64(rRB, _MM_SHUFFLE(3
, 1
, 2
, 0
));
724 _mm256_storeu_si256((__m256i*)(b), _mm256_blendv_epi8(rAG, rRB, colorMask)); \
725}
727inline void fetchTransformedBilinear_pixelBounds(
int,
int l1,
int l2,
int &v1,
int &v2)
735 Q_ASSERT(v1 >= l1 && v1 <= l2);
736 Q_ASSERT(v2 >= l1 && v2 <= l2);
739void QT_FASTCALL intermediate_adder_avx2(uint *b, uint *end,
const IntermediateBuffer &intermediate,
int offset,
int &fx,
int fdx);
741void QT_FASTCALL fetchTransformedBilinearARGB32PM_simple_scale_helper_avx2(uint *b, uint *end,
const QTextureData &image,
742 int &fx,
int &fy,
int fdx,
int )
746 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
747 const uint *s1 = (
const uint *)image.scanLine(y1);
748 const uint *s2 = (
const uint *)image.scanLine(y2);
750 const int disty = (fy & 0x0000ffff) >> 8;
751 const int idisty = 256 - disty;
752 const int length = end - b;
755 const int adjust = (fdx < 0) ? fdx * length : 0;
756 const int offset = (fx + adjust) >> 16;
759 Q_DECL_UNINITIALIZED IntermediateBuffer intermediate;
761 int count = (qint64(length) * qAbs(fdx) + FixedScale - 1) / FixedScale + 2;
764 Q_ASSERT(count <= BufferSize + 2);
766 int lim = qMin(count, image.x2 - x);
768 Q_ASSERT(x < image.x2);
769 uint t = s1[image.x1];
770 uint b = s2[image.x1];
771 quint32 rb = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
772 quint32 ag = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
774 intermediate.buffer_rb[f] = rb;
775 intermediate.buffer_ag[f] = ag;
778 }
while (x < image.x1 && f < lim);
781 const __m256i disty_ = _mm256_set1_epi16(disty);
782 const __m256i idisty_ = _mm256_set1_epi16(idisty);
783 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
786 for (; f < lim; x += 8, f += 8) {
788 __m256i top = _mm256_loadu_si256((
const __m256i*)((
const uint *)(s1)+x));
789 __m256i topAG = _mm256_srli_epi16(top, 8);
790 __m256i topRB = _mm256_and_si256(top, colorMask);
792 topAG = _mm256_mullo_epi16 (topAG, idisty_);
793 topRB = _mm256_mullo_epi16 (topRB, idisty_);
796 __m256i bottom = _mm256_loadu_si256((
const __m256i*)((
const uint *)(s2)+x));
797 __m256i bottomAG = _mm256_srli_epi16(bottom, 8);
798 __m256i bottomRB = _mm256_and_si256(bottom, colorMask);
799 bottomAG = _mm256_mullo_epi16 (bottomAG, disty_);
800 bottomRB = _mm256_mullo_epi16 (bottomRB, disty_);
803 __m256i rAG =_mm256_add_epi16(topAG, bottomAG);
804 rAG = _mm256_srli_epi16(rAG, 8);
805 _mm256_storeu_si256((__m256i*)(&intermediate.buffer_ag[f]), rAG);
806 __m256i rRB =_mm256_add_epi16(topRB, bottomRB);
807 rRB = _mm256_srli_epi16(rRB, 8);
808 _mm256_storeu_si256((__m256i*)(&intermediate.buffer_rb[f]), rRB);
811 for (; f < count; f++) {
812 x = qMin(x, image.x2 - 1);
817 intermediate.buffer_rb[f] = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
818 intermediate.buffer_ag[f] = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
823 intermediate_adder_avx2(b, end, intermediate, offset, fx, fdx);
826void QT_FASTCALL intermediate_adder_avx2(uint *b, uint *end,
const IntermediateBuffer &intermediate,
int offset,
int &fx,
int fdx)
828 fx -= offset * FixedScale;
830 const __m128i v_fdx = _mm_set1_epi32(fdx * 4);
831 const __m128i v_blend = _mm_set1_epi32(0x00800080);
832 const __m128i vdx_shuffle = _mm_set_epi8(
char(0x80), 13,
char(0x80), 13,
char(0x80), 9,
char(0x80), 9,
833 char(0x80), 5,
char(0x80), 5,
char(0x80), 1,
char(0x80), 1);
834 __m128i v_fx = _mm_setr_epi32(fx, fx + fdx, fx + fdx + fdx, fx + fdx + fdx + fdx);
836 while (b < end - 3) {
837 const __m128i offset = _mm_srli_epi32(v_fx, 16);
838 __m256i vrb = _mm256_i32gather_epi64((
const long long *)intermediate.buffer_rb, offset, 4);
839 __m256i vag = _mm256_i32gather_epi64((
const long long *)intermediate.buffer_ag, offset, 4);
841 __m128i vdx = _mm_shuffle_epi8(v_fx, vdx_shuffle);
842 __m128i vidx = _mm_sub_epi16(_mm_set1_epi16(256), vdx);
843 __m256i vmulx = _mm256_castsi128_si256(_mm_unpacklo_epi32(vidx, vdx));
844 vmulx = _mm256_inserti128_si256(vmulx, _mm_unpackhi_epi32(vidx, vdx), 1);
846 vrb = _mm256_mullo_epi16(vrb, vmulx);
847 vag = _mm256_mullo_epi16(vag, vmulx);
849 __m256i vrbag = _mm256_hadd_epi32(vrb, vag);
850 vrbag = _mm256_permute4x64_epi64(vrbag, _MM_SHUFFLE(3, 1, 2, 0));
852 __m128i rb = _mm256_castsi256_si128(vrbag);
853 __m128i ag = _mm256_extracti128_si256(vrbag, 1);
854 rb = _mm_srli_epi16(rb, 8);
856 _mm_storeu_si128((__m128i*)b, _mm_blendv_epi8(ag, rb, v_blend));
859 v_fx = _mm_add_epi32(v_fx, v_fdx);
861 fx = _mm_cvtsi128_si32(v_fx);
863 const int x = (fx >> 16);
865 const uint distx = (fx & 0x0000ffff) >> 8;
866 const uint idistx = 256 - distx;
867 const uint rb = (intermediate.buffer_rb[x] * idistx + intermediate.buffer_rb[x + 1] * distx) & 0xff00ff00;
868 const uint ag = (intermediate.buffer_ag[x] * idistx + intermediate.buffer_ag[x + 1] * distx) & 0xff00ff00;
873 fx += offset * FixedScale;
876void QT_FASTCALL fetchTransformedBilinearARGB32PM_downscale_helper_avx2(uint *b, uint *end,
const QTextureData &image,
877 int &fx,
int &fy,
int fdx,
int )
881 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
882 const uint *s1 = (
const uint *)image.scanLine(y1);
883 const uint *s2 = (
const uint *)image.scanLine(y2);
884 const int disty8 = (fy & 0x0000ffff) >> 8;
885 const int disty4 = (disty8 + 0x08) >> 4;
887 const qint64 min_fx = qint64(image.x1) * FixedScale;
888 const qint64 max_fx = qint64(image.x2 - 1) * FixedScale;
892 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
897 *b = INTERPOLATE_PIXEL_256(top, 256 - disty8, bot, disty8);
901 uint *boundedEnd = end;
903 boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx);
905 boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx);
908 const __m256i vdistShuffle =
909 _mm256_setr_epi8(0,
char(0x80), 0,
char(0x80), 4,
char(0x80), 4,
char(0x80), 8,
char(0x80), 8,
char(0x80), 12,
char(0x80), 12,
char(0x80),
910 0,
char(0x80), 0,
char(0x80), 4,
char(0x80), 4,
char(0x80), 8,
char(0x80), 8,
char(0x80), 12,
char(0x80), 12,
char(0x80));
911 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
912 const __m256i v_256 = _mm256_set1_epi16(256);
913 const __m256i v_disty = _mm256_set1_epi16(disty4);
914 const __m256i v_fdx = _mm256_set1_epi32(fdx * 8);
915 const __m256i v_fx_r = _mm256_set1_epi32(0x08);
916 const __m256i v_index = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
917 __m256i v_fx = _mm256_set1_epi32(fx);
918 v_fx = _mm256_add_epi32(v_fx, _mm256_mullo_epi32(_mm256_set1_epi32(fdx), v_index));
920 while (b < boundedEnd - 7) {
921 const __m256i offset = _mm256_srli_epi32(v_fx, 16);
922 const __m128i offsetLo = _mm256_castsi256_si128(offset);
923 const __m128i offsetHi = _mm256_extracti128_si256(offset, 1);
924 const __m256i toplo = _mm256_i32gather_epi64((
const long long *)s1, offsetLo, 4);
925 const __m256i tophi = _mm256_i32gather_epi64((
const long long *)s1, offsetHi, 4);
926 const __m256i botlo = _mm256_i32gather_epi64((
const long long *)s2, offsetLo, 4);
927 const __m256i bothi = _mm256_i32gather_epi64((
const long long *)s2, offsetHi, 4);
929 __m256i v_distx = _mm256_srli_epi16(v_fx, 8);
930 v_distx = _mm256_srli_epi16(_mm256_add_epi32(v_distx, v_fx_r), 4);
931 v_distx = _mm256_shuffle_epi8(v_distx, vdistShuffle);
933 interpolate_4_pixels_16_avx2(toplo, tophi, botlo, bothi, v_distx, v_disty, colorMask, v_256, b);
935 v_fx = _mm256_add_epi32(v_fx, v_fdx);
937 fx = _mm_extract_epi32(_mm256_castsi256_si128(v_fx) , 0);
939 while (b < boundedEnd) {
941 int distx8 = (fx & 0x0000ffff) >> 8;
942 *b = interpolate_4_pixels(s1 + x, s2 + x, distx8, disty8);
950 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
955 int distx8 = (fx & 0x0000ffff) >> 8;
956 *b = interpolate_4_pixels(tl, tr, bl, br, distx8, disty8);
962void QT_FASTCALL fetchTransformedBilinearARGB32PM_fast_rotate_helper_avx2(uint *b, uint *end,
const QTextureData &image,
963 int &fx,
int &fy,
int fdx,
int fdy)
965 const qint64 min_fx = qint64(image.x1) * FixedScale;
966 const qint64 max_fx = qint64(image.x2 - 1) * FixedScale;
967 const qint64 min_fy = qint64(image.y1) * FixedScale;
968 const qint64 max_fy = qint64(image.y2 - 1) * FixedScale;
975 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
976 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
977 if (x1 != x2 && y1 != y2)
979 const uint *s1 = (
const uint *)image.scanLine(y1);
980 const uint *s2 = (
const uint *)image.scanLine(y2);
985 int distx = (fx & 0x0000ffff) >> 8;
986 int disty = (fy & 0x0000ffff) >> 8;
987 *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
992 uint *boundedEnd = end;
994 boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx);
996 boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx);
998 boundedEnd = qMin(boundedEnd, b + (max_fy - fy) / fdy);
1000 boundedEnd = qMin(boundedEnd, b + (min_fy - fy) / fdy);
1003 const __m256i vdistShuffle =
1004 _mm256_setr_epi8(0,
char(0x80), 0,
char(0x80), 4,
char(0x80), 4,
char(0x80), 8,
char(0x80), 8,
char(0x80), 12,
char(0x80), 12,
char(0x80),
1005 0,
char(0x80), 0,
char(0x80), 4,
char(0x80), 4,
char(0x80), 8,
char(0x80), 8,
char(0x80), 12,
char(0x80), 12,
char(0x80));
1006 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
1007 const __m256i v_256 = _mm256_set1_epi16(256);
1008 const __m256i v_fdx = _mm256_set1_epi32(fdx * 8);
1009 const __m256i v_fdy = _mm256_set1_epi32(fdy * 8);
1010 const __m256i v_fxy_r = _mm256_set1_epi32(0x08);
1011 const __m256i v_index = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
1012 __m256i v_fx = _mm256_set1_epi32(fx);
1013 __m256i v_fy = _mm256_set1_epi32(fy);
1014 v_fx = _mm256_add_epi32(v_fx, _mm256_mullo_epi32(_mm256_set1_epi32(fdx), v_index));
1015 v_fy = _mm256_add_epi32(v_fy, _mm256_mullo_epi32(_mm256_set1_epi32(fdy), v_index));
1017 const uchar *textureData = image.imageData;
1018 const qsizetype bytesPerLine = image.bytesPerLine;
1019 const __m256i vbpl = _mm256_set1_epi16(bytesPerLine/4);
1021 while (b < boundedEnd - 7) {
1022 const __m256i vy = _mm256_packs_epi32(_mm256_srli_epi32(v_fy, 16), _mm256_setzero_si256());
1024 __m256i offset = _mm256_unpacklo_epi16(_mm256_mullo_epi16(vy, vbpl), _mm256_mulhi_epi16(vy, vbpl));
1025 offset = _mm256_add_epi32(offset, _mm256_srli_epi32(v_fx, 16));
1026 const __m128i offsetLo = _mm256_castsi256_si128(offset);
1027 const __m128i offsetHi = _mm256_extracti128_si256(offset, 1);
1028 const uint *topData = (
const uint *)(textureData);
1029 const uint *botData = (
const uint *)(textureData + bytesPerLine);
1030 const __m256i toplo = _mm256_i32gather_epi64((
const long long *)topData, offsetLo, 4);
1031 const __m256i tophi = _mm256_i32gather_epi64((
const long long *)topData, offsetHi, 4);
1032 const __m256i botlo = _mm256_i32gather_epi64((
const long long *)botData, offsetLo, 4);
1033 const __m256i bothi = _mm256_i32gather_epi64((
const long long *)botData, offsetHi, 4);
1035 __m256i v_distx = _mm256_srli_epi16(v_fx, 8);
1036 __m256i v_disty = _mm256_srli_epi16(v_fy, 8);
1037 v_distx = _mm256_srli_epi16(_mm256_add_epi32(v_distx, v_fxy_r), 4);
1038 v_disty = _mm256_srli_epi16(_mm256_add_epi32(v_disty, v_fxy_r), 4);
1039 v_distx = _mm256_shuffle_epi8(v_distx, vdistShuffle);
1040 v_disty = _mm256_shuffle_epi8(v_disty, vdistShuffle);
1042 interpolate_4_pixels_16_avx2(toplo, tophi, botlo, bothi, v_distx, v_disty, colorMask, v_256, b);
1044 v_fx = _mm256_add_epi32(v_fx, v_fdx);
1045 v_fy = _mm256_add_epi32(v_fy, v_fdy);
1047 fx = _mm_extract_epi32(_mm256_castsi256_si128(v_fx) , 0);
1048 fy = _mm_extract_epi32(_mm256_castsi256_si128(v_fy) , 0);
1050 while (b < boundedEnd) {
1054 const uint *s1 = (
const uint *)image.scanLine(y);
1055 const uint *s2 = (
const uint *)image.scanLine(y + 1);
1057 int distx = (fx & 0x0000ffff) >> 8;
1058 int disty = (fy & 0x0000ffff) >> 8;
1059 *b = interpolate_4_pixels(s1 + x, s2 + x, distx, disty);
1067 int x1 = (fx >> 16);
1069 int y1 = (fy >> 16);
1072 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
1073 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
1075 const uint *s1 = (
const uint *)image.scanLine(y1);
1076 const uint *s2 = (
const uint *)image.scanLine(y2);
1083 int distx = (fx & 0x0000ffff) >> 8;
1084 int disty = (fy & 0x0000ffff) >> 8;
1085 *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
1093static inline __m256i epilogueMaskFromCount(qsizetype count)
1095 Q_ASSERT(count > 0);
1096 static const __m256i offsetMask = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
1097 return _mm256_add_epi32(offsetMask, _mm256_set1_epi32(-count));
1101static void convertARGBToARGB32PM_avx2(uint *buffer,
const uint *src, qsizetype count)
1104 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
1105 const __m256i rgbaMask = _mm256_broadcastsi128_si256(_mm_setr_epi8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15));
1106 const __m256i shuffleMask = _mm256_broadcastsi128_si256(_mm_setr_epi8(6, 7, 6, 7, 6, 7, 6, 7, 14, 15, 14, 15, 14, 15, 14, 15));
1107 const __m256i half = _mm256_set1_epi16(0x0080);
1108 const __m256i zero = _mm256_setzero_si256();
1110 for (; i < count - 7; i += 8) {
1111 __m256i srcVector = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(src + i));
1112 if (!_mm256_testz_si256(srcVector, alphaMask)) {
1114 bool cf = _mm256_testc_si256(srcVector, alphaMask);
1116 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1118 __m256i src1 = _mm256_unpacklo_epi8(srcVector, zero);
1119 __m256i src2 = _mm256_unpackhi_epi8(srcVector, zero);
1120 __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1121 __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1122 src1 = _mm256_mullo_epi16(src1, alpha1);
1123 src2 = _mm256_mullo_epi16(src2, alpha2);
1124 src1 = _mm256_add_epi16(src1, _mm256_srli_epi16(src1, 8));
1125 src2 = _mm256_add_epi16(src2, _mm256_srli_epi16(src2, 8));
1126 src1 = _mm256_add_epi16(src1, half);
1127 src2 = _mm256_add_epi16(src2, half);
1128 src1 = _mm256_srli_epi16(src1, 8);
1129 src2 = _mm256_srli_epi16(src2, 8);
1130 src1 = _mm256_blend_epi16(src1, alpha1, 0x88);
1131 src2 = _mm256_blend_epi16(src2, alpha2, 0x88);
1132 srcVector = _mm256_packus_epi16(src1, src2);
1133 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), srcVector);
1135 if (buffer != src || RGBA)
1136 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), srcVector);
1139 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), zero);
1144 const __m256i epilogueMask = epilogueMaskFromCount(count - i);
1145 __m256i srcVector = _mm256_maskload_epi32(
reinterpret_cast<
const int *>(src + i), epilogueMask);
1146 const __m256i epilogueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, epilogueMask);
1148 if (!_mm256_testz_si256(srcVector, epilogueAlphaMask)) {
1150 bool cf = _mm256_testc_si256(srcVector, epilogueAlphaMask);
1152 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1154 __m256i src1 = _mm256_unpacklo_epi8(srcVector, zero);
1155 __m256i src2 = _mm256_unpackhi_epi8(srcVector, zero);
1156 __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1157 __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1158 src1 = _mm256_mullo_epi16(src1, alpha1);
1159 src2 = _mm256_mullo_epi16(src2, alpha2);
1160 src1 = _mm256_add_epi16(src1, _mm256_srli_epi16(src1, 8));
1161 src2 = _mm256_add_epi16(src2, _mm256_srli_epi16(src2, 8));
1162 src1 = _mm256_add_epi16(src1, half);
1163 src2 = _mm256_add_epi16(src2, half);
1164 src1 = _mm256_srli_epi16(src1, 8);
1165 src2 = _mm256_srli_epi16(src2, 8);
1166 src1 = _mm256_blend_epi16(src1, alpha1, 0x88);
1167 src2 = _mm256_blend_epi16(src2, alpha2, 0x88);
1168 srcVector = _mm256_packus_epi16(src1, src2);
1169 _mm256_maskstore_epi32(
reinterpret_cast<
int *>(buffer + i), epilogueMask, srcVector);
1171 if (buffer != src || RGBA)
1172 _mm256_maskstore_epi32(
reinterpret_cast<
int *>(buffer + i), epilogueMask, srcVector);
1175 _mm256_maskstore_epi32(
reinterpret_cast<
int *>(buffer + i), epilogueMask, zero);
1180void QT_FASTCALL convertARGB32ToARGB32PM_avx2(uint *buffer,
int count,
const QList<QRgb> *)
1182 convertARGBToARGB32PM_avx2<
false>(buffer, buffer, count);
1185void QT_FASTCALL convertRGBA8888ToARGB32PM_avx2(uint *buffer,
int count,
const QList<QRgb> *)
1187 convertARGBToARGB32PM_avx2<
true>(buffer, buffer, count);
1190const uint *QT_FASTCALL fetchARGB32ToARGB32PM_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1191 const QList<QRgb> *, QDitherInfo *)
1193 convertARGBToARGB32PM_avx2<
false>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1197const uint *QT_FASTCALL fetchRGBA8888ToARGB32PM_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1198 const QList<QRgb> *, QDitherInfo *)
1200 convertARGBToARGB32PM_avx2<
true>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1205static void convertARGBToRGBA64PM_avx2(QRgba64 *buffer,
const uint *src, qsizetype count)
1208 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
1209 const __m256i rgbaMask = _mm256_broadcastsi128_si256(_mm_setr_epi8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15));
1210 const __m256i shuffleMask = _mm256_broadcastsi128_si256(_mm_setr_epi8(6, 7, 6, 7, 6, 7, 6, 7, 14, 15, 14, 15, 14, 15, 14, 15));
1211 const __m256i zero = _mm256_setzero_si256();
1213 for (; i < count - 7; i += 8) {
1215 __m256i srcVector = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(src + i));
1216 if (!_mm256_testz_si256(srcVector, alphaMask)) {
1218 bool cf = _mm256_testc_si256(srcVector, alphaMask);
1220 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1228 srcVector = _mm256_permute4x64_epi64(srcVector, _MM_SHUFFLE(3, 1, 2, 0));
1230 const __m256i src1 = _mm256_unpacklo_epi8(srcVector, srcVector);
1231 const __m256i src2 = _mm256_unpackhi_epi8(srcVector, srcVector);
1233 const __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1234 const __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1235 dst1 = _mm256_mulhi_epu16(src1, alpha1);
1236 dst2 = _mm256_mulhi_epu16(src2, alpha2);
1237 dst1 = _mm256_add_epi16(dst1, _mm256_srli_epi16(dst1, 15));
1238 dst2 = _mm256_add_epi16(dst2, _mm256_srli_epi16(dst2, 15));
1239 dst1 = _mm256_blend_epi16(dst1, src1, 0x88);
1240 dst2 = _mm256_blend_epi16(dst2, src2, 0x88);
1248 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), dst1);
1249 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i) + 1, dst2);
1253 __m256i epilogueMask = epilogueMaskFromCount(count - i);
1254 const __m256i epilogueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, epilogueMask);
1256 __m256i srcVector = _mm256_maskload_epi32(
reinterpret_cast<
const int *>(src + i), epilogueMask);
1258 if (!_mm256_testz_si256(srcVector, epilogueAlphaMask)) {
1260 bool cf = _mm256_testc_si256(srcVector, epilogueAlphaMask);
1262 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1263 srcVector = _mm256_permute4x64_epi64(srcVector, _MM_SHUFFLE(3, 1, 2, 0));
1264 const __m256i src1 = _mm256_unpacklo_epi8(srcVector, srcVector);
1265 const __m256i src2 = _mm256_unpackhi_epi8(srcVector, srcVector);
1267 const __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1268 const __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1269 dst1 = _mm256_mulhi_epu16(src1, alpha1);
1270 dst2 = _mm256_mulhi_epu16(src2, alpha2);
1271 dst1 = _mm256_add_epi16(dst1, _mm256_srli_epi16(dst1, 15));
1272 dst2 = _mm256_add_epi16(dst2, _mm256_srli_epi16(dst2, 15));
1273 dst1 = _mm256_blend_epi16(dst1, src1, 0x88);
1274 dst2 = _mm256_blend_epi16(dst2, src2, 0x88);
1282 epilogueMask = _mm256_permute4x64_epi64(epilogueMask, _MM_SHUFFLE(3, 1, 2, 0));
1283 _mm256_maskstore_epi64(
reinterpret_cast<qint64 *>(buffer + i),
1284 _mm256_unpacklo_epi32(epilogueMask, epilogueMask),
1286 _mm256_maskstore_epi64(
reinterpret_cast<qint64 *>(buffer + i + 4),
1287 _mm256_unpackhi_epi32(epilogueMask, epilogueMask),
1292const QRgba64 * QT_FASTCALL convertARGB32ToRGBA64PM_avx2(QRgba64 *buffer,
const uint *src,
int count,
1293 const QList<QRgb> *, QDitherInfo *)
1295 convertARGBToRGBA64PM_avx2<
false>(buffer, src, count);
1299const QRgba64 * QT_FASTCALL convertRGBA8888ToRGBA64PM_avx2(QRgba64 *buffer,
const uint *src,
int count,
1300 const QList<QRgb> *, QDitherInfo *)
1302 convertARGBToRGBA64PM_avx2<
true>(buffer, src, count);
1306const QRgba64 *QT_FASTCALL fetchARGB32ToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1307 const QList<QRgb> *, QDitherInfo *)
1309 convertARGBToRGBA64PM_avx2<
false>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1313const QRgba64 *QT_FASTCALL fetchRGBA8888ToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1314 const QList<QRgb> *, QDitherInfo *)
1316 convertARGBToRGBA64PM_avx2<
true>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1320const QRgba64 *QT_FASTCALL fetchRGBA64ToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1321 const QList<QRgb> *, QDitherInfo *)
1323 const QRgba64 *s =
reinterpret_cast<
const QRgba64 *>(src) + index;
1325 const __m256i vh = _mm256_set1_epi32(0x8000);
1326 for (; i < count - 3; i += 4) {
1327 __m256i vs256 = _mm256_loadu_si256((
const __m256i *)(s + i));
1328 __m256i va256 = _mm256_shufflelo_epi16(vs256, _MM_SHUFFLE(3, 3, 3, 3));
1329 va256 = _mm256_shufflehi_epi16(va256, _MM_SHUFFLE(3, 3, 3, 3));
1330 const __m256i vmullo = _mm256_mullo_epi16(vs256, va256);
1331 const __m256i vmulhi = _mm256_mulhi_epu16(vs256, va256);
1332 __m256i vslo = _mm256_unpacklo_epi16(vmullo, vmulhi);
1333 __m256i vshi = _mm256_unpackhi_epi16(vmullo, vmulhi);
1334 vslo = _mm256_add_epi32(vslo, _mm256_srli_epi32(vslo, 16));
1335 vshi = _mm256_add_epi32(vshi, _mm256_srli_epi32(vshi, 16));
1336 vslo = _mm256_add_epi32(vslo, vh);
1337 vshi = _mm256_add_epi32(vshi, vh);
1338 vslo = _mm256_srli_epi32(vslo, 16);
1339 vshi = _mm256_srli_epi32(vshi, 16);
1340 vs256 = _mm256_packus_epi32(vslo, vshi);
1341 vs256 = _mm256_blend_epi16(vs256, va256, 0x88);
1342 _mm256_storeu_si256((__m256i *)(buffer + i), vs256);
1344 for (; i < count; ++i) {
1345 const auto a = s[i].alpha();
1346 __m128i vs = _mm_loadl_epi64((
const __m128i *)(s + i));
1347 __m128i va = _mm_shufflelo_epi16(vs, _MM_SHUFFLE(3, 3, 3, 3));
1348 vs = multiplyAlpha65535(vs, va);
1349 _mm_storel_epi64((__m128i *)(buffer + i), vs);
1350 buffer[i].setAlpha(a);
1355const uint *QT_FASTCALL fetchRGB16FToRGB32_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1356 const QList<QRgb> *, QDitherInfo *)
1358 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1359 const __m256 vf = _mm256_set1_ps(255.0f);
1360 const __m256 vh = _mm256_set1_ps(0.5f);
1362 for (; i + 1 < count; i += 2) {
1363 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1364 vsf = _mm256_mul_ps(vsf, vf);
1365 vsf = _mm256_add_ps(vsf, vh);
1366 __m256i vsi = _mm256_cvttps_epi32(vsf);
1367 vsi = _mm256_packs_epi32(vsi, vsi);
1368 vsi = _mm256_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1369 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1370 __m128i vsi128 = _mm256_castsi256_si128(vsi);
1371 vsi128 = _mm_packus_epi16(vsi128, vsi128);
1372 _mm_storel_epi64((__m128i *)(buffer + i), vsi128);
1375 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1376 vsf = _mm_mul_ps(vsf, _mm_set1_ps(255.0f));
1377 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1378 __m128i vsi = _mm_cvttps_epi32(vsf);
1379 vsi = _mm_packs_epi32(vsi, vsi);
1380 vsi = _mm_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1381 vsi = _mm_packus_epi16(vsi, vsi);
1382 buffer[i] = _mm_cvtsi128_si32(vsi);
1387const uint *QT_FASTCALL fetchRGBA16FToARGB32PM_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1388 const QList<QRgb> *, QDitherInfo *)
1390 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1391 const __m256 vf = _mm256_set1_ps(255.0f);
1392 const __m256 vh = _mm256_set1_ps(0.5f);
1394 for (; i + 1 < count; i += 2) {
1395 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1396 __m256 vsa = _mm256_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1397 vsf = _mm256_mul_ps(vsf, vsa);
1398 vsf = _mm256_blend_ps(vsf, vsa, 0x88);
1399 vsf = _mm256_mul_ps(vsf, vf);
1400 vsf = _mm256_add_ps(vsf, vh);
1401 __m256i vsi = _mm256_cvttps_epi32(vsf);
1402 vsi = _mm256_packus_epi32(vsi, vsi);
1403 vsi = _mm256_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1404 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1405 __m128i vsi128 = _mm256_castsi256_si128(vsi);
1406 vsi128 = _mm_packus_epi16(vsi128, vsi128);
1407 _mm_storel_epi64((__m128i *)(buffer + i), vsi128);
1410 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1411 __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1412 vsf = _mm_mul_ps(vsf, vsa);
1413 vsf = _mm_insert_ps(vsf, vsa, 0x30);
1414 vsf = _mm_mul_ps(vsf, _mm_set1_ps(255.0f));
1415 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1416 __m128i vsi = _mm_cvttps_epi32(vsf);
1417 vsi = _mm_packus_epi32(vsi, vsi);
1418 vsi = _mm_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1419 vsi = _mm_packus_epi16(vsi, vsi);
1420 buffer[i] = _mm_cvtsi128_si32(vsi);
1425const QRgba64 *QT_FASTCALL fetchRGBA16FPMToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1426 const QList<QRgb> *, QDitherInfo *)
1428 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1429 const __m256 vf = _mm256_set1_ps(65535.0f);
1430 const __m256 vh = _mm256_set1_ps(0.5f);
1432 for (; i + 1 < count; i += 2) {
1433 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1434 vsf = _mm256_mul_ps(vsf, vf);
1435 vsf = _mm256_add_ps(vsf, vh);
1436 __m256i vsi = _mm256_cvttps_epi32(vsf);
1437 vsi = _mm256_packus_epi32(vsi, vsi);
1438 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1439 _mm_storeu_si128((__m128i *)(buffer + i), _mm256_castsi256_si128(vsi));
1442 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1443 vsf = _mm_mul_ps(vsf, _mm_set1_ps(65535.0f));
1444 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1445 __m128i vsi = _mm_cvttps_epi32(vsf);
1446 vsi = _mm_packus_epi32(vsi, vsi);
1447 _mm_storel_epi64((__m128i *)(buffer + i), vsi);
1452const QRgba64 *QT_FASTCALL fetchRGBA16FToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1453 const QList<QRgb> *, QDitherInfo *)
1455 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1456 const __m256 vf = _mm256_set1_ps(65535.0f);
1457 const __m256 vh = _mm256_set1_ps(0.5f);
1459 for (; i + 1 < count; i += 2) {
1460 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1461 __m256 vsa = _mm256_shuffle_ps(vsf, vsf, _MM_SHUFFLE(3, 3, 3, 3));
1462 vsf = _mm256_mul_ps(vsf, vsa);
1463 vsf = _mm256_blend_ps(vsf, vsa, 0x88);
1464 vsf = _mm256_mul_ps(vsf, vf);
1465 vsf = _mm256_add_ps(vsf, vh);
1466 __m256i vsi = _mm256_cvttps_epi32(vsf);
1467 vsi = _mm256_packus_epi32(vsi, vsi);
1468 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1469 _mm_storeu_si128((__m128i *)(buffer + i), _mm256_castsi256_si128(vsi));
1472 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1473 __m128 vsa = _mm_shuffle_ps(vsf, vsf, _MM_SHUFFLE(3, 3, 3, 3));
1474 vsf = _mm_mul_ps(vsf, vsa);
1475 vsf = _mm_insert_ps(vsf, vsa, 0x30);
1476 vsf = _mm_mul_ps(vsf, _mm_set1_ps(65535.0f));
1477 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1478 __m128i vsi = _mm_cvttps_epi32(vsf);
1479 vsi = _mm_packus_epi32(vsi, vsi);
1480 _mm_storel_epi64((__m128i *)(buffer + i), vsi);
1485void QT_FASTCALL storeRGB16FFromRGB32_avx2(uchar *dest,
const uint *src,
int index,
int count,
1486 const QList<QRgb> *, QDitherInfo *)
1488 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1489 const __m256 vf = _mm256_set1_ps(1.0f / 255.0f);
1491 for (; i + 1 < count; i += 2) {
1492 __m256i vsi = _mm256_cvtepu8_epi32(_mm_loadl_epi64((
const __m128i *)(src + i)));
1493 vsi = _mm256_shuffle_epi32(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1494 __m256 vsf = _mm256_cvtepi32_ps(vsi);
1495 vsf = _mm256_mul_ps(vsf, vf);
1496 _mm_storeu_si128((__m128i *)(d + i), _mm256_cvtps_ph(vsf, 0));
1499 __m128i vsi = _mm_cvtsi32_si128(src[i]);
1500 vsi = _mm_cvtepu8_epi32(vsi);
1501 vsi = _mm_shuffle_epi32(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1502 __m128 vsf = _mm_cvtepi32_ps(vsi);
1503 vsf = _mm_mul_ps(vsf, _mm_set1_ps(1.0f / 255.0f));
1504 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));
1508void QT_FASTCALL storeRGBA16FFromARGB32PM_avx2(uchar *dest,
const uint *src,
int index,
int count,
1509 const QList<QRgb> *, QDitherInfo *)
1511 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1512 const __m128 vf = _mm_set1_ps(1.0f / 255.0f);
1513 for (
int i = 0; i < count; ++i) {
1514 const uint s = src[i];
1515 __m128i vsi = _mm_cvtsi32_si128(s);
1516 vsi = _mm_cvtepu8_epi32(vsi);
1517 vsi = _mm_shuffle_epi32(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1518 __m128 vsf = _mm_cvtepi32_ps(vsi);
1519 const uint8_t a = (s >> 24);
1521 vsf = _mm_mul_ps(vsf, vf);
1523 vsf = _mm_set1_ps(0.0f);
1525 const __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1526 __m128 vsr = _mm_rcp_ps(vsa);
1527 vsr = _mm_sub_ps(_mm_add_ps(vsr, vsr), _mm_mul_ps(vsr, _mm_mul_ps(vsr, vsa)));
1528 vsr = _mm_insert_ps(vsr, _mm_set_ss(1.0f), 0x30);
1529 vsf = _mm_mul_ps(vsf, vsr);
1531 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));
1535#if QT_CONFIG(raster_fp)
1536const QRgbaFloat32 *QT_FASTCALL fetchRGBA16FToRGBA32F_avx2(QRgbaFloat32 *buffer,
const uchar *src,
int index,
int count,
1537 const QList<QRgb> *, QDitherInfo *)
1539 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1541 for (; i + 1 < count; i += 2) {
1542 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1543 __m256 vsa = _mm256_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1544 vsf = _mm256_mul_ps(vsf, vsa);
1545 vsf = _mm256_blend_ps(vsf, vsa, 0x88);
1546 _mm256_storeu_ps((
float *)(buffer + i), vsf);
1549 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1550 __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1551 vsf = _mm_mul_ps(vsf, vsa);
1552 vsf = _mm_insert_ps(vsf, vsa, 0x30);
1553 _mm_storeu_ps((
float *)(buffer + i), vsf);
1558void QT_FASTCALL storeRGBX16FFromRGBA32F_avx2(uchar *dest,
const QRgbaFloat32 *src,
int index,
int count,
1559 const QList<QRgb> *, QDitherInfo *)
1561 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1562 const __m128 *s =
reinterpret_cast<
const __m128 *>(src);
1563 const __m128 zero = _mm_set_ps(1.0f, 0.0f, 0.0f, 0.0f);
1564 for (
int i = 0; i < count; ++i) {
1565 __m128 vsf = _mm_loadu_ps(
reinterpret_cast<
const float *>(s + i));
1566 const __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1567 const float a = _mm_cvtss_f32(vsa);
1573 __m128 vsr = _mm_rcp_ps(vsa);
1574 vsr = _mm_sub_ps(_mm_add_ps(vsr, vsr), _mm_mul_ps(vsr, _mm_mul_ps(vsr, vsa)));
1575 vsf = _mm_mul_ps(vsf, vsr);
1576 vsf = _mm_insert_ps(vsf, _mm_set_ss(1.0f), 0x30);
1578 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));
1582void QT_FASTCALL storeRGBA16FFromRGBA32F_avx2(uchar *dest,
const QRgbaFloat32 *src,
int index,
int count,
1583 const QList<QRgb> *, QDitherInfo *)
1585 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1586 const __m128 *s =
reinterpret_cast<
const __m128 *>(src);
1587 const __m128 zero = _mm_set1_ps(0.0f);
1588 for (
int i = 0; i < count; ++i) {
1589 __m128 vsf = _mm_loadu_ps(
reinterpret_cast<
const float *>(s + i));
1590 const __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1591 const float a = _mm_cvtss_f32(vsa);
1597 __m128 vsr = _mm_rcp_ps(vsa);
1598 vsr = _mm_sub_ps(_mm_add_ps(vsr, vsr), _mm_mul_ps(vsr, _mm_mul_ps(vsr, vsa)));
1599 vsr = _mm_insert_ps(vsr, _mm_set_ss(1.0f), 0x30);
1600 vsf = _mm_mul_ps(vsf, vsr);
1602 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));