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