Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
5c678349
Commit
5c678349
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Plain Diff
Merge branch 'iabdalkader-memcpy'
parents
bb295468
32781cce
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
stmhal/string0.c
+52
-10
52 additions, 10 deletions
stmhal/string0.c
with
52 additions
and
10 deletions
stmhal/string0.c
+
52
−
10
View file @
5c678349
...
...
@@ -27,14 +27,41 @@
#include
<stdint.h>
#include
"std.h"
void
*
memcpy
(
void
*
dest
,
const
void
*
src
,
size_t
n
)
{
// TODO align and copy 32 bits at a time
uint8_t
*
d
=
dest
;
const
uint8_t
*
s
=
src
;
for
(;
n
>
0
;
n
--
)
{
*
d
++
=
*
s
++
;
#define likely(x) __builtin_expect((x), 1)
void
*
memcpy
(
void
*
dst
,
const
void
*
src
,
size_t
n
)
{
if
(
likely
(
!
(((
uint32_t
)
dst
)
&
3
)
&&
!
(((
uint32_t
)
src
)
&
3
)))
{
// pointers aligned
uint32_t
*
d
=
dst
;
const
uint32_t
*
s
=
src
;
// copy words first
for
(
size_t
i
=
(
n
>>
2
);
i
;
i
--
)
{
*
d
++
=
*
s
++
;
}
if
(
n
&
2
)
{
// copy half-word
*
(
uint16_t
*
)
d
=
*
(
const
uint16_t
*
)
s
;
d
=
(
uint32_t
*
)((
uint16_t
*
)
d
+
1
);
s
=
(
const
uint32_t
*
)((
const
uint16_t
*
)
s
+
1
);
}
if
(
n
&
1
)
{
// copy byte
*
((
uint8_t
*
)
d
)
=
*
((
const
uint8_t
*
)
s
);
}
}
else
{
// unaligned access, copy bytes
uint8_t
*
d
=
dst
;
const
uint8_t
*
s
=
src
;
for
(;
n
;
n
--
)
{
*
d
++
=
*
s
++
;
}
}
return
dest
;
return
dst
;
}
void
*
memmove
(
void
*
dest
,
const
void
*
src
,
size_t
n
)
{
...
...
@@ -53,9 +80,24 @@ void *memmove(void *dest, const void *src, size_t n) {
}
void
*
memset
(
void
*
s
,
int
c
,
size_t
n
)
{
uint8_t
*
s2
=
s
;
for
(;
n
>
0
;
n
--
)
{
*
s2
++
=
c
;
if
(
c
==
0
&&
((
uint32_t
)
s
&
3
)
==
0
)
{
// aligned store of 0
uint32_t
*
s32
=
s
;
for
(
size_t
i
=
n
>>
2
;
i
>
0
;
i
--
)
{
*
s32
++
=
0
;
}
if
(
n
&
2
)
{
*
((
uint16_t
*
)
s32
)
=
0
;
s32
=
(
uint32_t
*
)((
uint16_t
*
)
s32
+
1
);
}
if
(
n
&
1
)
{
*
((
uint8_t
*
)
s32
)
=
0
;
}
}
else
{
uint8_t
*
s2
=
s
;
for
(;
n
>
0
;
n
--
)
{
*
s2
++
=
c
;
}
}
return
s
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment