Coverage Report

Created: 2026-07-25 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/painting/qimagescale_sse4.cpp
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#include "qimagescale_p.h"
6
#include "qimage.h"
7
#include <private/qdrawhelper_x86_p.h>
8
#include <private/qsimd_p.h>
9
10
#if defined(QT_COMPILER_SUPPORTS_SSE4_1)
11
12
QT_BEGIN_NAMESPACE
13
14
using namespace QImageScale;
15
16
inline static __m128i Q_DECL_VECTORCALL
17
qt_qimageScaleAARGBA_helper(const unsigned int *pix, int xyap, int Cxy, int step, const __m128i vxyap, const __m128i vCxy)
18
0
{
19
0
    __m128i vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
20
0
    __m128i vx = _mm_mullo_epi32(vpix, vxyap);
21
0
    int i;
22
0
    for (i = (1 << 14) - xyap; i > Cxy; i -= Cxy) {
23
0
        pix += step;
24
0
        vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
25
0
        vx = _mm_add_epi32(vx, _mm_mullo_epi32(vpix, vCxy));
26
0
    }
27
0
    pix += step;
28
0
    vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
29
0
    vx = _mm_add_epi32(vx, _mm_mullo_epi32(vpix, _mm_set1_epi32(i)));
30
0
    return vx;
31
0
}
32
33
template<bool RGB>
34
void qt_qimageScaleAARGBA_up_x_down_y_sse4(QImageScaleInfo *isi, unsigned int *dest,
35
                                           int dw, int dh, int dow, int sow)
36
0
{
37
0
    const unsigned int **ypoints = isi->ypoints;
38
0
    const int *xpoints = isi->xpoints;
39
0
    const int *xapoints = isi->xapoints;
40
0
    const int *yapoints = isi->yapoints;
41
42
0
    const __m128i v256 = _mm_set1_epi32(256);
43
44
    /* go through every scanline in the output buffer */
45
0
    auto scaleSection = [&] (int yStart, int yEnd) {
46
0
        for (int y = yStart; y < yEnd; ++y) {
47
0
            const int Cy = yapoints[y] >> 16;
48
0
            const int yap = yapoints[y] & 0xffff;
49
0
            const __m128i vCy = _mm_set1_epi32(Cy);
50
0
            const __m128i vyap = _mm_set1_epi32(yap);
51
52
0
            unsigned int *dptr = dest + (y * dow);
53
0
            for (int x = 0; x < dw; x++) {
54
0
                const unsigned int *sptr = ypoints[y] + xpoints[x];
55
0
                __m128i vx = qt_qimageScaleAARGBA_helper(sptr, yap, Cy, sow, vyap, vCy);
56
57
0
                const int xap = xapoints[x];
58
0
                if (xap > 0) {
59
0
                    const __m128i vxap = _mm_set1_epi32(xap);
60
0
                    const __m128i vinvxap = _mm_sub_epi32(v256, vxap);
61
0
                    __m128i vr = qt_qimageScaleAARGBA_helper(sptr + 1, yap, Cy, sow, vyap, vCy);
62
63
0
                    vx = _mm_mullo_epi32(vx, vinvxap);
64
0
                    vr = _mm_mullo_epi32(vr, vxap);
65
0
                    vx = _mm_add_epi32(vx, vr);
66
0
                    vx = _mm_srli_epi32(vx, 8);
67
0
                }
68
0
                vx = _mm_srli_epi32(vx, 14);
69
0
                vx = _mm_packus_epi32(vx, vx);
70
0
                vx = _mm_packus_epi16(vx, vx);
71
0
                *dptr = _mm_cvtsi128_si32(vx);
72
0
                if (RGB)
73
0
                    *dptr |= 0xff000000;
74
0
                dptr++;
75
0
            }
76
0
        }
77
0
    };
Unexecuted instantiation: qt_qimageScaleAARGBA_up_x_down_y_sse4<false>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)::{lambda(int, int)#1}::operator()(int, int) const
Unexecuted instantiation: qt_qimageScaleAARGBA_up_x_down_y_sse4<true>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)::{lambda(int, int)#1}::operator()(int, int) const
78
0
    multithread_pixels_function(isi, dh, scaleSection);
79
0
}
Unexecuted instantiation: void qt_qimageScaleAARGBA_up_x_down_y_sse4<false>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)
Unexecuted instantiation: void qt_qimageScaleAARGBA_up_x_down_y_sse4<true>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)
80
81
template<bool RGB>
82
void qt_qimageScaleAARGBA_down_x_up_y_sse4(QImageScaleInfo *isi, unsigned int *dest,
83
                                           int dw, int dh, int dow, int sow)
