2013-01-18 15:32:58 -07:00
|
|
|
/* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
|
* Routines to set a chunk of memory to a constant.
|
|
|
|
|
* vi:ts=4 sw=4:
|
|
|
|
|
*
|
|
|
|
|
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
|
* not use this file except in compliance with the License. You may obtain
|
|
|
|
|
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
|
* permissions and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-16 11:20:38 +01:00
|
|
|
#include <freerdp/config.h>
|
2013-01-19 14:27:34 -05:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
#include <string.h>
|
2013-02-21 02:45:10 -08:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
#include <freerdp/types.h>
|
|
|
|
|
#include <freerdp/primitives.h>
|
2013-02-21 02:45:10 -08:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
#include "prim_internal.h"
|
2024-06-17 11:51:03 +02:00
|
|
|
#include "prim_set.h"
|
2013-01-18 15:32:58 -07:00
|
|
|
|
|
|
|
|
/* ========================================================================= */
|
2025-03-10 18:17:49 +01:00
|
|
|
static pstatus_t general_set_8u(BYTE val, BYTE* WINPR_RESTRICT pDst, UINT32 len)
|
2013-01-18 15:32:58 -07:00
|
|
|
{
|
2019-11-06 15:24:51 +01:00
|
|
|
memset((void*)pDst, (int)val, (size_t)len);
|
2013-01-18 15:32:58 -07:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2025-03-10 18:17:49 +01:00
|
|
|
static pstatus_t general_zero(void* WINPR_RESTRICT pDst, size_t len)
|
2013-01-18 15:32:58 -07:00
|
|
|
{
|
|
|
|
|
memset(pDst, 0, len);
|
|
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ========================================================================= */
|
2025-03-10 18:17:49 +01:00
|
|
|
static pstatus_t general_set_32s(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 len)
|
2013-01-18 15:32:58 -07:00
|
|
|
{
|
2024-08-29 11:11:11 +02:00
|
|
|
INT32* dptr = pDst;
|
2024-01-23 16:49:54 +01:00
|
|
|
size_t span = 0;
|
|
|
|
|
size_t remaining = 0;
|
2013-01-18 15:32:58 -07:00
|
|
|
|
|
|
|
|
if (len < 256)
|
|
|
|
|
{
|
2019-11-06 15:24:51 +01:00
|
|
|
while (len--)
|
|
|
|
|
*dptr++ = val;
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* else quadratic growth memcpy algorithm */
|
|
|
|
|
span = 1;
|
|
|
|
|
*dptr = val;
|
|
|
|
|
remaining = len - 1;
|
2026-02-16 08:18:37 +01:00
|
|
|
primitives_t* prims = primitives_get();
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
while (remaining)
|
|
|
|
|
{
|
|
|
|
|
size_t thiswidth = span;
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2019-11-06 15:24:51 +01:00
|
|
|
if (thiswidth > remaining)
|
|
|
|
|
thiswidth = remaining;
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2024-10-14 15:50:38 +02:00
|
|
|
const size_t s = thiswidth << 2;
|
|
|
|
|
WINPR_ASSERT(thiswidth <= INT32_MAX);
|
2026-02-16 08:18:37 +01:00
|
|
|
const pstatus_t rc = prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s);
|
|
|
|
|
if (rc != PRIMITIVES_SUCCESS)
|
|
|
|
|
return rc;
|
2013-01-18 15:32:58 -07:00
|
|
|
remaining -= thiswidth;
|
|
|
|
|
span <<= 1;
|
|
|
|
|
}
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2025-03-10 18:17:49 +01:00
|
|
|
static pstatus_t general_set_32u(UINT32 val, UINT32* WINPR_RESTRICT pDst, UINT32 len)
|
2013-01-18 15:32:58 -07:00
|
|
|
{
|
2024-08-29 11:11:11 +02:00
|
|
|
UINT32* dptr = pDst;
|
2024-01-23 16:49:54 +01:00
|
|
|
size_t span = 0;
|
|
|
|
|
size_t remaining = 0;
|
2026-02-26 15:06:27 +01:00
|
|
|
primitives_t* prims = nullptr;
|
2013-01-18 15:32:58 -07:00
|
|
|
|
|
|
|
|
if (len < 256)
|
|
|
|
|
{
|
2019-11-06 15:24:51 +01:00
|
|
|
while (len--)
|
|
|
|
|
*dptr++ = val;
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* else quadratic growth memcpy algorithm */
|
|
|
|
|
span = 1;
|
|
|
|
|
*dptr = val;
|
|
|
|
|
remaining = len - 1;
|
|
|
|
|
prims = primitives_get();
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
while (remaining)
|
|
|
|
|
{
|
|
|
|
|
size_t thiswidth = span;
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2019-11-06 15:24:51 +01:00
|
|
|
if (thiswidth > remaining)
|
|
|
|
|
thiswidth = remaining;
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2024-10-14 15:50:38 +02:00
|
|
|
const size_t s = thiswidth << 2;
|
|
|
|
|
WINPR_ASSERT(thiswidth <= INT32_MAX);
|
2026-02-16 08:18:37 +01:00
|
|
|
const pstatus_t rc = prims->copy_8u((BYTE*)dptr, (BYTE*)(dptr + span), (INT32)s);
|
|
|
|
|
if (rc != PRIMITIVES_SUCCESS)
|
|
|
|
|
return rc;
|
|
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
remaining -= thiswidth;
|
|
|
|
|
span <<= 1;
|
|
|
|
|
}
|
2016-04-05 17:07:45 +02:00
|
|
|
|
2013-01-18 15:32:58 -07:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2024-09-12 12:52:21 +02:00
|
|
|
void primitives_init_set(primitives_t* WINPR_RESTRICT prims)
|
2013-01-18 15:32:58 -07:00
|
|
|
{
|
|
|
|
|
/* Start with the default. */
|
2019-11-06 15:24:51 +01:00
|
|
|
prims->set_8u = general_set_8u;
|
2013-01-18 15:32:58 -07:00
|
|
|
prims->set_32s = general_set_32s;
|
|
|
|
|
prims->set_32u = general_set_32u;
|
|
|
|
|
prims->zero = general_zero;
|
|
|
|
|
}
|
2024-06-17 11:51:03 +02:00
|
|
|
|
|
|
|
|
void primitives_init_set_opt(primitives_t* WINPR_RESTRICT prims)
|
|
|
|
|
{
|
2025-03-15 20:19:42 +01:00
|
|
|
primitives_init_set(prims);
|
2024-06-17 11:51:03 +02:00
|
|
|
primitives_init_set_sse2(prims);
|
|
|
|
|
}
|