Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Arm Trusted Firmware
Commits
0b96df76
Commit
0b96df76
authored
Sep 09, 2020
by
Mark Dykes
Committed by
TrustedFirmware Code Review
Sep 09, 2020
Browse files
Merge "libc: memset: improve performance by avoiding single byte writes" into integration
parents
7fbb3dba
75fab649
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/libc/memset.c
View file @
0b96df76
/*
* Copyright (c) 2013-20
19
, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2013-20
20
, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stddef.h>
#include <string.h>
#include <stdint.h>
void
*
memset
(
void
*
dst
,
int
val
,
size_t
count
)
{
char
*
ptr
=
dst
;
uint64_t
*
ptr64
;
uint64_t
fill
=
(
unsigned
char
)
val
;
while
(
count
--
)
/* Simplify code below by making sure we write at least one byte. */
if
(
count
==
0
)
{
return
dst
;
}
/* Handle the first part, until the pointer becomes 64-bit aligned. */
while
(((
uintptr_t
)
ptr
&
7
))
{
*
ptr
++
=
val
;
if
(
--
count
==
0
)
{
return
dst
;
}
}
/* Duplicate the fill byte to the rest of the 64-bit word. */
fill
|=
fill
<<
8
;
fill
|=
fill
<<
16
;
fill
|=
fill
<<
32
;
/* Use 64-bit writes for as long as possible. */
ptr64
=
(
void
*
)
ptr
;
for
(;
count
>=
8
;
count
-=
8
)
{
*
ptr64
++
=
fill
;
}
/* Handle the remaining part byte-per-byte. */
ptr
=
(
void
*
)
ptr64
;
while
(
count
--
)
{
*
ptr
++
=
val
;
}
return
dst
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment