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