23 #include <freerdp/config.h>
25 #include <freerdp/types.h>
26 #include <freerdp/primitives.h>
27 #include <winpr/sysinfo.h>
29 #include "prim_alphaComp.h"
31 #include "prim_internal.h"
34 #if defined(SSE2_ENABLED)
35 #include <emmintrin.h>
36 #include <pmmintrin.h>
40 static pstatus_t sse2_alphaComp_argb(
const BYTE* WINPR_RESTRICT pSrc1, UINT32 src1Step,
41 const BYTE* WINPR_RESTRICT pSrc2, UINT32 src2Step,
42 BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, UINT32 width,
45 const UINT32* sptr1 = (
const UINT32*)pSrc1;
46 const UINT32* sptr2 = (
const UINT32*)pSrc2;
55 if ((width <= 0) || (height <= 0))
56 return PRIMITIVES_SUCCESS;
60 return generic->alphaComp_argb(pSrc1, src1Step, pSrc2, src2Step, pDst, dstStep, width,
65 linebytes = width *
sizeof(UINT32);
66 src1Jump = (src1Step - linebytes) /
sizeof(UINT32);
67 src2Jump = (src2Step - linebytes) /
sizeof(UINT32);
68 dstJump = (dstStep - linebytes) /
sizeof(UINT32);
69 xmm0 = _mm_set1_epi32(0);
70 xmm1 = _mm_set1_epi16(1);
72 for (UINT32 y = 0; y < height; ++y)
79 switch ((ULONG_PTR)dptr & 0x0f)
107 pstatus_t status = 0;
108 status =
generic->alphaComp_argb((
const BYTE*)sptr1, src1Step, (
const BYTE*)sptr2,
109 src2Step, (BYTE*)dptr, dstStep, leadIn, 1);
110 if (status != PRIMITIVES_SUCCESS)
121 pixels -= count << 2;
132 xmm2 = LOAD_SI128(sptr1);
135 xmm3 = LOAD_SI128(sptr2);
138 xmm4 = _mm_unpackhi_epi8(xmm2, xmm0);
140 xmm5 = _mm_unpackhi_epi8(xmm3, xmm0);
142 xmm6 = _mm_subs_epi16(xmm4, xmm5);
144 xmm4 = _mm_shufflelo_epi16(xmm4, 0xff);
146 xmm4 = _mm_shufflehi_epi16(xmm4, 0xff);
148 xmm4 = _mm_adds_epi16(xmm4, xmm1);
150 xmm4 = _mm_mullo_epi16(xmm4, xmm6);
152 xmm4 = _mm_srai_epi16(xmm4, 8);
154 xmm4 = _mm_adds_epi16(xmm4, xmm5);
157 xmm5 = _mm_unpacklo_epi8(xmm2, xmm0);
159 xmm6 = _mm_unpacklo_epi8(xmm3, xmm0);
161 xmm7 = _mm_subs_epi16(xmm5, xmm6);
163 xmm5 = _mm_shufflelo_epi16(xmm5, 0xff);
165 xmm5 = _mm_shufflehi_epi16(xmm5, 0xff);
167 xmm5 = _mm_adds_epi16(xmm5, xmm1);
169 xmm5 = _mm_mullo_epi16(xmm5, xmm7);
171 xmm5 = _mm_srai_epi16(xmm5, 8);
173 xmm5 = _mm_adds_epi16(xmm5, xmm6);
176 xmm3 = _mm_set1_epi16(0x00ffU);
177 xmm4 = _mm_and_si128(xmm4, xmm3);
178 xmm5 = _mm_and_si128(xmm5, xmm3);
180 xmm5 = _mm_packus_epi16(xmm5, xmm4);
181 _mm_store_si128((__m128i*)dptr, xmm5);
188 pstatus_t status = 0;
189 status =
generic->alphaComp_argb((
const BYTE*)sptr1, src1Step, (
const BYTE*)sptr2,
190 src2Step, (BYTE*)dptr, dstStep, pixels, 1);
191 if (status != PRIMITIVES_SUCCESS)
205 return PRIMITIVES_SUCCESS;
210 void primitives_init_alphaComp_sse3(
primitives_t* WINPR_RESTRICT prims)
212 #if defined(SSE2_ENABLED)
213 generic = primitives_get_generic();
214 primitives_init_alphaComp(prims);
216 if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) &&
217 IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE))
219 WLog_VRB(PRIM_TAG,
"SSE2/SSE3 optimizations");
220 prims->alphaComp_argb = sse2_alphaComp_argb;
224 WLog_VRB(PRIM_TAG,
"undefined WITH_SSE2");