File: GraphicsContext3DNEON.h

package info (click to toggle)
qtwebkit 2.3.4.dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 290,116 kB
  • ctags: 272,544
  • sloc: cpp: 1,417,496; python: 85,048; ansic: 39,353; perl: 38,858; ruby: 10,313; objc: 9,505; xml: 8,679; asm: 3,864; yacc: 2,458; sh: 1,237; lex: 813; makefile: 592; java: 228; php: 79
file content (183 lines) | stat: -rw-r--r-- 7,909 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (C) 2012 Gabor Rapcsanyi (rgabor@inf.u-szeged.hu), University of Szeged
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef GraphicsContext3DNEON_h
#define GraphicsContext3DNEON_h

#if HAVE(ARM_NEON_INTRINSICS)

#include <arm_neon.h>

namespace WebCore {

namespace ARM {

ALWAYS_INLINE void unpackOneRowOfRGBA4444ToRGBA8NEON(const uint16_t* source, uint8_t* destination, unsigned pixelSize)
{
    uint16x8_t immediate0x0f = vdupq_n_u16(0x0F);
    for (unsigned i = 0; i < pixelSize; i += 8) {
        uint16x8_t eightPixels = vld1q_u16(source + i);

        uint8x8_t componentR = vqmovn_u16(vshrq_n_u16(eightPixels, 12));
        uint8x8_t componentG = vqmovn_u16(vandq_u16(vshrq_n_u16(eightPixels, 8), immediate0x0f));
        uint8x8_t componentB = vqmovn_u16(vandq_u16(vshrq_n_u16(eightPixels, 4), immediate0x0f));
        uint8x8_t componentA = vqmovn_u16(vandq_u16(eightPixels, immediate0x0f));

        componentR = vorr_u8(vshl_n_u8(componentR, 4), componentR);
        componentG = vorr_u8(vshl_n_u8(componentG, 4), componentG);
        componentB = vorr_u8(vshl_n_u8(componentB, 4), componentB);
        componentA = vorr_u8(vshl_n_u8(componentA, 4), componentA);

        uint8x8x4_t destComponents = {{componentR, componentG, componentB, componentA}};
        vst4_u8(destination, destComponents);
        destination += 32;
    }
}

ALWAYS_INLINE void packOneRowOfRGBA8ToUnsignedShort4444NEON(const uint8_t* source, uint16_t* destination, unsigned componentsSize)
{
    uint8_t* dst = reinterpret_cast<uint8_t*>(destination);
    uint8x8_t immediate0xf0 = vdup_n_u8(0xF0);
    for (unsigned i = 0; i < componentsSize; i += 32) {
        uint8x8x4_t RGBA8 = vld4_u8(source + i);

        uint8x8_t componentR = vand_u8(RGBA8.val[0], immediate0xf0);
        uint8x8_t componentG = vshr_n_u8(vand_u8(RGBA8.val[1], immediate0xf0), 4);
        uint8x8_t componentB = vand_u8(RGBA8.val[2], immediate0xf0);
        uint8x8_t componentA = vshr_n_u8(vand_u8(RGBA8.val[3], immediate0xf0), 4);

        uint8x8x2_t RGBA4;
        RGBA4.val[0] = vorr_u8(componentB, componentA);
        RGBA4.val[1] = vorr_u8(componentR, componentG);
        vst2_u8(dst, RGBA4);
        dst += 16;
    }
}

ALWAYS_INLINE void unpackOneRowOfRGBA5551ToRGBA8NEON(const uint16_t* source, uint8_t* destination, unsigned pixelSize)
{
    uint8x8_t immediate0x7 = vdup_n_u8(0x7);
    uint8x8_t immediate0xff = vdup_n_u8(0xFF);
    uint16x8_t immediate0x1f = vdupq_n_u16(0x1F);
    uint16x8_t immediate0x1 = vdupq_n_u16(0x1);

    for (unsigned i = 0; i < pixelSize; i += 8) {
        uint16x8_t eightPixels = vld1q_u16(source + i);

        uint8x8_t componentR = vqmovn_u16(vshrq_n_u16(eightPixels, 11));
        uint8x8_t componentG = vqmovn_u16(vandq_u16(vshrq_n_u16(eightPixels, 6), immediate0x1f));
        uint8x8_t componentB = vqmovn_u16(vandq_u16(vshrq_n_u16(eightPixels, 1), immediate0x1f));
        uint8x8_t componentA = vqmovn_u16(vandq_u16(eightPixels, immediate0x1));

        componentR = vorr_u8(vshl_n_u8(componentR, 3), vand_u8(componentR, immediate0x7));
        componentG = vorr_u8(vshl_n_u8(componentG, 3), vand_u8(componentG, immediate0x7));
        componentB = vorr_u8(vshl_n_u8(componentB, 3), vand_u8(componentB, immediate0x7));
        componentA = vmul_u8(componentA, immediate0xff);

        uint8x8x4_t destComponents = {{componentR, componentG, componentB, componentA}};
        vst4_u8(destination, destComponents);
        destination += 32;
    }
}

ALWAYS_INLINE void packOneRowOfRGBA8ToUnsignedShort5551NEON(const uint8_t* source, uint16_t* destination, unsigned componentsSize)
{
    uint8_t* dst = reinterpret_cast<uint8_t*>(destination);

    uint8x8_t immediate0xf8 = vdup_n_u8(0xF8);
    uint8x8_t immediate0x18 = vdup_n_u8(0x18);
    for (unsigned i = 0; i < componentsSize; i += 32) {
        uint8x8x4_t RGBA8 = vld4_u8(source + i);

        uint8x8_t componentR = vand_u8(RGBA8.val[0], immediate0xf8);
        uint8x8_t componentG3bit = vshr_n_u8(RGBA8.val[1], 5);

        uint8x8_t componentG2bit = vshl_n_u8(vand_u8(RGBA8.val[1], immediate0x18), 3);
        uint8x8_t componentB = vshr_n_u8(vand_u8(RGBA8.val[2], immediate0xf8), 2);
        uint8x8_t componentA = vshr_n_u8(RGBA8.val[3], 7);

        uint8x8x2_t RGBA5551;
        RGBA5551.val[0] = vorr_u8(vorr_u8(componentG2bit, componentB), componentA);
        RGBA5551.val[1] = vorr_u8(componentR, componentG3bit);
        vst2_u8(dst, RGBA5551);
        dst += 16;
    }
}

ALWAYS_INLINE void unpackOneRowOfRGB565ToRGBA8NEON(const uint16_t* source, uint8_t* destination, unsigned pixelSize)
{
    uint16x8_t immediate0x3f = vdupq_n_u16(0x3F);
    uint16x8_t immediate0x1f = vdupq_n_u16(0x1F);
    uint8x8_t immediate0x3 = vdup_n_u8(0x3);
    uint8x8_t immediate0x7 = vdup_n_u8(0x7);

    uint8x8_t componentA = vdup_n_u8(0xFF);

    for (unsigned i = 0; i < pixelSize; i += 8) {
        uint16x8_t eightPixels = vld1q_u16(source + i);

        uint8x8_t componentR = vqmovn_u16(vshrq_n_u16(eightPixels, 11));
        uint8x8_t componentG = vqmovn_u16(vandq_u16(vshrq_n_u16(eightPixels, 5), immediate0x3f));
        uint8x8_t componentB = vqmovn_u16(vandq_u16(eightPixels, immediate0x1f));

        componentR = vorr_u8(vshl_n_u8(componentR, 3), vand_u8(componentR, immediate0x7));
        componentG = vorr_u8(vshl_n_u8(componentG, 2), vand_u8(componentG, immediate0x3));
        componentB = vorr_u8(vshl_n_u8(componentB, 3), vand_u8(componentB, immediate0x7));

        uint8x8x4_t destComponents = {{componentR, componentG, componentB, componentA}};
        vst4_u8(destination, destComponents);
        destination += 32;
    }
}

ALWAYS_INLINE void packOneRowOfRGBA8ToUnsignedShort565NEON(const uint8_t* source, uint16_t* destination, unsigned componentsSize)
{
    uint8_t* dst = reinterpret_cast<uint8_t*>(destination);

    uint8x8_t immediate0xf8 = vdup_n_u8(0xF8);
    uint8x8_t immediate0x1c = vdup_n_u8(0x1C);
    for (unsigned i = 0; i < componentsSize; i += 32) {
        uint8x8x4_t RGBA8 = vld4_u8(source + i);

        uint8x8_t componentR = vand_u8(RGBA8.val[0], immediate0xf8);
        uint8x8_t componentGLeft = vshr_n_u8(RGBA8.val[1], 5);
        uint8x8_t componentGRight = vshl_n_u8(vand_u8(RGBA8.val[1], immediate0x1c), 3);
        uint8x8_t componentB = vshr_n_u8(vand_u8(RGBA8.val[2], immediate0xf8), 3);

        uint8x8x2_t RGB565;
        RGB565.val[0] = vorr_u8(componentGRight, componentB);
        RGB565.val[1] = vorr_u8(componentR, componentGLeft);
        vst2_u8(dst, RGB565);
        dst += 16;
    }
}

} // namespace ARM

} // namespace WebCore

#endif // HAVE(ARM_NEON_INTRINSICS)

#endif // GraphicsContext3DNEON_h