/src/FreeRDP/libfreerdp/primitives/prim_shift.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* FreeRDP: A Remote Desktop Protocol Client  | 
2  |  |  * Shift 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 <freerdp/config.h>  | 
17  |  |  | 
18  |  | #include <freerdp/types.h>  | 
19  |  | #include <freerdp/primitives.h>  | 
20  |  |  | 
21  |  | #include "prim_internal.h"  | 
22  |  | #include "prim_shift.h"  | 
23  |  |  | 
24  |  | /* ------------------------------------------------------------------------- */  | 
25  |  | static INLINE INT16 shift(INT16 val, UINT32 sh)  | 
26  | 0  | { | 
27  | 0  |   return val << sh;  | 
28  | 0  | }  | 
29  |  |  | 
30  |  | static INLINE pstatus_t general_lShiftC_16s_inplace(INT16* WINPR_RESTRICT pSrcDst, UINT32 val,  | 
31  |  |                                                     UINT32 len)  | 
32  | 0  | { | 
33  | 0  |   if (val == 0)  | 
34  | 0  |     return PRIMITIVES_SUCCESS;  | 
35  | 0  |   if (val >= 16)  | 
36  | 0  |     return -1;  | 
37  |  |  | 
38  | 0  |   for (UINT32 x = 0; x < len; x++)  | 
39  | 0  |     pSrcDst[x] = shift(pSrcDst[x], val);  | 
40  |  | 
  | 
41  | 0  |   return PRIMITIVES_SUCCESS;  | 
42  | 0  | }  | 
43  |  |  | 
44  |  | static INLINE pstatus_t general_lShiftC_16s(const INT16* pSrc, UINT32 val, INT16* pDst, UINT32 len)  | 
45  | 0  | { | 
46  | 0  |   if (val == 0)  | 
47  | 0  |     return PRIMITIVES_SUCCESS;  | 
48  | 0  |   if (val >= 16)  | 
49  | 0  |     return -1;  | 
50  |  |  | 
51  | 0  |   for (UINT32 x = 0; x < len; x++)  | 
52  | 0  |     pDst[x] = shift(pSrc[x], val);  | 
53  |  | 
  | 
54  | 0  |   return PRIMITIVES_SUCCESS;  | 
55  | 0  | }  | 
56  |  |  | 
57  |  | /* ------------------------------------------------------------------------- */  | 
58  |  | static INLINE pstatus_t general_rShiftC_16s(const INT16* pSrc, UINT32 val, INT16* pDst, UINT32 len)  | 
59  | 0  | { | 
60  | 0  |   if (val == 0)  | 
61  | 0  |     return PRIMITIVES_SUCCESS;  | 
62  | 0  |   if (val >= 16)  | 
63  | 0  |     return -1;  | 
64  |  |  | 
65  | 0  |   while (len--)  | 
66  | 0  |     *pDst++ = *pSrc++ >> val;  | 
67  |  | 
  | 
68  | 0  |   return PRIMITIVES_SUCCESS;  | 
69  | 0  | }  | 
70  |  |  | 
71  |  | /* ------------------------------------------------------------------------- */  | 
72  |  | static INLINE pstatus_t general_lShiftC_16u(const UINT16* pSrc, UINT32 val, UINT16* pDst,  | 
73  |  |                                             UINT32 len)  | 
74  | 0  | { | 
75  | 0  |   if (val == 0)  | 
76  | 0  |     return PRIMITIVES_SUCCESS;  | 
77  | 0  |   if (val >= 16)  | 
78  | 0  |     return -1;  | 
79  |  |  | 
80  | 0  |   while (len--)  | 
81  | 0  |     *pDst++ = (INT16)(*pSrc++ << val);  | 
82  |  | 
  | 
83  | 0  |   return PRIMITIVES_SUCCESS;  | 
84  | 0  | }  | 
85  |  |  | 
86  |  | /* ------------------------------------------------------------------------- */  | 
87  |  | static INLINE pstatus_t general_rShiftC_16u(const UINT16* pSrc, UINT32 val, UINT16* pDst,  | 
88  |  |                                             UINT32 len)  | 
89  | 0  | { | 
90  | 0  |   if (val == 0)  | 
91  | 0  |     return PRIMITIVES_SUCCESS;  | 
92  | 0  |   if (val >= 16)  | 
93  | 0  |     return -1;  | 
94  |  |  | 
95  | 0  |   while (len--)  | 
96  | 0  |     *pDst++ = *pSrc++ >> val;  | 
97  |  | 
  | 
98  | 0  |   return PRIMITIVES_SUCCESS;  | 
99  | 0  | }  | 
100  |  |  | 
101  |  | /* ------------------------------------------------------------------------- */  | 
102  |  | static INLINE pstatus_t general_shiftC_16s(const INT16* pSrc, INT32 val, INT16* pDst, UINT32 len)  | 
103  | 0  | { | 
104  | 0  |   if (val == 0)  | 
105  | 0  |     return PRIMITIVES_SUCCESS;  | 
106  |  |  | 
107  | 0  |   if (val < 0)  | 
108  | 0  |     return general_rShiftC_16s(pSrc, -val, pDst, len);  | 
109  | 0  |   else  | 
110  | 0  |     return general_lShiftC_16s(pSrc, val, pDst, len);  | 
111  | 0  | }  | 
112  |  |  | 
113  |  | /* ------------------------------------------------------------------------- */  | 
114  |  | static INLINE pstatus_t general_shiftC_16u(const UINT16* pSrc, INT32 val, UINT16* pDst, UINT32 len)  | 
115  | 0  | { | 
116  | 0  |   if (val == 0)  | 
117  | 0  |     return PRIMITIVES_SUCCESS;  | 
118  |  |  | 
119  | 0  |   if (val < 0)  | 
120  | 0  |     return general_rShiftC_16u(pSrc, -val, pDst, len);  | 
121  | 0  |   else  | 
122  | 0  |     return general_lShiftC_16u(pSrc, val, pDst, len);  | 
123  | 0  | }  | 
124  |  |  | 
125  |  | /* ------------------------------------------------------------------------- */  | 
126  |  | void primitives_init_shift(primitives_t* prims)  | 
127  | 1  | { | 
128  |  |   /* Start with the default. */  | 
129  | 1  |   prims->lShiftC_16s_inplace = general_lShiftC_16s_inplace;  | 
130  | 1  |   prims->lShiftC_16s = general_lShiftC_16s;  | 
131  | 1  |   prims->rShiftC_16s = general_rShiftC_16s;  | 
132  | 1  |   prims->lShiftC_16u = general_lShiftC_16u;  | 
133  | 1  |   prims->rShiftC_16u = general_rShiftC_16u;  | 
134  |  |   /* Wrappers */  | 
135  | 1  |   prims->shiftC_16s = general_shiftC_16s;  | 
136  | 1  |   prims->shiftC_16u = general_shiftC_16u;  | 
137  | 1  | }  | 
138  |  |  | 
139  |  | void primitives_init_shift_opt(primitives_t* WINPR_RESTRICT prims)  | 
140  | 0  | { | 
141  | 0  |   primitives_init_shift_sse3(prims);  | 
142  | 0  | }  |