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);
41#if QT_CONFIG(raster_64bit)
42inline static void Q_DECL_VECTORCALL
43BYTE_MUL_RGB64_AVX2(__m256i &pixelVector, __m256i alphaChannel, __m256i colorMask, __m256i half)
45 __m256i pixelVectorAG = _mm256_srli_epi32(pixelVector, 16);
46 __m256i pixelVectorRB = _mm256_and_si256(pixelVector, colorMask);
48 pixelVectorAG = _mm256_mullo_epi32(pixelVectorAG, alphaChannel);
49 pixelVectorRB = _mm256_mullo_epi32(pixelVectorRB, alphaChannel);
51 pixelVectorRB = _mm256_add_epi32(pixelVectorRB, _mm256_srli_epi32(pixelVectorRB, 16));
52 pixelVectorAG = _mm256_add_epi32(pixelVectorAG, _mm256_srli_epi32(pixelVectorAG, 16));
53 pixelVectorRB = _mm256_add_epi32(pixelVectorRB, half);
54 pixelVectorAG = _mm256_add_epi32(pixelVectorAG, half);
56 pixelVectorRB = _mm256_srli_epi32(pixelVectorRB, 16);
57 pixelVector = _mm256_blendv_epi8(pixelVectorAG, pixelVectorRB, colorMask);
62inline static void Q_DECL_VECTORCALL
63INTERPOLATE_PIXEL_255_AVX2(__m256i srcVector, __m256i &dstVector, __m256i alphaChannel, __m256i oneMinusAlphaChannel, __m256i colorMask, __m256i half)
65 const __m256i srcVectorAG = _mm256_srli_epi16(srcVector, 8);
66 const __m256i dstVectorAG = _mm256_srli_epi16(dstVector, 8);
67 const __m256i srcVectorRB = _mm256_and_si256(srcVector, colorMask);
68 const __m256i dstVectorRB = _mm256_and_si256(dstVector, colorMask);
69 const __m256i srcVectorAGalpha = _mm256_mullo_epi16(srcVectorAG, alphaChannel);
70 const __m256i srcVectorRBalpha = _mm256_mullo_epi16(srcVectorRB, alphaChannel);
71 const __m256i dstVectorAGoneMinusAlpha = _mm256_mullo_epi16(dstVectorAG, oneMinusAlphaChannel);
72 const __m256i dstVectorRBoneMinusAlpha = _mm256_mullo_epi16(dstVectorRB, oneMinusAlphaChannel);
73 __m256i finalAG = _mm256_add_epi16(srcVectorAGalpha, dstVectorAGoneMinusAlpha);
74 __m256i finalRB = _mm256_add_epi16(srcVectorRBalpha, dstVectorRBoneMinusAlpha);
75 finalAG = _mm256_add_epi16(finalAG, _mm256_srli_epi16(finalAG, 8));
76 finalRB = _mm256_add_epi16(finalRB, _mm256_srli_epi16(finalRB, 8));
77 finalAG = _mm256_add_epi16(finalAG, half);
78 finalRB = _mm256_add_epi16(finalRB, half);
79 finalRB = _mm256_srli_epi16(finalRB, 8);
81 dstVector = _mm256_blendv_epi8(finalAG, finalRB, colorMask);
84#if QT_CONFIG(raster_64bit)
85inline static void Q_DECL_VECTORCALL
86INTERPOLATE_PIXEL_RGB64_AVX2(__m256i srcVector, __m256i &dstVector, __m256i alphaChannel, __m256i oneMinusAlphaChannel, __m256i colorMask, __m256i half)
88 const __m256i srcVectorAG = _mm256_srli_epi32(srcVector, 16);
89 const __m256i dstVectorAG = _mm256_srli_epi32(dstVector, 16);
90 const __m256i srcVectorRB = _mm256_and_si256(srcVector, colorMask);
91 const __m256i dstVectorRB = _mm256_and_si256(dstVector, colorMask);
92 const __m256i srcVectorAGalpha = _mm256_mullo_epi32(srcVectorAG, alphaChannel);
93 const __m256i srcVectorRBalpha = _mm256_mullo_epi32(srcVectorRB, alphaChannel);
94 const __m256i dstVectorAGoneMinusAlpha = _mm256_mullo_epi32(dstVectorAG, oneMinusAlphaChannel);
95 const __m256i dstVectorRBoneMinusAlpha = _mm256_mullo_epi32(dstVectorRB, oneMinusAlphaChannel);
96 __m256i finalAG = _mm256_add_epi32(srcVectorAGalpha, dstVectorAGoneMinusAlpha);
97 __m256i finalRB = _mm256_add_epi32(srcVectorRBalpha, dstVectorRBoneMinusAlpha);
98 finalAG = _mm256_add_epi32(finalAG, _mm256_srli_epi32(finalAG, 16));
99 finalRB = _mm256_add_epi32(finalRB, _mm256_srli_epi32(finalRB, 16));
100 finalAG = _mm256_add_epi32(finalAG, half);
101 finalRB = _mm256_add_epi32(finalRB, half);
102 finalRB = _mm256_srli_epi32(finalRB, 16);
103 dstVector = _mm256_blendv_epi8(finalAG, finalRB, colorMask);
108inline static void Q_DECL_VECTORCALL BLEND_SOURCE_OVER_ARGB32_AVX2(quint32 *dst,
const quint32 *src,
const int length)
110 const __m256i half = _mm256_set1_epi16(0x80);
111 const __m256i one = _mm256_set1_epi16(0xff);
112 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
113 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
114 const __m256i offsetMask = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
115 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,
116 char(0xff),15,
char(0xff),15,
char(0xff),11,
char(0xff),11,
char(0xff),7,
char(0xff),7,
char(0xff),3,
char(0xff),3);
118 const int minusOffsetToAlignDstOn32Bytes = (
reinterpret_cast<quintptr>(dst) >> 2) & 0x7;
122 if (minusOffsetToAlignDstOn32Bytes != 0 && x < (length - 7)) {
123 const __m256i prologueMask = _mm256_sub_epi32(_mm256_set1_epi32(minusOffsetToAlignDstOn32Bytes - 1), offsetMask);
124 const __m256i srcVector = _mm256_maskload_epi32((
const int *)&src[x - minusOffsetToAlignDstOn32Bytes], prologueMask);
125 const __m256i prologueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, prologueMask);
126 if (!_mm256_testz_si256(srcVector, prologueAlphaMask)) {
127 if (_mm256_testc_si256(srcVector, prologueAlphaMask)) {
128 _mm256_maskstore_epi32((
int *)&dst[x - minusOffsetToAlignDstOn32Bytes], prologueMask, srcVector);
130 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
131 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
132 __m256i dstVector = _mm256_maskload_epi32((
int *)&dst[x - minusOffsetToAlignDstOn32Bytes], prologueMask);
133 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
134 dstVector = _mm256_add_epi8(dstVector, srcVector);
135 _mm256_maskstore_epi32((
int *)&dst[x - minusOffsetToAlignDstOn32Bytes], prologueMask, dstVector);
138 x += (8 - minusOffsetToAlignDstOn32Bytes);
141 for (; x < (length - 7); x += 8) {
142 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
143 if (!_mm256_testz_si256(srcVector, alphaMask)) {
144 if (_mm256_testc_si256(srcVector, alphaMask)) {
145 _mm256_store_si256((__m256i *)&dst[x], srcVector);
147 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
148 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
149 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
150 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
151 dstVector = _mm256_add_epi8(dstVector, srcVector);
152 _mm256_store_si256((__m256i *)&dst[x], dstVector);
159 const __m256i epilogueMask = _mm256_add_epi32(offsetMask, _mm256_set1_epi32(x - length));
160 const __m256i srcVector = _mm256_maskload_epi32((
const int *)&src[x], epilogueMask);
161 const __m256i epilogueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, epilogueMask);
162 if (!_mm256_testz_si256(srcVector, epilogueAlphaMask)) {
163 if (_mm256_testc_si256(srcVector, epilogueAlphaMask)) {
164 _mm256_maskstore_epi32((
int *)&dst[x], epilogueMask, srcVector);
166 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
167 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
168 __m256i dstVector = _mm256_maskload_epi32((
int *)&dst[x], epilogueMask);
169 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
170 dstVector = _mm256_add_epi8(dstVector, srcVector);
171 _mm256_maskstore_epi32((
int *)&dst[x], epilogueMask, dstVector);
179inline static void Q_DECL_VECTORCALL
180BLEND_SOURCE_OVER_ARGB32_WITH_CONST_ALPHA_AVX2(quint32 *dst,
const quint32 *src,
const int length,
const int const_alpha)
184 ALIGNMENT_PROLOGUE_32BYTES(dst, x, length)
185 blend_pixel(dst[x], src[x], const_alpha);
187 const __m256i half = _mm256_set1_epi16(0x80);
188 const __m256i one = _mm256_set1_epi16(0xff);
189 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
190 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
191 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,
192 char(0xff),15,
char(0xff),15,
char(0xff),11,
char(0xff),11,
char(0xff),7,
char(0xff),7,
char(0xff),3,
char(0xff),3);
193 const __m256i constAlphaVector = _mm256_set1_epi16(const_alpha);
194 for (; x < (length - 7); x += 8) {
195 __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
196 if (!_mm256_testz_si256(srcVector, alphaMask)) {
197 BYTE_MUL_AVX2(srcVector, constAlphaVector, colorMask, half);
199 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
200 alphaChannel = _mm256_sub_epi16(one, alphaChannel);
201 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
202 BYTE_MUL_AVX2(dstVector, alphaChannel, colorMask, half);
203 dstVector = _mm256_add_epi8(dstVector, srcVector);
204 _mm256_store_si256((__m256i *)&dst[x], dstVector);
207 SIMD_EPILOGUE(x, length, 7)
208 blend_pixel(dst[x], src[x], const_alpha);
211void qt_blend_argb32_on_argb32_avx2(uchar *destPixels,
int dbpl,
212 const uchar *srcPixels,
int sbpl,
216 if (const_alpha == 256) {
217 for (
int y = 0; y < h; ++y) {
218 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
219 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
220 BLEND_SOURCE_OVER_ARGB32_AVX2(dst, src, w);
224 }
else if (const_alpha != 0) {
225 const_alpha = (const_alpha * 255) >> 8;
226 for (
int y = 0; y < h; ++y) {
227 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
228 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
229 BLEND_SOURCE_OVER_ARGB32_WITH_CONST_ALPHA_AVX2(dst, src, w, const_alpha);
236void qt_blend_rgb32_on_rgb32_avx2(uchar *destPixels,
int dbpl,
237 const uchar *srcPixels,
int sbpl,
241 if (const_alpha == 256) {
242 for (
int y = 0; y < h; ++y) {
243 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
244 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
245 ::memcpy(dst, src, w *
sizeof(uint));
251 if (const_alpha == 0)
254 const __m256i half = _mm256_set1_epi16(0x80);
255 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
257 const_alpha = (const_alpha * 255) >> 8;
258 int one_minus_const_alpha = 255 - const_alpha;
259 const __m256i constAlphaVector = _mm256_set1_epi16(const_alpha);
260 const __m256i oneMinusConstAlpha = _mm256_set1_epi16(one_minus_const_alpha);
261 for (
int y = 0; y < h; ++y) {
262 const quint32 *src =
reinterpret_cast<
const quint32 *>(srcPixels);
263 quint32 *dst =
reinterpret_cast<quint32 *>(destPixels);
267 ALIGNMENT_PROLOGUE_32BYTES(dst, x, w)
268 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], one_minus_const_alpha);
271 for (; x < (w - 7); x += 8) {
272 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
273 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
274 INTERPOLATE_PIXEL_255_AVX2(srcVector, dstVector, constAlphaVector, oneMinusConstAlpha, colorMask, half);
275 _mm256_store_si256((__m256i *)&dst[x], dstVector);
279 SIMD_EPILOGUE(x, w, 7)
280 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], one_minus_const_alpha);
288void Q_DECL_VECTORCALL qt_memfillXX_avx2(uchar *dest, __m256i value256, qsizetype bytes)
290 __m128i value128 = _mm256_castsi256_si128(value256);
293 __m256i *dst256 =
reinterpret_cast<__m256i *>(dest);
294 uchar *end = dest + bytes;
295 while (
reinterpret_cast<uchar *>(dst256 + 4) <= end) {
296 _mm256_storeu_si256(dst256 + 0, value256);
297 _mm256_storeu_si256(dst256 + 1, value256);
298 _mm256_storeu_si256(dst256 + 2, value256);
299 _mm256_storeu_si256(dst256 + 3, value256);
304 bytes = end -
reinterpret_cast<uchar *>(dst256);
305 switch (bytes /
sizeof(value256)) {
306 case 3: _mm256_storeu_si256(dst256++, value256); Q_FALLTHROUGH();
307 case 2: _mm256_storeu_si256(dst256++, value256); Q_FALLTHROUGH();
308 case 1: _mm256_storeu_si256(dst256++, value256);
312 __m128i *dst128 =
reinterpret_cast<__m128i *>(dst256);
313 if (bytes &
sizeof(value128))
314 _mm_storeu_si128(dst128++, value128);
318 _mm_storel_epi64(
reinterpret_cast<__m128i *>(end - 8), value128);
321void qt_memfill64_avx2(quint64 *dest, quint64 value, qsizetype count)
323#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG)
325 __m128i value64 = _mm_set_epi64x(0, value);
326# ifdef Q_PROCESSOR_X86_64
327 asm (
"" :
"+x" (value64));
329 __m256i value256 = _mm256_broadcastq_epi64(value64);
331 __m256i value256 = _mm256_set1_epi64x(value);
334 qt_memfillXX_avx2(
reinterpret_cast<uchar *>(dest), value256, count *
sizeof(quint64));
337void qt_memfill32_avx2(quint32 *dest, quint32 value, qsizetype count)
344 qt_memfillXX_avx2(
reinterpret_cast<uchar *>(dest), _mm256_set1_epi32(value), count *
sizeof(quint32));
347void QT_FASTCALL comp_func_SourceOver_avx2(uint *destPixels,
const uint *srcPixels,
int length, uint const_alpha)
349 Q_ASSERT(const_alpha < 256);
351 const quint32 *src = (
const quint32 *) srcPixels;
352 quint32 *dst = (quint32 *) destPixels;
354 if (const_alpha == 255)
355 BLEND_SOURCE_OVER_ARGB32_AVX2(dst, src, length);
357 BLEND_SOURCE_OVER_ARGB32_WITH_CONST_ALPHA_AVX2(dst, src, length, const_alpha);
360#if QT_CONFIG(raster_64bit)
361void QT_FASTCALL comp_func_SourceOver_rgb64_avx2(QRgba64 *dst,
const QRgba64 *src,
int length, uint const_alpha)
363 Q_ASSERT(const_alpha < 256);
364 const __m256i half = _mm256_set1_epi32(0x8000);
365 const __m256i one = _mm256_set1_epi32(0xffff);
366 const __m256i colorMask = _mm256_set1_epi32(0x0000ffff);
367 __m256i alphaMask = _mm256_set1_epi32(0xff000000);
368 alphaMask = _mm256_unpacklo_epi8(alphaMask, alphaMask);
369 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,
370 char(0xff),
char(0xff),15,14,
char(0xff),
char(0xff),15,14,
char(0xff),
char(0xff),7,6,
char(0xff),
char(0xff),7,6);
372 if (const_alpha == 255) {
374 for (; x < length && (quintptr(dst + x) & 31); ++x)
375 blend_pixel(dst[x], src[x]);
376 for (; x < length - 3; x += 4) {
377 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
378 if (!_mm256_testz_si256(srcVector, alphaMask)) {
380 if (_mm256_testc_si256(srcVector, alphaMask)) {
382 _mm256_store_si256((__m256i *)&dst[x], srcVector);
384 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
385 alphaChannel = _mm256_sub_epi32(one, alphaChannel);
386 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
387 BYTE_MUL_RGB64_AVX2(dstVector, alphaChannel, colorMask, half);
388 dstVector = _mm256_add_epi16(dstVector, srcVector);
389 _mm256_store_si256((__m256i *)&dst[x], dstVector);
393 SIMD_EPILOGUE(x, length, 3)
394 blend_pixel(dst[x], src[x]);
396 const __m256i constAlphaVector = _mm256_set1_epi32(const_alpha | (const_alpha << 8));
398 for (; x < length && (quintptr(dst + x) & 31); ++x)
399 blend_pixel(dst[x], src[x], const_alpha);
400 for (; x < length - 3; x += 4) {
401 __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
402 if (!_mm256_testz_si256(srcVector, alphaMask)) {
404 BYTE_MUL_RGB64_AVX2(srcVector, constAlphaVector, colorMask, half);
406 __m256i alphaChannel = _mm256_shuffle_epi8(srcVector, alphaShuffleMask);
407 alphaChannel = _mm256_sub_epi32(one, alphaChannel);
408 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
409 BYTE_MUL_RGB64_AVX2(dstVector, alphaChannel, colorMask, half);
410 dstVector = _mm256_add_epi16(dstVector, srcVector);
411 _mm256_store_si256((__m256i *)&dst[x], dstVector);
414 SIMD_EPILOGUE(x, length, 3)
415 blend_pixel(dst[x], src[x], const_alpha);
420#if QT_CONFIG(raster_fp)
421void QT_FASTCALL comp_func_SourceOver_rgbafp_avx2(QRgbaFloat32 *dst,
const QRgbaFloat32 *src,
int length, uint const_alpha)
423 Q_ASSERT(const_alpha < 256);
425 const float a = const_alpha / 255.0f;
426 const __m128 one = _mm_set1_ps(1.0f);
427 const __m128 constAlphaVector = _mm_set1_ps(a);
428 const __m256 one256 = _mm256_set1_ps(1.0f);
429 const __m256 constAlphaVector256 = _mm256_set1_ps(a);
431 for (; x < length - 1; x += 2) {
432 __m256 srcVector = _mm256_loadu_ps((
const float *)&src[x]);
433 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
434 srcVector = _mm256_mul_ps(srcVector, constAlphaVector256);
435 __m256 alphaChannel = _mm256_permute_ps(srcVector, _MM_SHUFFLE(3, 3, 3, 3));
436 alphaChannel = _mm256_sub_ps(one256, alphaChannel);
437 dstVector = _mm256_mul_ps(dstVector, alphaChannel);
438 dstVector = _mm256_add_ps(dstVector, srcVector);
439 _mm256_storeu_ps((
float *)(dst + x), dstVector);
442 __m128 srcVector = _mm_loadu_ps((
const float *)&src[x]);
443 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
444 srcVector = _mm_mul_ps(srcVector, constAlphaVector);
445 __m128 alphaChannel = _mm_permute_ps(srcVector, _MM_SHUFFLE(3, 3, 3, 3));
446 alphaChannel = _mm_sub_ps(one, alphaChannel);
447 dstVector = _mm_mul_ps(dstVector, alphaChannel);
448 dstVector = _mm_add_ps(dstVector, srcVector);
449 _mm_storeu_ps((
float *)(dst + x), dstVector);
454void QT_FASTCALL comp_func_Source_avx2(uint *dst,
const uint *src,
int length, uint const_alpha)
456 if (const_alpha == 255) {
457 ::memcpy(dst, src, length *
sizeof(uint));
459 const int ialpha = 255 - const_alpha;
464 ALIGNMENT_PROLOGUE_32BYTES(dst, x, length)
465 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], ialpha);
468 const __m256i half = _mm256_set1_epi16(0x80);
469 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
470 const __m256i constAlphaVector = _mm256_set1_epi16(const_alpha);
471 const __m256i oneMinusConstAlpha = _mm256_set1_epi16(ialpha);
472 for (; x < length - 7; x += 8) {
473 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
474 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
475 INTERPOLATE_PIXEL_255_AVX2(srcVector, dstVector, constAlphaVector, oneMinusConstAlpha, colorMask, half);
476 _mm256_store_si256((__m256i *)&dst[x], dstVector);
480 SIMD_EPILOGUE(x, length, 7)
481 dst[x] = INTERPOLATE_PIXEL_255(src[x], const_alpha, dst[x], ialpha);
485#if QT_CONFIG(raster_64bit)
486void QT_FASTCALL comp_func_Source_rgb64_avx2(QRgba64 *dst,
const QRgba64 *src,
int length, uint const_alpha)
488 Q_ASSERT(const_alpha < 256);
489 if (const_alpha == 255) {
490 ::memcpy(dst, src, length *
sizeof(QRgba64));
492 const uint ca = const_alpha | (const_alpha << 8);
493 const uint cia = 65535 - ca;
498 for (; x < length && (quintptr(dst + x) & 31); ++x)
499 dst[x] = interpolate65535(src[x], ca, dst[x], cia);
502 const __m256i half = _mm256_set1_epi32(0x8000);
503 const __m256i colorMask = _mm256_set1_epi32(0x0000ffff);
504 const __m256i constAlphaVector = _mm256_set1_epi32(ca);
505 const __m256i oneMinusConstAlpha = _mm256_set1_epi32(cia);
506 for (; x < length - 3; x += 4) {
507 const __m256i srcVector = _mm256_lddqu_si256((
const __m256i *)&src[x]);
508 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
509 INTERPOLATE_PIXEL_RGB64_AVX2(srcVector, dstVector, constAlphaVector, oneMinusConstAlpha, colorMask, half);
510 _mm256_store_si256((__m256i *)&dst[x], dstVector);
514 SIMD_EPILOGUE(x, length, 3)
515 dst[x] = interpolate65535(src[x], ca, dst[x], cia);
520#if QT_CONFIG(raster_fp)
521void QT_FASTCALL comp_func_Source_rgbafp_avx2(QRgbaFloat32 *dst,
const QRgbaFloat32 *src,
int length, uint const_alpha)
523 Q_ASSERT(const_alpha < 256);
524 if (const_alpha == 255) {
525 ::memcpy(dst, src, length *
sizeof(QRgbaFloat32));
527 const float ca = const_alpha / 255.f;
528 const float cia = 1.0f - ca;
530 const __m128 constAlphaVector = _mm_set1_ps(ca);
531 const __m128 oneMinusConstAlpha = _mm_set1_ps(cia);
532 const __m256 constAlphaVector256 = _mm256_set1_ps(ca);
533 const __m256 oneMinusConstAlpha256 = _mm256_set1_ps(cia);
535 for (; x < length - 1; x += 2) {
536 __m256 srcVector = _mm256_loadu_ps((
const float *)&src[x]);
537 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
538 srcVector = _mm256_mul_ps(srcVector, constAlphaVector256);
539 dstVector = _mm256_mul_ps(dstVector, oneMinusConstAlpha256);
540 dstVector = _mm256_add_ps(dstVector, srcVector);
541 _mm256_storeu_ps((
float *)&dst[x], dstVector);
544 __m128 srcVector = _mm_loadu_ps((
const float *)&src[x]);
545 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
546 srcVector = _mm_mul_ps(srcVector, constAlphaVector);
547 dstVector = _mm_mul_ps(dstVector, oneMinusConstAlpha);
548 dstVector = _mm_add_ps(dstVector, srcVector);
549 _mm_storeu_ps((
float *)&dst[x], dstVector);
555void QT_FASTCALL comp_func_solid_SourceOver_avx2(uint *destPixels,
int length, uint color, uint const_alpha)
557 if ((const_alpha & qAlpha(color)) == 255) {
558 qt_memfill32(destPixels, color, length);
560 if (const_alpha != 255)
561 color = BYTE_MUL(color, const_alpha);
563 const quint32 minusAlphaOfColor = qAlpha(~color);
566 quint32 *dst = (quint32 *) destPixels;
567 const __m256i colorVector = _mm256_set1_epi32(color);
568 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
569 const __m256i half = _mm256_set1_epi16(0x80);
570 const __m256i minusAlphaOfColorVector = _mm256_set1_epi16(minusAlphaOfColor);
572 ALIGNMENT_PROLOGUE_32BYTES(dst, x, length)
573 destPixels[x] = color + BYTE_MUL(destPixels[x], minusAlphaOfColor);
575 for (; x < length - 7; x += 8) {
576 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
577 BYTE_MUL_AVX2(dstVector, minusAlphaOfColorVector, colorMask, half);
578 dstVector = _mm256_add_epi8(colorVector, dstVector);
579 _mm256_store_si256((__m256i *)&dst[x], dstVector);
581 SIMD_EPILOGUE(x, length, 7)
582 destPixels[x] = color + BYTE_MUL(destPixels[x], minusAlphaOfColor);
586#if QT_CONFIG(raster_64bit)
587void QT_FASTCALL comp_func_solid_SourceOver_rgb64_avx2(QRgba64 *destPixels,
int length, QRgba64 color, uint const_alpha)
589 Q_ASSERT(const_alpha < 256);
590 if (const_alpha == 255 && color.isOpaque()) {
591 qt_memfill64((quint64*)destPixels, color, length);
593 if (const_alpha != 255)
594 color = multiplyAlpha255(color, const_alpha);
596 const uint minusAlphaOfColor = 65535 - color.alpha();
598 quint64 *dst = (quint64 *) destPixels;
599 const __m256i colorVector = _mm256_set1_epi64x(color);
600 const __m256i colorMask = _mm256_set1_epi32(0x0000ffff);
601 const __m256i half = _mm256_set1_epi32(0x8000);
602 const __m256i minusAlphaOfColorVector = _mm256_set1_epi32(minusAlphaOfColor);
604 for (; x < length && (quintptr(dst + x) & 31); ++x)
605 destPixels[x] = color + multiplyAlpha65535(destPixels[x], minusAlphaOfColor);
607 for (; x < length - 3; x += 4) {
608 __m256i dstVector = _mm256_load_si256((__m256i *)&dst[x]);
609 BYTE_MUL_RGB64_AVX2(dstVector, minusAlphaOfColorVector, colorMask, half);
610 dstVector = _mm256_add_epi16(colorVector, dstVector);
611 _mm256_store_si256((__m256i *)&dst[x], dstVector);
613 SIMD_EPILOGUE(x, length, 3)
614 destPixels[x] = color + multiplyAlpha65535(destPixels[x], minusAlphaOfColor);
619#if QT_CONFIG(raster_fp)
620void QT_FASTCALL comp_func_solid_Source_rgbafp_avx2(QRgbaFloat32 *dst,
int length, QRgbaFloat32 color, uint const_alpha)
622 Q_ASSERT(const_alpha < 256);
623 if (const_alpha == 255) {
624 for (
int i = 0; i < length; ++i)
627 const float a = const_alpha / 255.0f;
628 const __m128 alphaVector = _mm_set1_ps(a);
629 const __m128 minusAlphaVector = _mm_set1_ps(1.0f - a);
630 __m128 colorVector = _mm_loadu_ps((
const float *)&color);
631 colorVector = _mm_mul_ps(colorVector, alphaVector);
632 const __m256 colorVector256 = _mm256_insertf128_ps(_mm256_castps128_ps256(colorVector), colorVector, 1);
633 const __m256 minusAlphaVector256 = _mm256_set1_ps(1.0f - a);
635 for (; x < length - 1; x += 2) {
636 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
637 dstVector = _mm256_mul_ps(dstVector, minusAlphaVector256);
638 dstVector = _mm256_add_ps(dstVector, colorVector256);
639 _mm256_storeu_ps((
float *)&dst[x], dstVector);
642 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
643 dstVector = _mm_mul_ps(dstVector, minusAlphaVector);
644 dstVector = _mm_add_ps(dstVector, colorVector);
645 _mm_storeu_ps((
float *)&dst[x], dstVector);
650void QT_FASTCALL comp_func_solid_SourceOver_rgbafp_avx2(QRgbaFloat32 *dst,
int length, QRgbaFloat32 color, uint const_alpha)
652 Q_ASSERT(const_alpha < 256);
653 if (const_alpha == 255 && color.a >= 1.0f) {
654 for (
int i = 0; i < length; ++i)
657 __m128 colorVector = _mm_loadu_ps((
const float *)&color);
658 if (const_alpha != 255)
659 colorVector = _mm_mul_ps(colorVector, _mm_set1_ps(const_alpha / 255.f));
660 __m128 minusAlphaOfColorVector =
661 _mm_sub_ps(_mm_set1_ps(1.0f), _mm_permute_ps(colorVector, _MM_SHUFFLE(3, 3, 3, 3)));
662 const __m256 colorVector256 = _mm256_insertf128_ps(_mm256_castps128_ps256(colorVector), colorVector, 1);
663 const __m256 minusAlphaVector256 = _mm256_insertf128_ps(_mm256_castps128_ps256(minusAlphaOfColorVector),
664 minusAlphaOfColorVector, 1);
666 for (; x < length - 1; x += 2) {
667 __m256 dstVector = _mm256_loadu_ps((
const float *)&dst[x]);
668 dstVector = _mm256_mul_ps(dstVector, minusAlphaVector256);
669 dstVector = _mm256_add_ps(dstVector, colorVector256);
670 _mm256_storeu_ps((
float *)&dst[x], dstVector);
673 __m128 dstVector = _mm_loadu_ps((
const float *)&dst[x]);
674 dstVector = _mm_mul_ps(dstVector, minusAlphaOfColorVector);
675 dstVector = _mm_add_ps(dstVector, colorVector);
676 _mm_storeu_ps((
float *)&dst[x], dstVector);
682#define interpolate_4_pixels_16_avx2(tlr1, tlr2, blr1, blr2, distx, disty, colorMask, v_256, b) \
683{
685 const __m256i vdistx = _mm256_permute4x64_epi64(distx, _MM_SHUFFLE(3
, 1
, 2
, 0
));
686 const __m256i vdisty = _mm256_permute4x64_epi64(disty, _MM_SHUFFLE(3
, 1
, 2
, 0
));
688 __m256i dxdy = _mm256_mullo_epi16 (vdistx, vdisty);
689 const __m256i distx_ = _mm256_slli_epi16(vdistx, 4
);
690 const __m256i disty_ = _mm256_slli_epi16(vdisty, 4
);
691 __m256i idxidy = _mm256_add_epi16(dxdy, _mm256_sub_epi16(v_256, _mm256_add_epi16(distx_, disty_)));
692 __m256i dxidy = _mm256_sub_epi16(distx_, dxdy);
693 __m256i idxdy = _mm256_sub_epi16(disty_, dxdy);
695 __m256i tlr1AG = _mm256_srli_epi16(tlr1, 8
);
696 __m256i tlr1RB = _mm256_and_si256(tlr1, colorMask);
697 __m256i tlr2AG = _mm256_srli_epi16(tlr2, 8
);
698 __m256i tlr2RB = _mm256_and_si256(tlr2, colorMask);
699 __m256i blr1AG = _mm256_srli_epi16(blr1, 8
);
700 __m256i blr1RB = _mm256_and_si256(blr1, colorMask);
701 __m256i blr2AG = _mm256_srli_epi16(blr2, 8
);
702 __m256i blr2RB = _mm256_and_si256(blr2, colorMask);
704 __m256i odxidy1 = _mm256_unpacklo_epi32(idxidy, dxidy);
705 __m256i odxidy2 = _mm256_unpackhi_epi32(idxidy, dxidy);
706 tlr1AG = _mm256_mullo_epi16(tlr1AG, odxidy1);
707 tlr1RB = _mm256_mullo_epi16(tlr1RB, odxidy1);
708 tlr2AG = _mm256_mullo_epi16(tlr2AG, odxidy2);
709 tlr2RB = _mm256_mullo_epi16(tlr2RB, odxidy2);
710 __m256i odxdy1 = _mm256_unpacklo_epi32(idxdy, dxdy);
711 __m256i odxdy2 = _mm256_unpackhi_epi32(idxdy, dxdy);
712 blr1AG = _mm256_mullo_epi16(blr1AG, odxdy1);
713 blr1RB = _mm256_mullo_epi16(blr1RB, odxdy1);
714 blr2AG = _mm256_mullo_epi16(blr2AG, odxdy2);
715 blr2RB = _mm256_mullo_epi16(blr2RB, odxdy2);
718 __m256i topAG = _mm256_hadd_epi32(tlr1AG, tlr2AG);
719 __m256i topRB = _mm256_hadd_epi32(tlr1RB, tlr2RB);
720 __m256i botAG = _mm256_hadd_epi32(blr1AG, blr2AG);
721 __m256i botRB = _mm256_hadd_epi32(blr1RB, blr2RB);
722 __m256i rAG = _mm256_add_epi16(topAG, botAG);
723 __m256i rRB = _mm256_add_epi16(topRB, botRB);
724 rRB = _mm256_srli_epi16(rRB, 8
);
726 rAG = _mm256_permute4x64_epi64(rAG, _MM_SHUFFLE(3
, 1
, 2
, 0
));
727 rRB = _mm256_permute4x64_epi64(rRB, _MM_SHUFFLE(3
, 1
, 2
, 0
));
728 _mm256_storeu_si256((__m256i*)(b), _mm256_blendv_epi8(rAG, rRB, colorMask)); \
729}
731inline void fetchTransformedBilinear_pixelBounds(
int,
int l1,
int l2,
int &v1,
int &v2)
739 Q_ASSERT(v1 >= l1 && v1 <= l2);
740 Q_ASSERT(v2 >= l1 && v2 <= l2);
743void QT_FASTCALL intermediate_adder_avx2(uint *b, uint *end,
const IntermediateBuffer &intermediate,
int offset,
int &fx,
int fdx);
745void QT_FASTCALL fetchTransformedBilinearARGB32PM_simple_scale_helper_avx2(uint *b, uint *end,
const QTextureData &image,
746 int &fx,
int &fy,
int fdx,
int )
750 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
751 const uint *s1 = (
const uint *)image.scanLine(y1);
752 const uint *s2 = (
const uint *)image.scanLine(y2);
754 const int disty = (fy & 0x0000ffff) >> 8;
755 const int idisty = 256 - disty;
756 const int length = end - b;
759 const int adjust = (fdx < 0) ? fdx * length : 0;
760 const int offset = (fx + adjust) >> 16;
763 Q_DECL_UNINITIALIZED IntermediateBuffer intermediate;
765 int count = (qint64(length) * qAbs(fdx) + FixedScale - 1) / FixedScale + 2;
768 Q_ASSERT(count <= BufferSize + 2);
770 int lim = qMin(count, image.x2 - x);
772 Q_ASSERT(x < image.x2);
773 uint t = s1[image.x1];
774 uint b = s2[image.x1];
775 quint32 rb = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
776 quint32 ag = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
778 intermediate.buffer_rb[f] = rb;
779 intermediate.buffer_ag[f] = ag;
782 }
while (x < image.x1 && f < lim);
785 const __m256i disty_ = _mm256_set1_epi16(disty);
786 const __m256i idisty_ = _mm256_set1_epi16(idisty);
787 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
790 for (; f < lim; x += 8, f += 8) {
792 __m256i top = _mm256_loadu_si256((
const __m256i*)((
const uint *)(s1)+x));
793 __m256i topAG = _mm256_srli_epi16(top, 8);
794 __m256i topRB = _mm256_and_si256(top, colorMask);
796 topAG = _mm256_mullo_epi16 (topAG, idisty_);
797 topRB = _mm256_mullo_epi16 (topRB, idisty_);
800 __m256i bottom = _mm256_loadu_si256((
const __m256i*)((
const uint *)(s2)+x));
801 __m256i bottomAG = _mm256_srli_epi16(bottom, 8);
802 __m256i bottomRB = _mm256_and_si256(bottom, colorMask);
803 bottomAG = _mm256_mullo_epi16 (bottomAG, disty_);
804 bottomRB = _mm256_mullo_epi16 (bottomRB, disty_);
807 __m256i rAG =_mm256_add_epi16(topAG, bottomAG);
808 rAG = _mm256_srli_epi16(rAG, 8);
809 _mm256_storeu_si256((__m256i*)(&intermediate.buffer_ag[f]), rAG);
810 __m256i rRB =_mm256_add_epi16(topRB, bottomRB);
811 rRB = _mm256_srli_epi16(rRB, 8);
812 _mm256_storeu_si256((__m256i*)(&intermediate.buffer_rb[f]), rRB);
815 for (; f < count; f++) {
816 x = qMin(x, image.x2 - 1);
821 intermediate.buffer_rb[f] = (((t & 0xff00ff) * idisty + (b & 0xff00ff) * disty) >> 8) & 0xff00ff;
822 intermediate.buffer_ag[f] = ((((t>>8) & 0xff00ff) * idisty + ((b>>8) & 0xff00ff) * disty) >> 8) & 0xff00ff;
827 intermediate_adder_avx2(b, end, intermediate, offset, fx, fdx);
830void QT_FASTCALL intermediate_adder_avx2(uint *b, uint *end,
const IntermediateBuffer &intermediate,
int offset,
int &fx,
int fdx)
832 fx -= offset * FixedScale;
834 const __m128i v_fdx = _mm_set1_epi32(fdx * 4);
835 const __m128i v_blend = _mm_set1_epi32(0x00800080);
836 const __m128i vdx_shuffle = _mm_set_epi8(
char(0x80), 13,
char(0x80), 13,
char(0x80), 9,
char(0x80), 9,
837 char(0x80), 5,
char(0x80), 5,
char(0x80), 1,
char(0x80), 1);
838 __m128i v_fx = _mm_setr_epi32(fx, fx + fdx, fx + fdx + fdx, fx + fdx + fdx + fdx);
840 while (b < end - 3) {
841 const __m128i offset = _mm_srli_epi32(v_fx, 16);
842 __m256i vrb = _mm256_i32gather_epi64((
const long long *)intermediate.buffer_rb, offset, 4);
843 __m256i vag = _mm256_i32gather_epi64((
const long long *)intermediate.buffer_ag, offset, 4);
845 __m128i vdx = _mm_shuffle_epi8(v_fx, vdx_shuffle);
846 __m128i vidx = _mm_sub_epi16(_mm_set1_epi16(256), vdx);
847 __m256i vmulx = _mm256_castsi128_si256(_mm_unpacklo_epi32(vidx, vdx));
848 vmulx = _mm256_inserti128_si256(vmulx, _mm_unpackhi_epi32(vidx, vdx), 1);
850 vrb = _mm256_mullo_epi16(vrb, vmulx);
851 vag = _mm256_mullo_epi16(vag, vmulx);
853 __m256i vrbag = _mm256_hadd_epi32(vrb, vag);
854 vrbag = _mm256_permute4x64_epi64(vrbag, _MM_SHUFFLE(3, 1, 2, 0));
856 __m128i rb = _mm256_castsi256_si128(vrbag);
857 __m128i ag = _mm256_extracti128_si256(vrbag, 1);
858 rb = _mm_srli_epi16(rb, 8);
860 _mm_storeu_si128((__m128i*)b, _mm_blendv_epi8(ag, rb, v_blend));
863 v_fx = _mm_add_epi32(v_fx, v_fdx);
865 fx = _mm_cvtsi128_si32(v_fx);
867 const int x = (fx >> 16);
869 const uint distx = (fx & 0x0000ffff) >> 8;
870 const uint idistx = 256 - distx;
871 const uint rb = (intermediate.buffer_rb[x] * idistx + intermediate.buffer_rb[x + 1] * distx) & 0xff00ff00;
872 const uint ag = (intermediate.buffer_ag[x] * idistx + intermediate.buffer_ag[x + 1] * distx) & 0xff00ff00;
877 fx += offset * FixedScale;
880void QT_FASTCALL fetchTransformedBilinearARGB32PM_downscale_helper_avx2(uint *b, uint *end,
const QTextureData &image,
881 int &fx,
int &fy,
int fdx,
int )
885 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
886 const uint *s1 = (
const uint *)image.scanLine(y1);
887 const uint *s2 = (
const uint *)image.scanLine(y2);
888 const int disty8 = (fy & 0x0000ffff) >> 8;
889 const int disty4 = (disty8 + 0x08) >> 4;
891 const qint64 min_fx = qint64(image.x1) * FixedScale;
892 const qint64 max_fx = qint64(image.x2 - 1) * FixedScale;
896 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
901 *b = INTERPOLATE_PIXEL_256(top, 256 - disty8, bot, disty8);
905 uint *boundedEnd = end;
907 boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx);
909 boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx);
912 const __m256i vdistShuffle =
913 _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),
914 0,
char(0x80), 0,
char(0x80), 4,
char(0x80), 4,
char(0x80), 8,
char(0x80), 8,
char(0x80), 12,
char(0x80), 12,
char(0x80));
915 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
916 const __m256i v_256 = _mm256_set1_epi16(256);
917 const __m256i v_disty = _mm256_set1_epi16(disty4);
918 const __m256i v_fdx = _mm256_set1_epi32(fdx * 8);
919 const __m256i v_fx_r = _mm256_set1_epi32(0x08);
920 const __m256i v_index = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
921 __m256i v_fx = _mm256_set1_epi32(fx);
922 v_fx = _mm256_add_epi32(v_fx, _mm256_mullo_epi32(_mm256_set1_epi32(fdx), v_index));
924 while (b < boundedEnd - 7) {
925 const __m256i offset = _mm256_srli_epi32(v_fx, 16);
926 const __m128i offsetLo = _mm256_castsi256_si128(offset);
927 const __m128i offsetHi = _mm256_extracti128_si256(offset, 1);
928 const __m256i toplo = _mm256_i32gather_epi64((
const long long *)s1, offsetLo, 4);
929 const __m256i tophi = _mm256_i32gather_epi64((
const long long *)s1, offsetHi, 4);
930 const __m256i botlo = _mm256_i32gather_epi64((
const long long *)s2, offsetLo, 4);
931 const __m256i bothi = _mm256_i32gather_epi64((
const long long *)s2, offsetHi, 4);
933 __m256i v_distx = _mm256_srli_epi16(v_fx, 8);
934 v_distx = _mm256_srli_epi16(_mm256_add_epi32(v_distx, v_fx_r), 4);
935 v_distx = _mm256_shuffle_epi8(v_distx, vdistShuffle);
937 interpolate_4_pixels_16_avx2(toplo, tophi, botlo, bothi, v_distx, v_disty, colorMask, v_256, b);
939 v_fx = _mm256_add_epi32(v_fx, v_fdx);
941 fx = _mm_extract_epi32(_mm256_castsi256_si128(v_fx) , 0);
943 while (b < boundedEnd) {
945 int distx8 = (fx & 0x0000ffff) >> 8;
946 *b = interpolate_4_pixels(s1 + x, s2 + x, distx8, disty8);
954 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
959 int distx8 = (fx & 0x0000ffff) >> 8;
960 *b = interpolate_4_pixels(tl, tr, bl, br, distx8, disty8);
966void QT_FASTCALL fetchTransformedBilinearARGB32PM_fast_rotate_helper_avx2(uint *b, uint *end,
const QTextureData &image,
967 int &fx,
int &fy,
int fdx,
int fdy)
969 const qint64 min_fx = qint64(image.x1) * FixedScale;
970 const qint64 max_fx = qint64(image.x2 - 1) * FixedScale;
971 const qint64 min_fy = qint64(image.y1) * FixedScale;
972 const qint64 max_fy = qint64(image.y2 - 1) * FixedScale;
979 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
980 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
981 if (x1 != x2 && y1 != y2)
983 const uint *s1 = (
const uint *)image.scanLine(y1);
984 const uint *s2 = (
const uint *)image.scanLine(y2);
989 int distx = (fx & 0x0000ffff) >> 8;
990 int disty = (fy & 0x0000ffff) >> 8;
991 *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
996 uint *boundedEnd = end;
998 boundedEnd = qMin(boundedEnd, b + (max_fx - fx) / fdx);
1000 boundedEnd = qMin(boundedEnd, b + (min_fx - fx) / fdx);
1002 boundedEnd = qMin(boundedEnd, b + (max_fy - fy) / fdy);
1004 boundedEnd = qMin(boundedEnd, b + (min_fy - fy) / fdy);
1007 const __m256i vdistShuffle =
1008 _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),
1009 0,
char(0x80), 0,
char(0x80), 4,
char(0x80), 4,
char(0x80), 8,
char(0x80), 8,
char(0x80), 12,
char(0x80), 12,
char(0x80));
1010 const __m256i colorMask = _mm256_set1_epi32(0x00ff00ff);
1011 const __m256i v_256 = _mm256_set1_epi16(256);
1012 const __m256i v_fdx = _mm256_set1_epi32(fdx * 8);
1013 const __m256i v_fdy = _mm256_set1_epi32(fdy * 8);
1014 const __m256i v_fxy_r = _mm256_set1_epi32(0x08);
1015 const __m256i v_index = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
1016 __m256i v_fx = _mm256_set1_epi32(fx);
1017 __m256i v_fy = _mm256_set1_epi32(fy);
1018 v_fx = _mm256_add_epi32(v_fx, _mm256_mullo_epi32(_mm256_set1_epi32(fdx), v_index));
1019 v_fy = _mm256_add_epi32(v_fy, _mm256_mullo_epi32(_mm256_set1_epi32(fdy), v_index));
1021 const uchar *textureData = image.imageData;
1022 const qsizetype bytesPerLine = image.bytesPerLine;
1023 const __m256i vbpl = _mm256_set1_epi16(bytesPerLine/4);
1025 while (b < boundedEnd - 7) {
1026 const __m256i vy = _mm256_packs_epi32(_mm256_srli_epi32(v_fy, 16), _mm256_setzero_si256());
1028 __m256i offset = _mm256_unpacklo_epi16(_mm256_mullo_epi16(vy, vbpl), _mm256_mulhi_epi16(vy, vbpl));
1029 offset = _mm256_add_epi32(offset, _mm256_srli_epi32(v_fx, 16));
1030 const __m128i offsetLo = _mm256_castsi256_si128(offset);
1031 const __m128i offsetHi = _mm256_extracti128_si256(offset, 1);
1032 const uint *topData = (
const uint *)(textureData);
1033 const uint *botData = (
const uint *)(textureData + bytesPerLine);
1034 const __m256i toplo = _mm256_i32gather_epi64((
const long long *)topData, offsetLo, 4);
1035 const __m256i tophi = _mm256_i32gather_epi64((
const long long *)topData, offsetHi, 4);
1036 const __m256i botlo = _mm256_i32gather_epi64((
const long long *)botData, offsetLo, 4);
1037 const __m256i bothi = _mm256_i32gather_epi64((
const long long *)botData, offsetHi, 4);
1039 __m256i v_distx = _mm256_srli_epi16(v_fx, 8);
1040 __m256i v_disty = _mm256_srli_epi16(v_fy, 8);
1041 v_distx = _mm256_srli_epi16(_mm256_add_epi32(v_distx, v_fxy_r), 4);
1042 v_disty = _mm256_srli_epi16(_mm256_add_epi32(v_disty, v_fxy_r), 4);
1043 v_distx = _mm256_shuffle_epi8(v_distx, vdistShuffle);
1044 v_disty = _mm256_shuffle_epi8(v_disty, vdistShuffle);
1046 interpolate_4_pixels_16_avx2(toplo, tophi, botlo, bothi, v_distx, v_disty, colorMask, v_256, b);
1048 v_fx = _mm256_add_epi32(v_fx, v_fdx);
1049 v_fy = _mm256_add_epi32(v_fy, v_fdy);
1051 fx = _mm_extract_epi32(_mm256_castsi256_si128(v_fx) , 0);
1052 fy = _mm_extract_epi32(_mm256_castsi256_si128(v_fy) , 0);
1054 while (b < boundedEnd) {
1058 const uint *s1 = (
const uint *)image.scanLine(y);
1059 const uint *s2 = (
const uint *)image.scanLine(y + 1);
1061 int distx = (fx & 0x0000ffff) >> 8;
1062 int disty = (fy & 0x0000ffff) >> 8;
1063 *b = interpolate_4_pixels(s1 + x, s2 + x, distx, disty);
1071 int x1 = (fx >> 16);
1073 int y1 = (fy >> 16);
1076 fetchTransformedBilinear_pixelBounds(image.width, image.x1, image.x2 - 1, x1, x2);
1077 fetchTransformedBilinear_pixelBounds(image.height, image.y1, image.y2 - 1, y1, y2);
1079 const uint *s1 = (
const uint *)image.scanLine(y1);
1080 const uint *s2 = (
const uint *)image.scanLine(y2);
1087 int distx = (fx & 0x0000ffff) >> 8;
1088 int disty = (fy & 0x0000ffff) >> 8;
1089 *b = interpolate_4_pixels(tl, tr, bl, br, distx, disty);
1097static inline __m256i epilogueMaskFromCount(qsizetype count)
1099 Q_ASSERT(count > 0);
1100 static const __m256i offsetMask = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
1101 return _mm256_add_epi32(offsetMask, _mm256_set1_epi32(-count));
1105static void convertARGBToARGB32PM_avx2(uint *buffer,
const uint *src, qsizetype count)
1108 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
1109 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));
1110 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));
1111 const __m256i half = _mm256_set1_epi16(0x0080);
1112 const __m256i zero = _mm256_setzero_si256();
1114 for (; i < count - 7; i += 8) {
1115 __m256i srcVector = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(src + i));
1116 if (!_mm256_testz_si256(srcVector, alphaMask)) {
1118 bool cf = _mm256_testc_si256(srcVector, alphaMask);
1120 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1122 __m256i src1 = _mm256_unpacklo_epi8(srcVector, zero);
1123 __m256i src2 = _mm256_unpackhi_epi8(srcVector, zero);
1124 __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1125 __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1126 src1 = _mm256_mullo_epi16(src1, alpha1);
1127 src2 = _mm256_mullo_epi16(src2, alpha2);
1128 src1 = _mm256_add_epi16(src1, _mm256_srli_epi16(src1, 8));
1129 src2 = _mm256_add_epi16(src2, _mm256_srli_epi16(src2, 8));
1130 src1 = _mm256_add_epi16(src1, half);
1131 src2 = _mm256_add_epi16(src2, half);
1132 src1 = _mm256_srli_epi16(src1, 8);
1133 src2 = _mm256_srli_epi16(src2, 8);
1134 src1 = _mm256_blend_epi16(src1, alpha1, 0x88);
1135 src2 = _mm256_blend_epi16(src2, alpha2, 0x88);
1136 srcVector = _mm256_packus_epi16(src1, src2);
1137 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), srcVector);
1139 if (buffer != src || RGBA)
1140 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), srcVector);
1143 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), zero);
1148 const __m256i epilogueMask = epilogueMaskFromCount(count - i);
1149 __m256i srcVector = _mm256_maskload_epi32(
reinterpret_cast<
const int *>(src + i), epilogueMask);
1150 const __m256i epilogueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, epilogueMask);
1152 if (!_mm256_testz_si256(srcVector, epilogueAlphaMask)) {
1154 bool cf = _mm256_testc_si256(srcVector, epilogueAlphaMask);
1156 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1158 __m256i src1 = _mm256_unpacklo_epi8(srcVector, zero);
1159 __m256i src2 = _mm256_unpackhi_epi8(srcVector, zero);
1160 __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1161 __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1162 src1 = _mm256_mullo_epi16(src1, alpha1);
1163 src2 = _mm256_mullo_epi16(src2, alpha2);
1164 src1 = _mm256_add_epi16(src1, _mm256_srli_epi16(src1, 8));
1165 src2 = _mm256_add_epi16(src2, _mm256_srli_epi16(src2, 8));
1166 src1 = _mm256_add_epi16(src1, half);
1167 src2 = _mm256_add_epi16(src2, half);
1168 src1 = _mm256_srli_epi16(src1, 8);
1169 src2 = _mm256_srli_epi16(src2, 8);
1170 src1 = _mm256_blend_epi16(src1, alpha1, 0x88);
1171 src2 = _mm256_blend_epi16(src2, alpha2, 0x88);
1172 srcVector = _mm256_packus_epi16(src1, src2);
1173 _mm256_maskstore_epi32(
reinterpret_cast<
int *>(buffer + i), epilogueMask, srcVector);
1175 if (buffer != src || RGBA)
1176 _mm256_maskstore_epi32(
reinterpret_cast<
int *>(buffer + i), epilogueMask, srcVector);
1179 _mm256_maskstore_epi32(
reinterpret_cast<
int *>(buffer + i), epilogueMask, zero);
1184void QT_FASTCALL convertARGB32ToARGB32PM_avx2(uint *buffer,
int count,
const QList<QRgb> *)
1186 convertARGBToARGB32PM_avx2<
false>(buffer, buffer, count);
1189void QT_FASTCALL convertRGBA8888ToARGB32PM_avx2(uint *buffer,
int count,
const QList<QRgb> *)
1191 convertARGBToARGB32PM_avx2<
true>(buffer, buffer, count);
1194const uint *QT_FASTCALL fetchARGB32ToARGB32PM_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1195 const QList<QRgb> *, QDitherInfo *)
1197 convertARGBToARGB32PM_avx2<
false>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1201const uint *QT_FASTCALL fetchRGBA8888ToARGB32PM_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1202 const QList<QRgb> *, QDitherInfo *)
1204 convertARGBToARGB32PM_avx2<
true>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1209static void convertARGBToRGBA64PM_avx2(QRgba64 *buffer,
const uint *src, qsizetype count)
1212 const __m256i alphaMask = _mm256_set1_epi32(0xff000000);
1213 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));
1214 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));
1215 const __m256i zero = _mm256_setzero_si256();
1217 for (; i < count - 7; i += 8) {
1219 __m256i srcVector = _mm256_loadu_si256(
reinterpret_cast<
const __m256i *>(src + i));
1220 if (!_mm256_testz_si256(srcVector, alphaMask)) {
1222 bool cf = _mm256_testc_si256(srcVector, alphaMask);
1224 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1232 srcVector = _mm256_permute4x64_epi64(srcVector, _MM_SHUFFLE(3, 1, 2, 0));
1234 const __m256i src1 = _mm256_unpacklo_epi8(srcVector, srcVector);
1235 const __m256i src2 = _mm256_unpackhi_epi8(srcVector, srcVector);
1237 const __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1238 const __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1239 dst1 = _mm256_mulhi_epu16(src1, alpha1);
1240 dst2 = _mm256_mulhi_epu16(src2, alpha2);
1241 dst1 = _mm256_add_epi16(dst1, _mm256_srli_epi16(dst1, 15));
1242 dst2 = _mm256_add_epi16(dst2, _mm256_srli_epi16(dst2, 15));
1243 dst1 = _mm256_blend_epi16(dst1, src1, 0x88);
1244 dst2 = _mm256_blend_epi16(dst2, src2, 0x88);
1252 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i), dst1);
1253 _mm256_storeu_si256(
reinterpret_cast<__m256i *>(buffer + i) + 1, dst2);
1257 __m256i epilogueMask = epilogueMaskFromCount(count - i);
1258 const __m256i epilogueAlphaMask = _mm256_blendv_epi8(_mm256_setzero_si256(), alphaMask, epilogueMask);
1260 __m256i srcVector = _mm256_maskload_epi32(
reinterpret_cast<
const int *>(src + i), epilogueMask);
1262 if (!_mm256_testz_si256(srcVector, epilogueAlphaMask)) {
1264 bool cf = _mm256_testc_si256(srcVector, epilogueAlphaMask);
1266 srcVector = _mm256_shuffle_epi8(srcVector, rgbaMask);
1267 srcVector = _mm256_permute4x64_epi64(srcVector, _MM_SHUFFLE(3, 1, 2, 0));
1268 const __m256i src1 = _mm256_unpacklo_epi8(srcVector, srcVector);
1269 const __m256i src2 = _mm256_unpackhi_epi8(srcVector, srcVector);
1271 const __m256i alpha1 = _mm256_shuffle_epi8(src1, shuffleMask);
1272 const __m256i alpha2 = _mm256_shuffle_epi8(src2, shuffleMask);
1273 dst1 = _mm256_mulhi_epu16(src1, alpha1);
1274 dst2 = _mm256_mulhi_epu16(src2, alpha2);
1275 dst1 = _mm256_add_epi16(dst1, _mm256_srli_epi16(dst1, 15));
1276 dst2 = _mm256_add_epi16(dst2, _mm256_srli_epi16(dst2, 15));
1277 dst1 = _mm256_blend_epi16(dst1, src1, 0x88);
1278 dst2 = _mm256_blend_epi16(dst2, src2, 0x88);
1286 epilogueMask = _mm256_permute4x64_epi64(epilogueMask, _MM_SHUFFLE(3, 1, 2, 0));
1287 _mm256_maskstore_epi64(
reinterpret_cast<qint64 *>(buffer + i),
1288 _mm256_unpacklo_epi32(epilogueMask, epilogueMask),
1290 _mm256_maskstore_epi64(
reinterpret_cast<qint64 *>(buffer + i + 4),
1291 _mm256_unpackhi_epi32(epilogueMask, epilogueMask),
1296const QRgba64 * QT_FASTCALL convertARGB32ToRGBA64PM_avx2(QRgba64 *buffer,
const uint *src,
int count,
1297 const QList<QRgb> *, QDitherInfo *)
1299 convertARGBToRGBA64PM_avx2<
false>(buffer, src, count);
1303const QRgba64 * QT_FASTCALL convertRGBA8888ToRGBA64PM_avx2(QRgba64 *buffer,
const uint *src,
int count,
1304 const QList<QRgb> *, QDitherInfo *)
1306 convertARGBToRGBA64PM_avx2<
true>(buffer, src, count);
1310const QRgba64 *QT_FASTCALL fetchARGB32ToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1311 const QList<QRgb> *, QDitherInfo *)
1313 convertARGBToRGBA64PM_avx2<
false>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1317const QRgba64 *QT_FASTCALL fetchRGBA8888ToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1318 const QList<QRgb> *, QDitherInfo *)
1320 convertARGBToRGBA64PM_avx2<
true>(buffer,
reinterpret_cast<
const uint *>(src) + index, count);
1324const QRgba64 *QT_FASTCALL fetchRGBA64ToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1325 const QList<QRgb> *, QDitherInfo *)
1327 const QRgba64 *s =
reinterpret_cast<
const QRgba64 *>(src) + index;
1329 const __m256i vh = _mm256_set1_epi32(0x8000);
1330 for (; i < count - 3; i += 4) {
1331 __m256i vs256 = _mm256_loadu_si256((
const __m256i *)(s + i));
1332 __m256i va256 = _mm256_shufflelo_epi16(vs256, _MM_SHUFFLE(3, 3, 3, 3));
1333 va256 = _mm256_shufflehi_epi16(va256, _MM_SHUFFLE(3, 3, 3, 3));
1334 const __m256i vmullo = _mm256_mullo_epi16(vs256, va256);
1335 const __m256i vmulhi = _mm256_mulhi_epu16(vs256, va256);
1336 __m256i vslo = _mm256_unpacklo_epi16(vmullo, vmulhi);
1337 __m256i vshi = _mm256_unpackhi_epi16(vmullo, vmulhi);
1338 vslo = _mm256_add_epi32(vslo, _mm256_srli_epi32(vslo, 16));
1339 vshi = _mm256_add_epi32(vshi, _mm256_srli_epi32(vshi, 16));
1340 vslo = _mm256_add_epi32(vslo, vh);
1341 vshi = _mm256_add_epi32(vshi, vh);
1342 vslo = _mm256_srli_epi32(vslo, 16);
1343 vshi = _mm256_srli_epi32(vshi, 16);
1344 vs256 = _mm256_packus_epi32(vslo, vshi);
1345 vs256 = _mm256_blend_epi16(vs256, va256, 0x88);
1346 _mm256_storeu_si256((__m256i *)(buffer + i), vs256);
1348 for (; i < count; ++i) {
1349 const auto a = s[i].alpha();
1350 __m128i vs = _mm_loadl_epi64((
const __m128i *)(s + i));
1351 __m128i va = _mm_shufflelo_epi16(vs, _MM_SHUFFLE(3, 3, 3, 3));
1352 vs = multiplyAlpha65535(vs, va);
1353 _mm_storel_epi64((__m128i *)(buffer + i), vs);
1354 buffer[i].setAlpha(a);
1359const uint *QT_FASTCALL fetchRGB16FToRGB32_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1360 const QList<QRgb> *, QDitherInfo *)
1362 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1363 const __m256 vf = _mm256_set1_ps(255.0f);
1364 const __m256 vh = _mm256_set1_ps(0.5f);
1366 for (; i + 1 < count; i += 2) {
1367 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1368 vsf = _mm256_mul_ps(vsf, vf);
1369 vsf = _mm256_add_ps(vsf, vh);
1370 __m256i vsi = _mm256_cvttps_epi32(vsf);
1371 vsi = _mm256_packs_epi32(vsi, vsi);
1372 vsi = _mm256_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1373 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1374 __m128i vsi128 = _mm256_castsi256_si128(vsi);
1375 vsi128 = _mm_packus_epi16(vsi128, vsi128);
1376 _mm_storel_epi64((__m128i *)(buffer + i), vsi128);
1379 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1380 vsf = _mm_mul_ps(vsf, _mm_set1_ps(255.0f));
1381 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1382 __m128i vsi = _mm_cvttps_epi32(vsf);
1383 vsi = _mm_packs_epi32(vsi, vsi);
1384 vsi = _mm_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1385 vsi = _mm_packus_epi16(vsi, vsi);
1386 buffer[i] = _mm_cvtsi128_si32(vsi);
1391const uint *QT_FASTCALL fetchRGBA16FToARGB32PM_avx2(uint *buffer,
const uchar *src,
int index,
int count,
1392 const QList<QRgb> *, QDitherInfo *)
1394 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1395 const __m256 vf = _mm256_set1_ps(255.0f);
1396 const __m256 vh = _mm256_set1_ps(0.5f);
1398 for (; i + 1 < count; i += 2) {
1399 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1400 __m256 vsa = _mm256_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1401 vsf = _mm256_mul_ps(vsf, vsa);
1402 vsf = _mm256_blend_ps(vsf, vsa, 0x88);
1403 vsf = _mm256_mul_ps(vsf, vf);
1404 vsf = _mm256_add_ps(vsf, vh);
1405 __m256i vsi = _mm256_cvttps_epi32(vsf);
1406 vsi = _mm256_packus_epi32(vsi, vsi);
1407 vsi = _mm256_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1408 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1409 __m128i vsi128 = _mm256_castsi256_si128(vsi);
1410 vsi128 = _mm_packus_epi16(vsi128, vsi128);
1411 _mm_storel_epi64((__m128i *)(buffer + i), vsi128);
1414 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1415 __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1416 vsf = _mm_mul_ps(vsf, vsa);
1417 vsf = _mm_insert_ps(vsf, vsa, 0x30);
1418 vsf = _mm_mul_ps(vsf, _mm_set1_ps(255.0f));
1419 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1420 __m128i vsi = _mm_cvttps_epi32(vsf);
1421 vsi = _mm_packus_epi32(vsi, vsi);
1422 vsi = _mm_shufflelo_epi16(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1423 vsi = _mm_packus_epi16(vsi, vsi);
1424 buffer[i] = _mm_cvtsi128_si32(vsi);
1429const QRgba64 *QT_FASTCALL fetchRGBA16FPMToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1430 const QList<QRgb> *, QDitherInfo *)
1432 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1433 const __m256 vf = _mm256_set1_ps(65535.0f);
1434 const __m256 vh = _mm256_set1_ps(0.5f);
1436 for (; i + 1 < count; i += 2) {
1437 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1438 vsf = _mm256_mul_ps(vsf, vf);
1439 vsf = _mm256_add_ps(vsf, vh);
1440 __m256i vsi = _mm256_cvttps_epi32(vsf);
1441 vsi = _mm256_packus_epi32(vsi, vsi);
1442 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1443 _mm_storeu_si128((__m128i *)(buffer + i), _mm256_castsi256_si128(vsi));
1446 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1447 vsf = _mm_mul_ps(vsf, _mm_set1_ps(65535.0f));
1448 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1449 __m128i vsi = _mm_cvttps_epi32(vsf);
1450 vsi = _mm_packus_epi32(vsi, vsi);
1451 _mm_storel_epi64((__m128i *)(buffer + i), vsi);
1456const QRgba64 *QT_FASTCALL fetchRGBA16FToRGBA64PM_avx2(QRgba64 *buffer,
const uchar *src,
int index,
int count,
1457 const QList<QRgb> *, QDitherInfo *)
1459 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1460 const __m256 vf = _mm256_set1_ps(65535.0f);
1461 const __m256 vh = _mm256_set1_ps(0.5f);
1463 for (; i + 1 < count; i += 2) {
1464 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1465 __m256 vsa = _mm256_shuffle_ps(vsf, vsf, _MM_SHUFFLE(3, 3, 3, 3));
1466 vsf = _mm256_mul_ps(vsf, vsa);
1467 vsf = _mm256_blend_ps(vsf, vsa, 0x88);
1468 vsf = _mm256_mul_ps(vsf, vf);
1469 vsf = _mm256_add_ps(vsf, vh);
1470 __m256i vsi = _mm256_cvttps_epi32(vsf);
1471 vsi = _mm256_packus_epi32(vsi, vsi);
1472 vsi = _mm256_permute4x64_epi64(vsi, _MM_SHUFFLE(3, 1, 2, 0));
1473 _mm_storeu_si128((__m128i *)(buffer + i), _mm256_castsi256_si128(vsi));
1476 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1477 __m128 vsa = _mm_shuffle_ps(vsf, vsf, _MM_SHUFFLE(3, 3, 3, 3));
1478 vsf = _mm_mul_ps(vsf, vsa);
1479 vsf = _mm_insert_ps(vsf, vsa, 0x30);
1480 vsf = _mm_mul_ps(vsf, _mm_set1_ps(65535.0f));
1481 vsf = _mm_add_ps(vsf, _mm_set1_ps(0.5f));
1482 __m128i vsi = _mm_cvttps_epi32(vsf);
1483 vsi = _mm_packus_epi32(vsi, vsi);
1484 _mm_storel_epi64((__m128i *)(buffer + i), vsi);
1489void QT_FASTCALL storeRGB16FFromRGB32_avx2(uchar *dest,
const uint *src,
int index,
int count,
1490 const QList<QRgb> *, QDitherInfo *)
1492 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1493 const __m256 vf = _mm256_set1_ps(1.0f / 255.0f);
1495 for (; i + 1 < count; i += 2) {
1496 __m256i vsi = _mm256_cvtepu8_epi32(_mm_loadl_epi64((
const __m128i *)(src + i)));
1497 vsi = _mm256_shuffle_epi32(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1498 __m256 vsf = _mm256_cvtepi32_ps(vsi);
1499 vsf = _mm256_mul_ps(vsf, vf);
1500 _mm_storeu_si128((__m128i *)(d + i), _mm256_cvtps_ph(vsf, 0));
1503 __m128i vsi = _mm_cvtsi32_si128(src[i]);
1504 vsi = _mm_cvtepu8_epi32(vsi);
1505 vsi = _mm_shuffle_epi32(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1506 __m128 vsf = _mm_cvtepi32_ps(vsi);
1507 vsf = _mm_mul_ps(vsf, _mm_set1_ps(1.0f / 255.0f));
1508 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));
1512void QT_FASTCALL storeRGBA16FFromARGB32PM_avx2(uchar *dest,
const uint *src,
int index,
int count,
1513 const QList<QRgb> *, QDitherInfo *)
1515 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1516 const __m128 vf = _mm_set1_ps(1.0f / 255.0f);
1517 for (
int i = 0; i < count; ++i) {
1518 const uint s = src[i];
1519 __m128i vsi = _mm_cvtsi32_si128(s);
1520 vsi = _mm_cvtepu8_epi32(vsi);
1521 vsi = _mm_shuffle_epi32(vsi, _MM_SHUFFLE(3, 0, 1, 2));
1522 __m128 vsf = _mm_cvtepi32_ps(vsi);
1523 const uint8_t a = (s >> 24);
1525 vsf = _mm_mul_ps(vsf, vf);
1527 vsf = _mm_set1_ps(0.0f);
1529 const __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1530 __m128 vsr = _mm_rcp_ps(vsa);
1531 vsr = _mm_sub_ps(_mm_add_ps(vsr, vsr), _mm_mul_ps(vsr, _mm_mul_ps(vsr, vsa)));
1532 vsr = _mm_insert_ps(vsr, vf, 0x30);
1533 vsf = _mm_mul_ps(vsf, vsr);
1535 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));
1539#if QT_CONFIG(raster_fp)
1540const QRgbaFloat32 *QT_FASTCALL fetchRGBA16FToRGBA32F_avx2(QRgbaFloat32 *buffer,
const uchar *src,
int index,
int count,
1541 const QList<QRgb> *, QDitherInfo *)
1543 const quint64 *s =
reinterpret_cast<
const quint64 *>(src) + index;
1545 for (; i + 1 < count; i += 2) {
1546 __m256 vsf = _mm256_cvtph_ps(_mm_loadu_si128((
const __m128i *)(s + i)));
1547 __m256 vsa = _mm256_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1548 vsf = _mm256_mul_ps(vsf, vsa);
1549 vsf = _mm256_blend_ps(vsf, vsa, 0x88);
1550 _mm256_storeu_ps((
float *)(buffer + i), vsf);
1553 __m128 vsf = _mm_cvtph_ps(_mm_loadl_epi64((
const __m128i *)(s + i)));
1554 __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1555 vsf = _mm_mul_ps(vsf, vsa);
1556 vsf = _mm_insert_ps(vsf, vsa, 0x30);
1557 _mm_storeu_ps((
float *)(buffer + i), vsf);
1562void QT_FASTCALL storeRGBX16FFromRGBA32F_avx2(uchar *dest,
const QRgbaFloat32 *src,
int index,
int count,
1563 const QList<QRgb> *, QDitherInfo *)
1565 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1566 const __m128 *s =
reinterpret_cast<
const __m128 *>(src);
1567 const __m128 zero = _mm_set_ps(1.0f, 0.0f, 0.0f, 0.0f);
1568 for (
int i = 0; i < count; ++i) {
1569 __m128 vsf = _mm_loadu_ps(
reinterpret_cast<
const float *>(s + i));
1570 const __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1571 const float a = _mm_cvtss_f32(vsa);
1577 __m128 vsr = _mm_rcp_ps(vsa);
1578 vsr = _mm_sub_ps(_mm_add_ps(vsr, vsr), _mm_mul_ps(vsr, _mm_mul_ps(vsr, vsa)));
1579 vsf = _mm_mul_ps(vsf, vsr);
1580 vsf = _mm_insert_ps(vsf, _mm_set_ss(1.0f), 0x30);
1582 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));
1586void QT_FASTCALL storeRGBA16FFromRGBA32F_avx2(uchar *dest,
const QRgbaFloat32 *src,
int index,
int count,
1587 const QList<QRgb> *, QDitherInfo *)
1589 quint64 *d =
reinterpret_cast<quint64 *>(dest) + index;
1590 const __m128 *s =
reinterpret_cast<
const __m128 *>(src);
1591 const __m128 zero = _mm_set1_ps(0.0f);
1592 for (
int i = 0; i < count; ++i) {
1593 __m128 vsf = _mm_loadu_ps(
reinterpret_cast<
const float *>(s + i));
1594 const __m128 vsa = _mm_permute_ps(vsf, _MM_SHUFFLE(3, 3, 3, 3));
1595 const float a = _mm_cvtss_f32(vsa);
1601 __m128 vsr = _mm_rcp_ps(vsa);
1602 vsr = _mm_sub_ps(_mm_add_ps(vsr, vsr), _mm_mul_ps(vsr, _mm_mul_ps(vsr, vsa)));
1603 vsr = _mm_insert_ps(vsr, _mm_set_ss(1.0f), 0x30);
1604 vsf = _mm_mul_ps(vsf, vsr);
1606 _mm_storel_epi64((__m128i *)(d + i), _mm_cvtps_ph(vsf, 0));