FreeRDP
Loading...
Searching...
No Matches
prim_add.c
1/* FreeRDP: A Remote Desktop Protocol Client
2 * 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>
18
19#include <stdint.h>
20
21#include <freerdp/types.h>
22#include <freerdp/primitives.h>
23
24#include "prim_internal.h"
25#include "prim_add.h"
26
27/* ----------------------------------------------------------------------------
28 * 16-bit signed add with saturation (under and over).
29 */
30static INLINE INT16 add(INT16 a, INT16 b)
31{
32 INT32 k = (INT32)a + (INT32)b;
33
34 if (k > INT16_MAX)
35 return INT16_MAX;
36
37 if (k < INT16_MIN)
38 return INT16_MIN;
39
40 return (INT16)k;
41}
42
43static pstatus_t general_add_16s(const INT16* WINPR_RESTRICT pSrc1,
44 const INT16* WINPR_RESTRICT pSrc2, INT16* WINPR_RESTRICT pDst,
45 UINT32 len)
46{
47 const UINT32 rem = len % 16;
48 const UINT32 align = len - rem;
49
50 for (UINT32 x = 0; x < align; x++)
51 *pDst++ = add(*pSrc1++, *pSrc2++);
52
53 for (UINT32 x = 0; x < rem; x++)
54 *pDst++ = add(*pSrc1++, *pSrc2++);
55
56 return PRIMITIVES_SUCCESS;
57}
58
59static pstatus_t general_add_16s_inplace(INT16* WINPR_RESTRICT pSrcDst1,
60 INT16* WINPR_RESTRICT pSrcDst2, UINT32 len)
61{
62 for (UINT32 x = 0; x < len; x++)
63 {
64 INT16 v = add(pSrcDst1[x], pSrcDst2[x]);
65 pSrcDst1[x] = v;
66 pSrcDst2[x] = v;
67 }
68
69 return PRIMITIVES_SUCCESS;
70}
71
72/* ------------------------------------------------------------------------- */
73void primitives_init_add(primitives_t* WINPR_RESTRICT prims)
74{
75 prims->add_16s = general_add_16s;
76 prims->add_16s_inplace = general_add_16s_inplace;
77}
78
79void primitives_init_add_opt(primitives_t* WINPR_RESTRICT prims)
80{
81 primitives_init_add(prims);
82 primitives_init_add_sse3(prims);
83}