84
0
{
85
0
    const unsigned int **ypoints = isi->ypoints;
86
0
    int *xpoints = isi->xpoints;
87
0
    int *xapoints = isi->xapoints;
88
0
    int *yapoints = isi->yapoints;
89
90
0
    const __m128i v256 = _mm_set1_epi32(256);
91
92
    /* go through every scanline in the output buffer */
93
0
    auto scaleSection = [&] (int yStart, int yEnd) {
94
0
        for (int y = yStart; y < yEnd; ++y) {
95
0
            unsigned int *dptr = dest + (y * dow);
96
0
            for (int x = 0; x < dw; x++) {
97
0
                int Cx = xapoints[x] >> 16;
98
0
                int xap = xapoints[x] & 0xffff;
99
0
                const __m128i vCx = _mm_set1_epi32(Cx);
100
0
                const __m128i vxap = _mm_set1_epi32(xap);
101
102
0
                const unsigned int *sptr = ypoints[y] + xpoints[x];
103
0
                __m128i vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1, vxap, vCx);
104
105
0
                int yap = yapoints[y];
106
0
                if (yap > 0) {
107
0
                    const __m128i vyap = _mm_set1_epi32(yap);
108
0
                    const __m128i vinvyap = _mm_sub_epi32(v256, vyap);
109
0
                    __m128i vr = qt_qimageScaleAARGBA_helper(sptr + sow, xap, Cx, 1, vxap, vCx);
110
111
0
                    vx = _mm_mullo_epi32(vx, vinvyap);
112
0
                    vr = _mm_mullo_epi32(vr, vyap);
113
0
                    vx = _mm_add_epi32(vx, vr);
114
0
                    vx = _mm_srli_epi32(vx, 8);
115
0
                }
116
0
                vx = _mm_srli_epi32(vx, 14);
117
0
                vx = _mm_packus_epi32(vx, vx);
118
0
                vx = _mm_packus_epi16(vx, vx);
119
0
                *dptr = _mm_cvtsi128_si32(vx);
120
0
                if (RGB)
121
0
                    *dptr |= 0xff000000;
122
0
                dptr++;
123
0
            }
124
0
        }
125
0
    };
Unexecuted instantiation: qt_qimageScaleAARGBA_down_x_up_y_sse4<false>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)::{lambda(int, int)#1}::operator()(int, int) const
Unexecuted instantiation: qt_qimageScaleAARGBA_down_x_up_y_sse4<true>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)::{lambda(int, int)#1}::operator()(int, int) const
126
0
    multithread_pixels_function(isi, dh, scaleSection);
127
0
}
Unexecuted instantiation: void qt_qimageScaleAARGBA_down_x_up_y_sse4<false>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)
Unexecuted instantiation: void qt_qimageScaleAARGBA_down_x_up_y_sse4<true>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)
128
129
template<bool RGB>
130
void qt_qimageScaleAARGBA_down_xy_sse4(QImageScaleInfo *isi, unsigned int *dest,
131
                                       int dw, int dh, int dow, int sow)
