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
|
/* FreeRDP: A Remote Desktop Protocol Client
* Optimized routines to set a chunk of memory to a constant.
* vi:ts=4 sw=4:
*
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*
*/
#include <freerdp/config.h>
#include <string.h>
#include <freerdp/types.h>
#include <freerdp/primitives.h>
#include <winpr/sysinfo.h>
#ifdef WITH_SSE2
#include <emmintrin.h>
#endif /* WITH_SSE2 */
#ifdef WITH_IPP
#include <ipps.h>
#endif /* WITH_IPP */
#include "prim_internal.h"
static primitives_t* generic = NULL;
/* ========================================================================= */
#ifdef WITH_SSE2
#if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS)
static pstatus_t sse2_set_8u(BYTE val, BYTE* WINPR_RESTRICT pDst, UINT32 len)
{
BYTE byte = 0;
BYTE* dptr = NULL;
__m128i xmm0;
size_t count = 0;
if (len < 16)
return generic->set_8u(val, pDst, len);
byte = val;
dptr = (BYTE*)pDst;
/* Seek 16-byte alignment. */
while ((ULONG_PTR)dptr & 0x0f)
{
*dptr++ = byte;
if (--len == 0)
return PRIMITIVES_SUCCESS;
}
xmm0 = _mm_set1_epi8(byte);
/* Cover 256-byte chunks via SSE register stores. */
count = len >> 8;
len -= count << 8;
/* Do 256-byte chunks using one XMM register. */
while (count--)
{
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
}
/* Cover 16-byte chunks via SSE register stores. */
count = len >> 4;
len -= count << 4;
/* Do 16-byte chunks using one XMM register. */
while (count--)
{
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 16;
}
/* Do leftover bytes. */
while (len--)
*dptr++ = byte;
return PRIMITIVES_SUCCESS;
}
#endif /* !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) */
#endif /* WITH_SSE2 */
/* ------------------------------------------------------------------------- */
#ifdef WITH_SSE2
#if !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS)
static pstatus_t sse2_set_32u(UINT32 val, UINT32* WINPR_RESTRICT pDst, UINT32 len)
{
const primitives_t* prim = primitives_get_generic();
UINT32* dptr = (UINT32*)pDst;
__m128i xmm0;
size_t count = 0;
/* If really short, just do it here. */
if (len < 32)
{
while (len--)
*dptr++ = val;
return PRIMITIVES_SUCCESS;
}
/* Assure we can reach 16-byte alignment. */
if (((ULONG_PTR)dptr & 0x03) != 0)
{
return prim->set_32u(val, pDst, len);
}
/* Seek 16-byte alignment. */
while ((ULONG_PTR)dptr & 0x0f)
{
*dptr++ = val;
if (--len == 0)
return PRIMITIVES_SUCCESS;
}
xmm0 = _mm_set1_epi32(val);
/* Cover 256-byte chunks via SSE register stores. */
count = len >> 6;
len -= count << 6;
/* Do 256-byte chunks using one XMM register. */
while (count--)
{
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
}
/* Cover 16-byte chunks via SSE register stores. */
count = len >> 2;
len -= count << 2;
/* Do 16-byte chunks using one XMM register. */
while (count--)
{
_mm_store_si128((__m128i*)dptr, xmm0);
dptr += 4;
}
/* Do leftover bytes. */
while (len--)
*dptr++ = val;
return PRIMITIVES_SUCCESS;
}
/* ------------------------------------------------------------------------- */
static pstatus_t sse2_set_32s(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 len)
{
UINT32 uval = *((UINT32*)&val);
return sse2_set_32u(uval, (UINT32*)pDst, len);
}
#endif /* !defined(WITH_IPP) || defined(ALL_PRIMITIVES_VERSIONS) */
#endif /* WITH_SSE2 */
#ifdef WITH_IPP
/* ------------------------------------------------------------------------- */
static pstatus_t ipp_wrapper_set_32u(UINT32 val, UINT32* WINPR_RESTRICT pDst, INT32 len)
{
/* A little type conversion, then use the signed version. */
INT32 sval = *((INT32*)&val);
return ippsSet_32s(sval, (INT32*)pDst, len);
}
#endif
/* ------------------------------------------------------------------------- */
void primitives_init_set_opt(primitives_t* WINPR_RESTRICT prims)
{
generic = primitives_get_generic();
primitives_init_set(prims);
/* Pick tuned versions if possible. */
#ifdef WITH_IPP
prims->set_8u = (__set_8u_t)ippsSet_8u;
prims->set_32s = (__set_32s_t)ippsSet_32s;
prims->set_32u = (__set_32u_t)ipp_wrapper_set_32u;
prims->zero = (__zero_t)ippsZero_8u;
#elif defined(WITH_SSE2)
if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE))
{
prims->set_8u = sse2_set_8u;
prims->set_32s = sse2_set_32s;
prims->set_32u = sse2_set_32u;
}
#endif
}
|