/src/FreeRDP/libfreerdp/primitives/prim_set.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* FreeRDP: A Remote Desktop Protocol Client |
2 | | * Routines to set a chunk of memory to a constant. |
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 <string.h> |
20 | | |
21 | | #include <freerdp/types.h> |
22 | | #include <freerdp/primitives.h> |
23 | | |
24 | | #include "prim_internal.h" |
25 | | #include "prim_set.h" |
26 | | |
27 | | /* ========================================================================= */ |
28 | | static pstatus_t general_set_8u(BYTE val, BYTE* pDst, UINT32 len) |
29 | 0 | { |
30 | 0 | memset((void*)pDst, (int)val, (size_t)len); |
31 | 0 | return PRIMITIVES_SUCCESS; |
32 | 0 | } |
33 | | |
34 | | /* ------------------------------------------------------------------------- */ |
35 | | static pstatus_t general_zero(void* pDst, size_t len) |
36 | 0 | { |
37 | 0 | memset(pDst, 0, len); |
38 | 0 | return PRIMITIVES_SUCCESS; |
39 | 0 | } |
40 | | |
41 | | /* ========================================================================= */ |
42 | | static pstatus_t general_set_32s(INT32 val, INT32* pDst, UINT32 len) |
43 | 0 | { |
44 | 0 | INT32* dptr = pDst; |
45 | 0 | size_t span = 0; |
46 | 0 | size_t remaining = 0; |
47 | 0 | primitives_t* prims = NULL; |
48 | |
|
49 | 0 | if (len < 256) |
50 | 0 | { |
51 | 0 | while (len--) |
52 | 0 | *dptr++ = val; |
53 | |
|
54 | 0 | return PRIMITIVES_SUCCESS; |
55 | 0 | } |
56 | | |
57 | | /* else quadratic growth memcpy algorithm */ |
58 | 0 | span = 1; |
59 | 0 | *dptr = val; |
60 | 0 | remaining = len - 1; |
61 | 0 | prims = primitives_get(); |
62 | |
|
63 | 0 | while (remaining) |
64 | 0 | { |
65 | 0 | size_t thiswidth = span; |
66 | |
|
67 | 0 | if (thiswidth > remaining) |
68 | 0 | thiswidth = remaining; |
69 | |
|
70 | 0 | prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2); |
71 | 0 | remaining -= thiswidth; |
72 | 0 | span <<= 1; |
73 | 0 | } |
74 | |
|
75 | 0 | return PRIMITIVES_SUCCESS; |
76 | 0 | } |
77 | | |
78 | | /* ------------------------------------------------------------------------- */ |
79 | | static pstatus_t general_set_32u(UINT32 val, UINT32* pDst, UINT32 len) |
80 | 0 | { |
81 | 0 | UINT32* dptr = pDst; |
82 | 0 | size_t span = 0; |
83 | 0 | size_t remaining = 0; |
84 | 0 | primitives_t* prims = NULL; |
85 | |
|
86 | 0 | if (len < 256) |
87 | 0 | { |
88 | 0 | while (len--) |
89 | 0 | *dptr++ = val; |
90 | |
|
91 | 0 | return PRIMITIVES_SUCCESS; |
92 | 0 | } |
93 | | |
94 | | /* else quadratic growth memcpy algorithm */ |
95 | 0 | span = 1; |
96 | 0 | *dptr = val; |
97 | 0 | remaining = len - 1; |
98 | 0 | prims = primitives_get(); |
99 | |
|
100 | 0 | while (remaining) |
101 | 0 | { |
102 | 0 | size_t thiswidth = span; |
103 | |
|
104 | 0 | if (thiswidth > remaining) |
105 | 0 | thiswidth = remaining; |
106 | |
|
107 | 0 | prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), thiswidth << 2); |
108 | 0 | remaining -= thiswidth; |
109 | 0 | span <<= 1; |
110 | 0 | } |
111 | |
|
112 | 0 | return PRIMITIVES_SUCCESS; |
113 | 0 | } |
114 | | |
115 | | /* ------------------------------------------------------------------------- */ |
116 | | void primitives_init_set(primitives_t* prims) |
117 | 1 | { |
118 | | /* Start with the default. */ |
119 | 1 | prims->set_8u = general_set_8u; |
120 | 1 | prims->set_32s = general_set_32s; |
121 | 1 | prims->set_32u = general_set_32u; |
122 | 1 | prims->zero = general_zero; |
123 | 1 | } |
124 | | |
125 | | void primitives_init_set_opt(primitives_t* WINPR_RESTRICT prims) |
126 | 0 | { |
127 | 0 | primitives_init_set_sse2(prims); |
128 | 0 | } |