Debian Codegraph @

libfreerdp/primitives/sse/prim_copy_avx2.c

raw symbols SCIP
1 /* FreeRDP: A Remote Desktop Protocol Client
2 * Copy operations.
3 * vi:ts=4 sw=4:
4 *
5 * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may
7 * not use this file except in compliance with the License. You may obtain
8 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include <winpr/sysinfo.h>cxx . . $ `<file>/winpr/include/winpr/sysinfo.h`/
17
18 #include <freerdp/config.h>cxx . . $ `<file>/build/include/freerdp/config.h`/
19
20 #include <string.h>
21 #include <freerdp/types.h>cxx . . $ `<file>/include/freerdp/types.h`/
22 #include <freerdp/primitives.h>cxx . . $ `<file>/include/freerdp/primitives.h`/
23 #include <freerdp/log.h>cxx . . $ `<file>/include/freerdp/log.h`/
24
25 #include "prim_internal.h"cxx . . $ `<file>/libfreerdp/primitives/prim_internal.h`/
26 #include "prim_copy.h"cxx . . $ `<file>/libfreerdp/primitives/prim_copy.h`/
27 #include "../codec/color.h"cxx . . $ `<file>/libfreerdp/codec/color.h`/
28
29 #include <freerdp/codec/color.h>cxx . . $ `<file>/include/freerdp/codec/color.h`/
30
31 #if defined(SSE_AVX_INTRINSICS_ENABLEDcxx . . $ `libfreerdp/core/simd.h:36:9`!)
32 #include <emmintrin.h>
33 #include <immintrin.h>
34
35 static inline __m256icxx . . $ __m256i# mm256_set_epu32cxx . . $ mm256_set_epu32(855b13aefd7517fe).(uint32_tcxx . . $ uint32_t# i0, uint32_tcxx . . $ uint32_t# i1, uint32_tcxx . . $ uint32_t# i2, uint32_tcxx . . $ uint32_t# i3,
36 uint32_tcxx . . $ uint32_t# i4, uint32_tcxx . . $ uint32_t# i5, uint32_tcxx . . $ uint32_t# i6, uint32_tcxx . . $ uint32_t# i7)
37 {
38 return _mm256_set_epi32cxx . . $ _mm256_set_epi32(2292cbcd86f26a40).((int32_tcxx . . $ int32_t#)i0, (int32_tcxx . . $ int32_t#)i1, (int32_tcxx . . $ int32_t#)i2, (int32_tcxx . . $ int32_t#)i3, (int32_tcxx . . $ int32_t#)i4,
39 (int32_tcxx . . $ int32_t#)i5, (int32_tcxx . . $ int32_t#)i6, (int32_tcxx . . $ int32_t#)i7);
40 }
41
42 static inline pstatus_tcxx . . $ pstatus_t# avx2_image_copy_bgr24_bgrx32cxx . . $ avx2_image_copy_bgr24_bgrx32(f3dedd71ff7dcc63).(BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pDstData, UINT32cxx . . $ UINT32# nDstStep,
43 UINT32cxx . . $ UINT32# nXDst, UINT32cxx . . $ UINT32# nYDst, UINT32cxx . . $ UINT32# nWidth,
44 UINT32cxx . . $ UINT32# nHeight,
45 const BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pSrcData,
46 UINT32cxx . . $ UINT32# nSrcStep, UINT32cxx . . $ UINT32# nXSrc, UINT32cxx . . $ UINT32# nYSrc,
47 int64_tcxx . . $ int64_t# srcVMultiplier, int64_tcxx . . $ int64_t# srcVOffset,
48 int64_tcxx . . $ int64_t# dstVMultiplier, int64_tcxx . . $ int64_t# dstVOffset)
49 {
50
51 const int64_tcxx . . $ int64_t# srcByte = 3;
52 const int64_tcxx . . $ int64_t# dstByte = 4;
53
54 const __m256icxx . . $ __m256i# mask = mm256_set_epu32cxx . . $ mm256_set_epu32(855b13aefd7517fe).(0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000,
55 0xFF000000, 0xFF000000, 0xFF000000);
56 const __m256icxx . . $ __m256i# smask = mm256_set_epu32cxx . . $ mm256_set_epu32(855b13aefd7517fe).(0xff171615, 0xff141312, 0xff1110ff, 0xffffffff,
57 0xff0b0a09, 0xff080706, 0xff050403, 0xff020100);
58 const __m256icxx . . $ __m256i# shelpmask = mm256_set_epu32cxx . . $ mm256_set_epu32(855b13aefd7517fe).(0xffffffff, 0xffffffff, 0xffffff1f, 0xff1e1d1c,
59 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff);
60 const UINT32cxx . . $ UINT32# rem = nWidth % 8;
61 const int64_tcxx . . $ int64_t# width = nWidth - rem;
62
63 for (int64_tcxx . . $ int64_t# y = 0; y < nHeight; y++)
64 {
65 const BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! srcLine =
66 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
67 BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! dstLine =
68 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
69
70 int64_tcxx . . $ int64_t# x = 0;
71
72 /* Ensure alignment requirements can be met */
73 for (; x < width; x += 8)
74 {
75 const __m256icxx . . $ __m256i#* src = (const __m256icxx . . $ __m256i#*)&srcLine[(x + nXSrc) * srcByte];
76 __m256icxx . . $ __m256i#* dst = (__m256icxx . . $ __m256i#*)&dstLine[(x + nXDst) * dstByte];
77 const __m256icxx . . $ __m256i# s0 = _mm256_loadu_si256cxx . . $ _mm256_loadu_si256(181560bb045879).(src);
78 __m256icxx . . $ __m256i# s1 = _mm256_shuffle_epi8cxx . . $ _mm256_shuffle_epi8(45577336e34aacfa).(s0, smask);
79
80 /* _mm256_shuffle_epi8 can not cross 128bit lanes.
81 * manually copy these bytes with extract/insert */
82 const __m256icxx . . $ __m256i# sx = _mm256_broadcastsi128_si256cxx . . $ _mm256_broadcastsi128_si256(3a1bf679c19286da).(_mm256_extractf128_si256cxx . . $ _mm256_extractf128_si256(e68ab85cc47b12ae).(s0, 0));
83 const __m256icxx . . $ __m256i# sxx = _mm256_shuffle_epi8cxx . . $ _mm256_shuffle_epi8(45577336e34aacfa).(sx, shelpmask);
84 const __m256icxx . . $ __m256i# bmask = _mm256_set_epi32cxx . . $ _mm256_set_epi32(2292cbcd86f26a40).(0x00000000, 0x00000000, 0x000000FF, 0x00FFFFFF,
85 0x00000000, 0x00000000, 0x00000000, 0x00000000);
86 const __m256icxx . . $ __m256i# merged = _mm256_blendv_epi8cxx . . $ _mm256_blendv_epi8(9e96fd23a9a34087).(s1, sxx, bmask);
87
88 const __m256icxx . . $ __m256i# s2 = _mm256_loadu_si256cxx . . $ _mm256_loadu_si256(181560bb045879).(dst);
89 __m256icxx . . $ __m256i# d0 = _mm256_blendv_epi8cxx . . $ _mm256_blendv_epi8(9e96fd23a9a34087).(merged, s2, mask);
90 _mm256_storeu_si256cxx . . $ _mm256_storeu_si256(9aee33bb86c0058a).(dst, d0);
91 }
92
93 for (; x < nWidth; x++)
94 {
95 const BYTEcxx . . $ BYTE#* src = &srcLine[(x + nXSrc) * srcByte];
96 BYTEcxx . . $ BYTE#* dst = &dstLine[(x + nXDst) * dstByte];
97 *dst++ = *src++;
98 *dst++ = *src++;
99 *dst++ = *src++;
100 }
101 }
102
103 return PRIMITIVES_SUCCESScxx . . $ `include/freerdp/primitives.h:37:9`!;
104 }
105
106 static inline pstatus_tcxx . . $ pstatus_t# avx2_image_copy_bgrx32_bgrx32cxx . . $ avx2_image_copy_bgrx32_bgrx32(f3dedd71ff7dcc63).(BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pDstData,
107 UINT32cxx . . $ UINT32# nDstStep, UINT32cxx . . $ UINT32# nXDst, UINT32cxx . . $ UINT32# nYDst,
108 UINT32cxx . . $ UINT32# nWidth, UINT32cxx . . $ UINT32# nHeight,
109 const BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pSrcData,
110 UINT32cxx . . $ UINT32# nSrcStep, UINT32cxx . . $ UINT32# nXSrc, UINT32cxx . . $ UINT32# nYSrc,
111 int64_tcxx . . $ int64_t# srcVMultiplier, int64_tcxx . . $ int64_t# srcVOffset,
112 int64_tcxx . . $ int64_t# dstVMultiplier, int64_tcxx . . $ int64_t# dstVOffset)
113 {
114
115 const int64_tcxx . . $ int64_t# srcByte = 4;
116 const int64_tcxx . . $ int64_t# dstByte = 4;
117
118 const __m256icxx . . $ __m256i# mask = _mm256_setr_epi8cxx . . $ _mm256_setr_epi8(82ef20e75a36e220).(
119 (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00,
120 (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00,
121 (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00,
122 (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00);
123 const UINT32cxx . . $ UINT32# rem = nWidth % 8;
124 const int64_tcxx . . $ int64_t# width = nWidth - rem;
125 for (int64_tcxx . . $ int64_t# y = 0; y < nHeight; y++)
126 {
127 const BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! srcLine =
128 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
129 BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! dstLine =
130 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
131
132 int64_tcxx . . $ int64_t# x = 0;
133 for (; x < width; x += 8)
134 {
135 const __m256icxx . . $ __m256i#* src = (const __m256icxx . . $ __m256i#*)&srcLine[(x + nXSrc) * srcByte];
136 __m256icxx . . $ __m256i#* dst = (__m256icxx . . $ __m256i#*)&dstLine[(x + nXDst) * dstByte];
137 const __m256icxx . . $ __m256i# s0 = _mm256_loadu_si256cxx . . $ _mm256_loadu_si256(181560bb045879).(src);
138 const __m256icxx . . $ __m256i# s1 = _mm256_loadu_si256cxx . . $ _mm256_loadu_si256(181560bb045879).(dst);
139 __m256icxx . . $ __m256i# d0 = _mm256_blendv_epi8cxx . . $ _mm256_blendv_epi8(9e96fd23a9a34087).(s1, s0, mask);
140 _mm256_storeu_si256cxx . . $ _mm256_storeu_si256(9aee33bb86c0058a).(dst, d0);
141 }
142
143 for (; x < nWidth; x++)
144 {
145 const BYTEcxx . . $ BYTE#* src = &srcLine[(x + nXSrc) * srcByte];
146 BYTEcxx . . $ BYTE#* dst = &dstLine[(x + nXDst) * dstByte];
147 *dst++ = *src++;
148 *dst++ = *src++;
149 *dst++ = *src++;
150 }
151 }
152
153 return PRIMITIVES_SUCCESScxx . . $ `include/freerdp/primitives.h:37:9`!;
154 }
155
156 static pstatus_tcxx . . $ pstatus_t# avx2_image_copy_no_overlap_dst_alphacxx . . $ avx2_image_copy_no_overlap_dst_alpha(5f3aee7dcfba87d3).(
157 BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pDstData, DWORDcxx . . $ DWORD# DstFormat, UINT32cxx . . $ UINT32# nDstStep, UINT32cxx . . $ UINT32# nXDst, UINT32cxx . . $ UINT32# nYDst,
158 UINT32cxx . . $ UINT32# nWidth, UINT32cxx . . $ UINT32# nHeight, const BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pSrcData, DWORDcxx . . $ DWORD# SrcFormat,
159 UINT32cxx . . $ UINT32# nSrcStep, UINT32cxx . . $ UINT32# nXSrc, UINT32cxx . . $ UINT32# nYSrc, const gdiPalettecxx . . $ gdiPalette#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! palette,
160 UINT32cxx . . $ UINT32# flags, int64_tcxx . . $ int64_t# srcVMultiplier, int64_tcxx . . $ int64_t# srcVOffset, int64_tcxx . . $ int64_t# dstVMultiplier,
161 int64_tcxx . . $ int64_t# dstVOffset)
162 {
163 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(pDstData);
164 WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(pSrcData);
165
166 switch (SrcFormat)
167 {
168 case PIXEL_FORMAT_BGR24cxx . . $ `include/freerdp/codec/color.h:90:9`!:
169 switch (DstFormat)
170 {
171 case PIXEL_FORMAT_BGRX32cxx . . $ `include/freerdp/codec/color.h:80:9`!:
172 case PIXEL_FORMAT_BGRA32cxx . . $ `include/freerdp/codec/color.h:79:9`!:
173 return avx2_image_copy_bgr24_bgrx32cxx . . $ avx2_image_copy_bgr24_bgrx32(f3dedd71ff7dcc63).(
174 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
175 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
176 default:
177 break;
178 }
179 break;
180 case PIXEL_FORMAT_BGRX32cxx . . $ `include/freerdp/codec/color.h:80:9`!:
181 case PIXEL_FORMAT_BGRA32cxx . . $ `include/freerdp/codec/color.h:79:9`!:
182 switch (DstFormat)
183 {
184 case PIXEL_FORMAT_BGRX32cxx . . $ `include/freerdp/codec/color.h:80:9`!:
185 case PIXEL_FORMAT_BGRA32cxx . . $ `include/freerdp/codec/color.h:79:9`!:
186 return avx2_image_copy_bgrx32_bgrx32cxx . . $ avx2_image_copy_bgrx32_bgrx32(f3dedd71ff7dcc63).(
187 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
188 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
189 default:
190 break;
191 }
192 break;
193 case PIXEL_FORMAT_RGBX32cxx . . $ `include/freerdp/codec/color.h:82:9`!:
194 case PIXEL_FORMAT_RGBA32cxx . . $ `include/freerdp/codec/color.h:81:9`!:
195 switch (DstFormat)
196 {
197 case PIXEL_FORMAT_RGBX32cxx . . $ `include/freerdp/codec/color.h:82:9`!:
198 case PIXEL_FORMAT_RGBA32cxx . . $ `include/freerdp/codec/color.h:81:9`!:
199 return avx2_image_copy_bgrx32_bgrx32cxx . . $ avx2_image_copy_bgrx32_bgrx32(f3dedd71ff7dcc63).(
200 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
201 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
202 default:
203 break;
204 }
205 break;
206 default:
207 break;
208 }
209
210 primitives_tcxx . . $ primitives_t#* gen = primitives_get_genericcxx . . $ primitives_get_generic(5aab25e1eee8af3f).();
211 return gen->copy_no_overlapcxx . . $ $anonymous_type_a81ffe69c5842754_3#copy_no_overlap.(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight,
212 pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette, flags);
213 }
214
215 static pstatus_tcxx . . $ pstatus_t# avx2_image_copy_no_overlapcxx . . $ avx2_image_copy_no_overlap(6f26b3e6415705a2).(BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pDstData, DWORDcxx . . $ DWORD# DstFormat,
216 UINT32cxx . . $ UINT32# nDstStep, UINT32cxx . . $ UINT32# nXDst, UINT32cxx . . $ UINT32# nYDst,
217 UINT32cxx . . $ UINT32# nWidth, UINT32cxx . . $ UINT32# nHeight,
218 const BYTEcxx . . $ BYTE#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pSrcData, DWORDcxx . . $ DWORD# SrcFormat,
219 UINT32cxx . . $ UINT32# nSrcStep, UINT32cxx . . $ UINT32# nXSrc, UINT32cxx . . $ UINT32# nYSrc,
220 const gdiPalettecxx . . $ gdiPalette#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! palette, UINT32cxx . . $ UINT32# flags)
221 {
222 const BOOLcxx . . $ BOOL# vSrcVFlip = (flags & FREERDP_FLIP_VERTICALcxx . . $ FREERDP_FLIP_VERTICAL.) != 0;
223 int64_tcxx . . $ int64_t# srcVOffset = 0;
224 int64_tcxx . . $ int64_t# srcVMultiplier = 1;
225 int64_tcxx . . $ int64_t# dstVOffset = 0;
226 int64_tcxx . . $ int64_t# dstVMultiplier = 1;
227
228 if ((nWidth == 0) || (nHeight == 0))
229 return PRIMITIVES_SUCCESScxx . . $ `include/freerdp/primitives.h:37:9`!;
230
231 if ((nHeight > INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!) || (nWidth > INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!))
232 return -1;
233
234 if (!pDstData || !pSrcData)
235 return -1;
236
237 if (nDstStep == 0)
238 nDstStep = nWidth * FreeRDPGetBytesPerPixelcxx . . $ FreeRDPGetBytesPerPixel(2141b656ce2cc063).(DstFormat);
239
240 if (nSrcStep == 0)
241 nSrcStep = nWidth * FreeRDPGetBytesPerPixelcxx . . $ FreeRDPGetBytesPerPixel(2141b656ce2cc063).(SrcFormat);
242
243 if (vSrcVFlip)
244 {
245 srcVOffset = (nHeight - 1ll) * nSrcStep;
246 srcVMultiplier = -1;
247 }
248
249 if (((flags & FREERDP_KEEP_DST_ALPHAcxx . . $ FREERDP_KEEP_DST_ALPHA.) != 0) && FreeRDPColorHasAlphacxx . . $ FreeRDPColorHasAlpha(4c679297bf94b9eb).(DstFormat))
250 return avx2_image_copy_no_overlap_dst_alphacxx . . $ avx2_image_copy_no_overlap_dst_alpha(5f3aee7dcfba87d3).(pDstData, DstFormat, nDstStep, nXDst, nYDst,
251 nWidth, nHeight, pSrcData, SrcFormat, nSrcStep,
252 nXSrc, nYSrc, palette, flags, srcVMultiplier,
253 srcVOffset, dstVMultiplier, dstVOffset);
254 else if (FreeRDPAreColorFormatsEqualNoAlphacxx . . $ FreeRDPAreColorFormatsEqualNoAlpha(83f10ac8959d5577).(SrcFormat, DstFormat))
255 return generic_image_copy_no_overlap_memcpycxx . . $ generic_image_copy_no_overlap_memcpy(863cef2c23ba6505).(pDstData, DstFormat, nDstStep, nXDst, nYDst,
256 nWidth, nHeight, pSrcData, SrcFormat, nSrcStep,
257 nXSrc, nYSrc, palette, srcVMultiplier,
258 srcVOffset, dstVMultiplier, dstVOffset, flags);
259 else
260 {
261 primitives_tcxx . . $ primitives_t#* gen = primitives_get_genericcxx . . $ primitives_get_generic(5aab25e1eee8af3f).();
262 return gen->copy_no_overlapcxx . . $ $anonymous_type_a81ffe69c5842754_3#copy_no_overlap.(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight,
263 pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette, flags);
264 }
265 }
266 #endif
267
268 /* ------------------------------------------------------------------------- */
269 void primitives_init_copy_avx2_intcxx . . $ primitives_init_copy_avx2_int(9308eb7af8fe464a).(primitives_tcxx . . $ primitives_t#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! prims)
270 {
271 #if defined(SSE_AVX_INTRINSICS_ENABLEDcxx . . $ `libfreerdp/core/simd.h:36:9`!)
272 WLog_VRBcxx . . $ `winpr/include/winpr/wlog.h:339:9`!(PRIM_TAGcxx . . $ `libfreerdp/core/simd.h:26:9`!, "AVX2 optimizations");
273 prims->copy_no_overlapcxx . . $ $anonymous_type_a81ffe69c5842754_3#copy_no_overlap. = avx2_image_copy_no_overlapcxx . . $ avx2_image_copy_no_overlap(6f26b3e6415705a2).;
274 #else
275 WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or WITH_AVX2 or AVX2 intrinsics not available");
276 WINPR_UNUSED(prims);
277 #endif
278 }