summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qdrawhelper_arm_simd.cpp
blob: 2a5f5e430279a654cc26c01d74f1138bb9c609c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdrawhelper_arm_simd_p.h"

#include <private/qpaintengine_raster_p.h>
#include <private/qblendfunctions_p.h>

#ifdef QT_HAVE_ARM_SIMD

#if defined(Q_OS_SYMBIAN)
#if !defined(__SWITCH_TO_ARM)
#ifdef __MARM_THUMB__
#ifndef __ARMCC__
#define __SWITCH_TO_ARM      asm("push {r0} ");\
                             asm("add r0, pc, #4 ");\
                             asm("bx r0 ");\
                             asm("nop ");\
                             asm(".align 2 ");\
                             asm(".code 32 ");\
                             asm("ldr r0, [sp], #4 ")
#define __END_ARM            asm(".code 16 ")
#else
#define __SWITCH_TO_ARM      asm(".code 32 ");
#define __END_ARM
#endif // __ARMCC__
#else
#define __SWITCH_TO_ARM
#define __END_ARM
#endif //__MARM_THUMB__
#endif
#endif

#if defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)
__asm void qt_blend_argb32_on_argb32_arm_simd(uchar *destPixels, int dbpl,
                                        const uchar *srcPixels, int sbpl,
                                        int w, int h,
                                        int const_alpha)
{
#ifndef __ARMCC__
    __SWITCH_TO_ARM;
#else
    CODE32
#endif // __ARMCC__

    stmfd   sp!, {r4-r12, r14}

    // read arguments off the stack
    add     r8, sp, #10 * 4
    ldmia   r8, {r4-r6}

    // adjust dbpl and sbpl
    mov     r14, #4
    mul     r14, r4, r14
    sub     r1, r1, r14
    sub     r3, r3, r14

    // load 0xFF00FF00 to r12
    mov     r12, #0xFF000000
    add     r12, r12, #0xFF00

    // load 0x800080 to r14
    mov     r14, #0x800000
    add     r14, r14, #0x80

    /*
      Registers:
       r0 dst
       r1 dbpl
       r2 src
       r3 sbpl
       r4 w
       r5 h
       r6 const_alpha
       r12 0xFF0000
       r14 0x800080
    */

    cmp     r6, #256 //test if we have fully opaque constant alpha value
    bne     argb32constalpha // branch if not

argb32_next_row

    mov     r7, r4

argb32_next_pixel

    ldr     r8, [r2], #4 // load src pixel

    // Negate r8 and extract src alpha
    mvn     r11, r8 // bitwise not
    uxtb    r11, r11, ror #24

    cmp     r11, #0 // test for full src opacity (negated)
    beq     argb32_no_blend

    cmp     r11, #255 // test for full src transparency (negated)
    addeq   r0, #4
    beq     argb32_nop

    ldr     r9, [r0] // load dst pixel

    // blend
    uxtb16  r10, r9
    uxtb16  r6, r9, ror #8
    mla     r10, r11, r10, r14
    mla     r9, r6, r11, r14
    uxtab16 r10, r10, r10, ror #8
    uxtab16 r9, r9, r9, ror #8
    and     r9, r9, r12
    uxtab16 r10, r9, r10, ror #8

    uqadd8  r8, r10, r8

argb32_no_blend

    str     r8, [r0], #4

argb32_nop

    subs    r7, r7, #1
    bgt     argb32_next_pixel

    add     r0, r0, r1 // dest = dest + dbpl
    add     r2, r2, r3 // src = src + sbpl

    subs    r5, r5, #1
    bgt     argb32_next_row

    b       argb32_blend_exit

argb32constalpha

    cmp     r6, #0
    beq     argb32_blend_exit

    ; const_alpha = (const_alpha * 255) >> 8;
    mov     r11, #255
    mul     r6, r6, r11
    mov     r11, r6, lsr #8

argb32constalpha_next_row

    mov     r7, r4

argb32constalpha_next_pixel

    ldr     r9, [r2], #4 // load src pixel

    // blend
    uxtb16  r10, r9
    uxtb16  r6, r9, ror #8
    mla     r10, r11, r10, r14
    mla     r9, r6, r11, r14
    uxtab16 r10, r10, r10, ror #8
    uxtab16 r9, r9, r9, ror #8
    and     r9, r9, r12
    uxtab16 r8, r9, r10, ror #8

    ldr     r9, [r0] // load dst pixel

    // blend
    uxtb16  r10, r9
    uxtb16  r6, r9, ror #8

    // Negate r11 and extract src alpha
    mvn     r9, r11 // bitwise not
    uxtb    r9, r9, ror #24

    mla     r10, r9, r10, r14
    mla     r9, r6, r9, r14
    uxtab16 r10, r10, r10, ror #8
    uxtab16 r9, r9, r9, ror #8
    and     r9, r9, r12
    uxtab16 r10, r9, r10, ror #8

    uqadd8  r8, r10, r8

    str     r8, [r0], #4

    subs    r7, r7, #1
    bgt     argb32constalpha_next_pixel

    add     r0, r0, r1 // dest = dest + dbpl
    add     r2, r2, r3 // src = src + sbpl

    subs    r5, r5, #1
    bgt     argb32constalpha_next_row

argb32_blend_exit

    // Restore registers
    ldmfd   sp!, {r4-r12, lr}
    bx      lr

    __END_ARM
}

