/src/FreeRDP/libfreerdp/primitives/prim_add.c
Line  | Count  | Source (jump to first uncovered line)  | 
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  |  |  */  | 
30  |  | static INLINE INT16 add(INT16 a, INT16 b)  | 
31  | 0  | { | 
32  | 0  |   INT32 k = (INT32)a + (INT32)b;  | 
33  |  | 
  | 
34  | 0  |   if (k > INT16_MAX)  | 
35  | 0  |     return INT16_MAX;  | 
36  |  |  | 
37  | 0  |   if (k < INT16_MIN)  | 
38  | 0  |     return INT16_MIN;  | 
39  |  |  | 
40  | 0  |   return (INT16)k;  | 
41  | 0  | }  | 
42  |  |  | 
43  |  | static pstatus_t general_add_16s(const INT16* WINPR_RESTRICT pSrc1,  | 
44  |  |                                  const INT16* WINPR_RESTRICT pSrc2, INT16* WINPR_RESTRICT pDst,  | 
45  |  |                                  UINT32 len)  | 
46  | 0  | { | 
47  | 0  |   const UINT32 rem = len % 16;  | 
48  | 0  |   const UINT32 align = len - rem;  | 
49  |  | 
  | 
50  | 0  |   for (UINT32 x = 0; x < align; x++)  | 
51  | 0  |     *pDst++ = add(*pSrc1++, *pSrc2++);  | 
52  |  | 
  | 
53  | 0  |   for (UINT32 x = 0; x < rem; x++)  | 
54  | 0  |     *pDst++ = add(*pSrc1++, *pSrc2++);  | 
55  |  | 
  | 
56  | 0  |   return PRIMITIVES_SUCCESS;  | 
57  | 0  | }  | 
58  |  |  | 
59  |  | static pstatus_t general_add_16s_inplace(INT16* WINPR_RESTRICT pSrcDst1,  | 
60  |  |                                          INT16* WINPR_RESTRICT pSrcDst2, UINT32 len)  | 
61  | 0  | { | 
62  | 0  |   for (UINT32 x = 0; x < len; x++)  | 
63  | 0  |   { | 
64  | 0  |     INT16 v = add(pSrcDst1[x], pSrcDst2[x]);  | 
65  | 0  |     pSrcDst1[x] = v;  | 
66  | 0  |     pSrcDst2[x] = v;  | 
67  | 0  |   }  | 
68  |  | 
  | 
69  | 0  |   return PRIMITIVES_SUCCESS;  | 
70  | 0  | }  | 
71  |  |  | 
72  |  | /* ------------------------------------------------------------------------- */  | 
73  |  | void primitives_init_add(primitives_t* prims)  | 
74  | 1  | { | 
75  | 1  |   prims->add_16s = general_add_16s;  | 
76  | 1  |   prims->add_16s_inplace = general_add_16s_inplace;  | 
77  | 1  | }  | 
78  |  |  | 
79  |  | void primitives_init_add_opt(primitives_t* WINPR_RESTRICT prims)  | 
80  | 0  | { | 
81  | 0  |   primitives_init_add_sse3(prims);  | 
82  | 0  | }  |