| 1 | /* FreeRDP: A Remote Desktop Protocol Client |
| 2 | * Optimized add 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 | |
| 17 | #include <freerdp/config.h>cxx . . $ `<file>/build/include/freerdp/config.h`/ |
| 18 | |
| 19 | #include <freerdp/types.h>cxx . . $ `<file>/include/freerdp/types.h`/ |
| 20 | #include <freerdp/primitives.h>cxx . . $ `<file>/include/freerdp/primitives.h`/ |
| 21 | #include <winpr/sysinfo.h>cxx . . $ `<file>/winpr/include/winpr/sysinfo.h`/ |
| 22 | |
| 23 | #include "prim_add.h"cxx . . $ `<file>/libfreerdp/primitives/prim_add.h`/ |
| 24 | |
| 25 | #include "prim_internal.h"cxx . . $ `<file>/libfreerdp/primitives/prim_internal.h`/ |
| 26 | #include "prim_templates.h"cxx . . $ `<file>/libfreerdp/primitives/sse/prim_templates.h`/ |
| 27 | |
| 28 | #if defined(SSE_AVX_INTRINSICS_ENABLEDcxx . . $ `libfreerdp/core/simd.h:36:9`!) |
| 29 | #include <emmintrin.h> |
| 30 | #include <pmmintrin.h> |
| 31 | |
| 32 | static primitives_tcxx . . $ primitives_t#* genericcxx . . $ generic. = nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 33 | |
| 34 | /* ------------------------------------------------------------------------- */ |
| 35 | SSE3_SSD_ROUTINEcxx . . $ `libfreerdp/primitives/sse/prim_templates.h:202:9`!(sse3_add_16s, INT16, generic->add_16s, _mm_adds_epi16, |
| 36 | generic->add_16s(sptr1++, sptr2++, dptr++, 1)) |
| 37 | |
| 38 | static pstatus_tcxx . . $ pstatus_t# sse3_add_16s_inplacecxx . . $ sse3_add_16s_inplace(593ae1e3c5bea724).(INT16cxx . . $ INT16#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pSrcDst1, |
| 39 | INT16cxx . . $ INT16#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! pSrcDst2, UINT32cxx . . $ UINT32# ulen) |
| 40 | { |
| 41 | const int shifts = 2; |
| 42 | INT16cxx . . $ INT16#* dptr1 = pSrcDst1; |
| 43 | INT16cxx . . $ INT16#* dptr2 = pSrcDst2; |
| 44 | |
| 45 | if (ulen < 16) /* pointless if too small */ |
| 46 | return genericcxx . . $ generic.->add_16s_inplacecxx . . $ $anonymous_type_a81ffe69c5842754_3#add_16s_inplace.(pSrcDst1, pSrcDst2, ulen); |
| 47 | |
| 48 | UINT32cxx . . $ UINT32# offBeatMask = (1u << (shifts - 1)) - 1; |
| 49 | if ((ULONG_PTRcxx . . $ ULONG_PTR#)pSrcDst1 & offBeatMask) |
| 50 | { |
| 51 | /* Incrementing the pointer skips over 16-byte boundary. */ |
| 52 | return genericcxx . . $ generic.->add_16s_inplacecxx . . $ $anonymous_type_a81ffe69c5842754_3#add_16s_inplace.(pSrcDst1, pSrcDst2, ulen); |
| 53 | } |
| 54 | /* Get to the 16-byte boundary now. */ |
| 55 | const size_t rem = ((UINT_PTRcxx . . $ UINT_PTR#)dptr1 & 0xf) / sizeof(INT16cxx . . $ INT16#); |
| 56 | if (rem != 0) |
| 57 | { |
| 58 | const UINT32cxx . . $ UINT32# add = 16 - (UINT32cxx . . $ UINT32#)rem; |
| 59 | pstatus_tcxx . . $ pstatus_t# status = genericcxx . . $ generic.->add_16s_inplacecxx . . $ $anonymous_type_a81ffe69c5842754_3#add_16s_inplace.(dptr1, dptr2, add); |
| 60 | if (status != PRIMITIVES_SUCCESScxx . . $ `include/freerdp/primitives.h:37:9`!) |
| 61 | return status; |
| 62 | dptr1 += add; |
| 63 | dptr2 += add; |
| 64 | } |
| 65 | /* Use 4 128-bit SSE registers. */ |
| 66 | size_t len = ulen; |
| 67 | size_t count = len >> (7 - shifts); |
| 68 | len -= count << (7 - shifts); |
| 69 | if (((const ULONG_PTRcxx . . $ ULONG_PTR#)dptr1 & 0x0f) || ((const ULONG_PTRcxx . . $ ULONG_PTR#)dptr2 & 0x0f)) |
| 70 | { |
| 71 | /* Unaligned loads */ |
| 72 | while (count--) |
| 73 | { |
| 74 | const __m128icxx . . $ __m128i#* vsptr1 = (const __m128icxx . . $ __m128i#*)dptr1; |
| 75 | const __m128icxx . . $ __m128i#* vsptr2 = (const __m128icxx . . $ __m128i#*)dptr2; |
| 76 | __m128icxx . . $ __m128i#* vdptr1 = (__m128icxx . . $ __m128i#*)dptr1; |
| 77 | __m128icxx . . $ __m128i#* vdptr2 = (__m128icxx . . $ __m128i#*)dptr2; |
| 78 | |
| 79 | __m128icxx . . $ __m128i# xmm0 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 80 | __m128icxx . . $ __m128i# xmm1 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 81 | __m128icxx . . $ __m128i# xmm2 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 82 | __m128icxx . . $ __m128i# xmm3 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 83 | __m128icxx . . $ __m128i# xmm4 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 84 | __m128icxx . . $ __m128i# xmm5 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 85 | __m128icxx . . $ __m128i# xmm6 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 86 | __m128icxx . . $ __m128i# xmm7 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 87 | |
| 88 | xmm0 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm0, xmm4); |
| 89 | xmm1 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm1, xmm5); |
| 90 | xmm2 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm2, xmm6); |
| 91 | xmm3 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm3, xmm7); |
| 92 | |
| 93 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm0); |
| 94 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm1); |
| 95 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm2); |
| 96 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm3); |
| 97 | |
| 98 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm0); |
| 99 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm1); |
| 100 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm2); |
| 101 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm3); |
| 102 | |
| 103 | dptr1 = (INT16cxx . . $ INT16#*)vdptr1; |
| 104 | dptr2 = (INT16cxx . . $ INT16#*)vdptr2; |
| 105 | } |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | /* Aligned loads */ |
| 110 | while (count--) |
| 111 | { |
| 112 | const __m128icxx . . $ __m128i#* vsptr1 = (const __m128icxx . . $ __m128i#*)dptr1; |
| 113 | const __m128icxx . . $ __m128i#* vsptr2 = (const __m128icxx . . $ __m128i#*)dptr2; |
| 114 | __m128icxx . . $ __m128i#* vdptr1 = (__m128icxx . . $ __m128i#*)dptr1; |
| 115 | __m128icxx . . $ __m128i#* vdptr2 = (__m128icxx . . $ __m128i#*)dptr2; |
| 116 | |
| 117 | __m128icxx . . $ __m128i# xmm0 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 118 | __m128icxx . . $ __m128i# xmm1 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 119 | __m128icxx . . $ __m128i# xmm2 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 120 | __m128icxx . . $ __m128i# xmm3 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1++); |
| 121 | __m128icxx . . $ __m128i# xmm4 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 122 | __m128icxx . . $ __m128i# xmm5 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 123 | __m128icxx . . $ __m128i# xmm6 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 124 | __m128icxx . . $ __m128i# xmm7 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2++); |
| 125 | |
| 126 | xmm0 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm0, xmm4); |
| 127 | xmm1 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm1, xmm5); |
| 128 | xmm2 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm2, xmm6); |
| 129 | xmm3 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm3, xmm7); |
| 130 | |
| 131 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm0); |
| 132 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm1); |
| 133 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm2); |
| 134 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm3); |
| 135 | |
| 136 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm0); |
| 137 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm1); |
| 138 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm2); |
| 139 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm3); |
| 140 | |
| 141 | dptr1 = (INT16cxx . . $ INT16#*)vdptr1; |
| 142 | dptr2 = (INT16cxx . . $ INT16#*)vdptr2; |
| 143 | } |
| 144 | } |
| 145 | /* Use a single 128-bit SSE register. */ |
| 146 | count = len >> (5 - shifts); |
| 147 | len -= count << (5 - shifts); |
| 148 | while (count--) |
| 149 | { |
| 150 | const __m128icxx . . $ __m128i#* vsptr1 = (const __m128icxx . . $ __m128i#*)dptr1; |
| 151 | const __m128icxx . . $ __m128i#* vsptr2 = (const __m128icxx . . $ __m128i#*)dptr2; |
| 152 | __m128icxx . . $ __m128i#* vdptr1 = (__m128icxx . . $ __m128i#*)dptr1; |
| 153 | __m128icxx . . $ __m128i#* vdptr2 = (__m128icxx . . $ __m128i#*)dptr2; |
| 154 | |
| 155 | __m128icxx . . $ __m128i# xmm0 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr1); |
| 156 | __m128icxx . . $ __m128i# xmm1 = LOAD_SI128cxx . . $ LOAD_SI128(7f771a116cc7c384).(vsptr2); |
| 157 | |
| 158 | xmm0 = _mm_adds_epi16cxx . . $ _mm_adds_epi16(e79ab442e937dade).(xmm0, xmm1); |
| 159 | |
| 160 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr1++, xmm0); |
| 161 | STORE_SI128cxx . . $ STORE_SI128(2e73c3cb7991893e).(vdptr2++, xmm0); |
| 162 | |
| 163 | dptr1 = (INT16cxx . . $ INT16#*)vdptr1; |
| 164 | dptr2 = (INT16cxx . . $ INT16#*)vdptr2; |
| 165 | } |
| 166 | /* Finish off the remainder. */ |
| 167 | if (len > 0) |
| 168 | return genericcxx . . $ generic.->add_16s_inplacecxx . . $ $anonymous_type_a81ffe69c5842754_3#add_16s_inplace.(dptr1, dptr2, WINPR_ASSERTING_INT_CASTcxx . . $ `winpr/include/winpr/cast.h:111:9`!(uint32_t, len)); |
| 169 | |
| 170 | return PRIMITIVES_SUCCESScxx . . $ `include/freerdp/primitives.h:37:9`!; |
| 171 | } |
| 172 | #endif |
| 173 | |
| 174 | /* ------------------------------------------------------------------------- */ |
| 175 | void primitives_init_add_sse3_intcxx . . $ primitives_init_add_sse3_int(9308eb7af8fe464a).(primitives_tcxx . . $ primitives_t#* WINPR_RESTRICTcxx . . $ `winpr/include/winpr/platform.h:54:9`! prims) |
| 176 | { |
| 177 | #if defined(SSE_AVX_INTRINSICS_ENABLEDcxx . . $ `libfreerdp/core/simd.h:36:9`!) |
| 178 | genericcxx . . $ generic. = primitives_get_genericcxx . . $ primitives_get_generic(5aab25e1eee8af3f).(); |
| 179 | |
| 180 | WLog_VRBcxx . . $ `winpr/include/winpr/wlog.h:339:9`!(PRIM_TAGcxx . . $ `libfreerdp/core/simd.h:26:9`!, "SSE2/SSE3 optimizations"); |
| 181 | prims->add_16scxx . . $ $anonymous_type_a81ffe69c5842754_3#add_16s. = sse3_add_16scxx . . $ sse3_add_16s(4872388fe17ed3a4).; |
| 182 | prims->add_16s_inplacecxx . . $ $anonymous_type_a81ffe69c5842754_3#add_16s_inplace. = sse3_add_16s_inplacecxx . . $ sse3_add_16s_inplace(593ae1e3c5bea724).; |
| 183 | #else |
| 184 | WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE3 intrinsics not available"); |
| 185 | WINPR_UNUSED(prims); |
| 186 | #endif |
| 187 | } |