132
0
{
133
0
    const unsigned int **ypoints = isi->ypoints;
134
0
    int *xpoints = isi->xpoints;
135
0
    int *xapoints = isi->xapoints;
136
0
    int *yapoints = isi->yapoints;
137
138
0
    auto scaleSection = [&] (int yStart, int yEnd) {
139
0
        for (int y = yStart; y < yEnd; ++y) {
140
0
            int Cy = yapoints[y] >> 16;
141
0
            int yap = yapoints[y] & 0xffff;
142
0
            const __m128i vCy = _mm_set1_epi32(Cy);
143
0
            const __m128i vyap = _mm_set1_epi32(yap);
144
145
0
            unsigned int *dptr = dest + (y * dow);
146
0
            for (int x = 0; x < dw; x++) {
147
0
                const int Cx = xapoints[x] >> 16;
148
0
                const int xap = xapoints[x] & 0xffff;
149
0
                const __m128i vCx = _mm_set1_epi32(Cx);
150
0
                const __m128i vxap = _mm_set1_epi32(xap);
151
152
0
                const unsigned int *sptr = ypoints[y] + xpoints[x];
153
0
                __m128i vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1, vxap, vCx);
154
0
                __m128i vr = _mm_mullo_epi32(_mm_srli_epi32(vx, 4), vyap);
155
156
0
                int j;
157
0
                for (j = (1 << 14) - yap; j > Cy; j -= Cy) {
158
0
                    sptr += sow;
159
0
                    vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1, vxap, vCx);
160
0
                    vr = _mm_add_epi32(vr, _mm_mullo_epi32(_mm_srli_epi32(vx, 4), vCy));
161
0
                }
162
0
                sptr += sow;
163
0
                vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1, vxap, vCx);
164
0
                vr = _mm_add_epi32(vr, _mm_mullo_epi32(_mm_srli_epi32(vx, 4), _mm_set1_epi32(j)));
165
166
0
                vr = _mm_srli_epi32(vr, 24);
167
0
                vr = _mm_packus_epi32(vr, _mm_setzero_si128());
168
0
                vr = _mm_packus_epi16(vr, _mm_setzero_si128());
169
0
                *dptr = _mm_cvtsi128_si32(vr);
170
0
                if (RGB)
171
0
                    *dptr |= 0xff000000;
172
0
                dptr++;
173
0
            }
174
0
        }
175
0
    };
Unexecuted instantiation: qt_qimageScaleAARGBA_down_xy_sse4<false>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)::{lambda(int, int)#1}::operator()(int, int) const
Unexecuted instantiation: qt_qimageScaleAARGBA_down_xy_sse4<true>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)::{lambda(int, int)#1}::operator()(int, int) const
176
0
    multithread_pixels_function(isi, dh, scaleSection);
177
0
}
Unexecuted instantiation: void qt_qimageScaleAARGBA_down_xy_sse4<false>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)
Unexecuted instantiation: void qt_qimageScaleAARGBA_down_xy_sse4<true>(QImageScale::QImageScaleInfo*, unsigned int*, int, int, int, int)
178
179
template void qt_qimageScaleAARGBA_up_x_down_y_sse4<false>(QImageScaleInfo *isi, unsigned int *dest,
180
                                                           int dw, int dh, int dow, int sow);
181
182
template void qt_qimageScaleAARGBA_up_x_down_y_sse4<true>(QImageScaleInfo *isi, unsigned int *dest,
183
                                                          int dw, int dh, int dow, int sow);
184
185
template void qt_qimageScaleAARGBA_down_x_up_y_sse4<false>(QImageScaleInfo *isi, unsigned int *dest,
186
                                                           int dw, int dh, int dow, int sow);
187
188
template void qt_qimageScaleAARGBA_down_x_up_y_sse4<true>(QImageScaleInfo *isi, unsigned int *dest,
189
                                                          int dw, int dh, int dow, int sow);
190
191
template void qt_qimageScaleAARGBA_down_xy_sse4<false>(QImageScaleInfo *isi, unsigned int *dest,
192
                                                       int dw, int dh, int dow, int sow);
193
194
template void qt_qimageScaleAARGBA_down_xy_sse4<true>(QImageScaleInfo *isi, unsigned int *dest,
195
                                                      int dw, int dh, int dow, int sow);
196
197
QT_END_NAMESPACE
198
199
#endif