Coverage Report

Created: 2025-07-01 06:46

/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* WINPR_RESTRICT 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* WINPR_RESTRICT 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* WINPR_RESTRICT 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
    const size_t s = thiswidth << 2;
71
0
    WINPR_ASSERT(thiswidth <= INT32_MAX);
72
0
    prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s);
73
0
    remaining -= thiswidth;
74
0
    span <<= 1;
75
0
  }
76
77
0
  return PRIMITIVES_SUCCESS;
78
0
}
79
80
/* ------------------------------------------------------------------------- */
81
static pstatus_t general_set_32u(UINT32 val, UINT32* WINPR_RESTRICT pDst, UINT32 len)
82
0
{
83
0
  UINT32* dptr = pDst;
84
0
  size_t span = 0;
85
0
  size_t remaining = 0;
86
0
  primitives_t* prims = NULL;
87
88
0
  if (len < 256)
89
0
  {
90
0
    while (len--)
91
0
      *dptr++ = val;
92
93
0
    return PRIMITIVES_SUCCESS;
94
0
  }
95
96
  /* else quadratic growth memcpy algorithm */
97
0
  span = 1;
98
0
  *dptr = val;
99
0
  remaining = len - 1;
100
0
  prims = primitives_get();
101
102
0
  while (remaining)
103
0
  {
104
0
    size_t thiswidth = span;
105
106
0
    if (thiswidth > remaining)
107
0
      thiswidth = remaining;
108
109
0
    const size_t s = thiswidth << 2;
110
0
    WINPR_ASSERT(thiswidth <= INT32_MAX);
111
0
    prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s);
112
0
    remaining -= thiswidth;
113
0
    span <<= 1;
114
0
  }
115
116
0
  return PRIMITIVES_SUCCESS;
117
0
}
118
119
/* ------------------------------------------------------------------------- */
120
void primitives_init_set(primitives_t* WINPR_RESTRICT prims)
121
0
{
122
  /* Start with the default. */
123
0
  prims->set_8u = general_set_8u;
124
0
  prims->set_32s = general_set_32s;
125
0
  prims->set_32u = general_set_32u;
126
0
  prims->zero = general_zero;
127
0
}
128
129
void primitives_init_set_opt(primitives_t* WINPR_RESTRICT prims)
130
0
{
131
0
  primitives_init_set(prims);
132
0
  primitives_init_set_sse2(prims);
133
0
}