void qt_blend_rgb32_on_rgb32_arm_simd(uchar *destPixels, int dbpl,
                             const uchar *srcPixels, int sbpl,
                             int w, int h,
                             int const_alpha)
{
    if (const_alpha != 256) {
        qt_blend_argb32_on_argb32_arm_simd(destPixels, dbpl, srcPixels, sbpl, w, h, const_alpha);
        return;
    }

    const uint *src = (const uint *) srcPixels;
    uint *dst = (uint *) destPixels;
    if (w <= 64) {
        for (int y=0; y<h; ++y) {
            qt_memconvert(dst, src, w);
            dst = (quint32 *)(((uchar *) dst) + dbpl);
            src = (const quint32 *)(((const uchar *) src) + sbpl);
        }
    } else {
        int len = w * 4;
        for (int y=0; y<h; ++y) {
            memcpy(dst, src, len);
            dst = (quint32 *)(((uchar *) dst) + dbpl);
            src = (const quint32 *)(((const uchar *) src) + sbpl);
        }
    }
}

#else // defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)

// TODO: add GNU assembler instructions and support for other platforms.
//       Default to C code for now

void qt_blend_argb32_on_argb32_arm_simd(uchar *destPixels, int dbpl,
                                        const uchar *srcPixels, int sbpl,
                                        int w, int h,
                                        int const_alpha)
{
    const uint *src = (const uint *) srcPixels;
    uint *dst = (uint *) destPixels;
    if (const_alpha == 256) {
        for (int y=0; y<h; ++y) {
            for (int x=0; x<w; ++x) {
                uint s = src[x];
                if (s >= 0xff000000)
                    dst[x] = s;
                else if (s != 0)
                    dst[x] = s + BYTE_MUL(dst[x], qAlpha(~s));
            }
            dst = (quint32 *)(((uchar *) dst) + dbpl);
            src = (const quint32 *)(((const uchar *) src) + sbpl);
        }
    } else if (const_alpha != 0) {
        const_alpha = (const_alpha * 255) >> 8;
        for (int y=0; y<h; ++y) {
            for (int x=0; x<w; ++x) {
                uint s = BYTE_MUL(src[x], const_alpha);
                dst[x] = s + BYTE_MUL(dst[x], qAlpha(~s));
            }
            dst = (quint32 *)(((uchar *) dst) + dbpl);
            src = (const quint32 *)(((const uchar *) src) + sbpl);
        }
    }
}

void qt_blend_rgb32_on_rgb32_arm_simd(uchar *destPixels, int dbpl,
                             const uchar *srcPixels, int sbpl,
                             int w, int h,
                             int const_alpha)
{
    if (const_alpha != 256) {
        qt_blend_argb32_on_argb32_arm_simd(destPixels, dbpl, srcPixels, sbpl, w, h, const_alpha);
        return;
    }

    const uint *src = (const uint *) srcPixels;
    uint *dst = (uint *) destPixels;
    if (w <= 64) {
        for (int y=0; y<h; ++y) {
            qt_memconvert(dst, src, w);
            dst = (quint32 *)(((uchar *) dst) + dbpl);
            src = (const quint32 *)(((const uchar *) src) + sbpl);
        }
    } else {
        int len = w * 4;
        for (int y=0; y<h; ++y) {
            memcpy(dst, src, len);
            dst = (quint32 *)(((uchar *) dst) + dbpl);
            src = (const quint32 *)(((const uchar *) src) + sbpl);
        }
    }
}

#endif

#endif // QT_HAVE_ARMV_SIMD