source: trunk/src/gui/painting/qdrawhelper_sse_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QDRAWHELPER_SSE_P_H
43#define QDRAWHELPER_SSE_P_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists purely as an
50// implementation detail. This header file may change from version to
51// version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include <private/qdrawhelper_mmx_p.h>
57
58#ifdef QT_HAVE_SSE
59
60#ifdef QT_LINUXBASE
61// this is an evil hack - the posix_memalign declaration in LSB
62// is wrong - see http://bugs.linuxbase.org/show_bug.cgi?id=2431
63# define posix_memalign _lsb_hack_posix_memalign
64# include <xmmintrin.h>
65# undef posix_memalign
66#else
67# include <xmmintrin.h>
68#endif
69
70QT_BEGIN_NAMESPACE
71
72#ifndef _MM_SHUFFLE
73#define _MM_SHUFFLE(fp3,fp2,fp1,fp0) \
74 (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | (fp0))
75#endif
76
77struct QSSEIntrinsics : public QMMXIntrinsics
78{
79 static inline m64 alpha(m64 x) {
80 return _mm_shuffle_pi16 (x, _MM_SHUFFLE(3, 3, 3, 3));
81 }
82
83 static inline m64 _load_alpha(uint x, const m64 &mmx_0x0000) {
84 m64 t = _mm_unpacklo_pi8(_mm_cvtsi32_si64(x), mmx_0x0000);
85 return _mm_shuffle_pi16 (t, _MM_SHUFFLE(0, 0, 0, 0));
86 }
87};
88
89template <class MM>
90inline void qt_memfill32_sse_template(quint32 *dest, quint32 value, int count)
91{
92 if (count < 7) {
93 switch (count) {
94 case 6: *dest++ = value;
95 case 5: *dest++ = value;
96 case 4: *dest++ = value;
97 case 3: *dest++ = value;
98 case 2: *dest++ = value;
99 case 1: *dest = value;
100 }
101 return;
102 };
103
104 __m64 *dst64 = reinterpret_cast<__m64*>(dest);
105 const __m64 value64 = _mm_set_pi32(value, value);
106 int count64 = count / 2;
107
108 int n = (count64 + 3) / 4;
109 switch (count64 & 0x3) {
110 case 0: do { _mm_stream_pi(dst64++, value64);
111 case 3: _mm_stream_pi(dst64++, value64);
112 case 2: _mm_stream_pi(dst64++, value64);
113 case 1: _mm_stream_pi(dst64++, value64);
114 } while (--n > 0);
115 }
116
117 if (count & 0x1)
118 dest[count - 1] = value;
119
120 MM::end();
121}
122
123template <class MM>
124inline void qt_bitmapblit16_sse_template(QRasterBuffer *rasterBuffer,
125 int x, int y,
126 quint32 color,
127 const uchar *src,
128 int width, int height, int stride)
129{
130 const quint16 c = qt_colorConvert<quint16, quint32>(color, 0);
131 quint16 *dest = reinterpret_cast<quint16*>(rasterBuffer->scanLine(y)) + x;
132 const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint16);
133
134 const __m64 c64 = _mm_set1_pi16(c);
135#ifdef Q_CC_MSVC
136# pragma warning(disable: 4309) // truncation of constant value
137#endif
138 const __m64 maskmask1 = _mm_set_pi16(0x1010, 0x2020, 0x4040, 0x8080);
139 const __m64 maskadd1 = _mm_set_pi16(0x7070, 0x6060, 0x4040, 0x0000);
140
141 if (width > 4) {
142 const __m64 maskmask2 = _mm_set_pi16(0x0101, 0x0202, 0x0404, 0x0808);
143 const __m64 maskadd2 = _mm_set_pi16(0x7f7f, 0x7e7e, 0x7c7c, 0x7878);
144
145 while (height--) {
146 for (int x = 0; x < width; x += 8) {
147 const quint8 s = src[x >> 3];
148 if (!s)
149 continue;
150 __m64 mask1 = _mm_set1_pi8(s);
151 __m64 mask2 = mask1;
152 mask1 = _m_pand(mask1, maskmask1);
153 mask1 = _mm_add_pi16(mask1, maskadd1);
154 _mm_maskmove_si64(c64, mask1, (char*)(dest + x));
155 mask2 = _m_pand(mask2, maskmask2);
156 mask2 = _mm_add_pi16(mask2, maskadd2);
157 _mm_maskmove_si64(c64, mask2, (char*)(dest + x + 4));
158 }
159 dest += destStride;
160 src += stride;
161 }
162 } else {
163 while (height--) {
164 const quint8 s = *src;
165 if (s) {
166 __m64 mask1 = _mm_set1_pi8(s);
167 mask1 = _m_pand(mask1, maskmask1);
168 mask1 = _mm_add_pi16(mask1, maskadd1);
169 _mm_maskmove_si64(c64, mask1, (char*)(dest));
170 }
171 dest += destStride;
172 src += stride;
173 }
174 }
175
176 MM::end();
177}
178
179QT_END_NAMESPACE
180
181#endif // QT_HAVE_SSE
182#endif // QDRAWHELPER_SSE_P_H
Note: See TracBrowser for help on using the repository browser.