summaryrefslogtreecommitdiff
path: root/firmware/asm/mempcpy.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2014-08-06 04:26:52 -0400
committerMichael Sevakis <jethead71@rockbox.org>2014-08-29 22:06:57 -0400
commit77b3625763ae4d5aa6aaa9d44fbc1bfec6b29335 (patch)
tree74b12e2669da8653932f48f1ca3816eef4bf6324 /firmware/asm/mempcpy.c
parent7d1a47cf13726c95ac46027156cc12dd9da5b855 (diff)
downloadrockbox-77b3625763ae4d5aa6aaa9d44fbc1bfec6b29335.tar.gz
rockbox-77b3625763ae4d5aa6aaa9d44fbc1bfec6b29335.zip
Add mempcpy implementation
A GNU extension that returns dst + size instead of dst. It's a nice shortcut when copying strings with a known size or back-to-back blocks and you have to do it often. May of course be called directly or alternately through __builtin_mempcpy in some compiler versions. For ASM on native targets, it is implemented as an alternate entrypoint to memcpy which adds minimal code and overhead. Change-Id: I4cbb3483f6df3c1007247fe0a95fd7078737462b
Diffstat (limited to 'firmware/asm/mempcpy.c')
-rw-r--r--firmware/asm/mempcpy.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/firmware/asm/mempcpy.c b/firmware/asm/mempcpy.c
new file mode 100644
index 0000000000..2b1ccecbe8
--- /dev/null
+++ b/firmware/asm/mempcpy.c
@@ -0,0 +1,47 @@
1/*
2FUNCTION
3 <<mempcpy>>---copy memory regions and return end pointer
4
5ANSI_SYNOPSIS
6 #include <string.h>
7 void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
8
9TRAD_SYNOPSIS
10 void *mempcpy(<[out]>, <[in]>, <[n]>
11 void *<[out]>;
12 void *<[in]>;
13 size_t <[n]>;
14
15DESCRIPTION
16 This function copies <[n]> bytes from the memory region
17 pointed to by <[in]> to the memory region pointed to by
18 <[out]>.
19
20 If the regions overlap, the behavior is undefined.
21
22RETURNS
23 <<mempcpy>> returns a pointer to the byte following the
24 last byte copied to the <[out]> region.
25
26PORTABILITY
27<<mempcpy>> is a GNU extension.
28
29<<mempcpy>> requires no supporting OS subroutines.
30
31 */
32
33#include "config.h"
34#include "_ansi.h" /* for _DEFUN */
35#include <string.h>
36
37/* This may be conjoined with memcpy in <cpu>/memcpy.S to get it nearly for
38 free */
39
40_PTR
41_DEFUN (mempcpy, (dst0, src0, len0),
42 _PTR dst0 _AND
43 _CONST _PTR src0 _AND
44 size_t len0)
45{
46 return memcpy(dst0, src0, len0) + len0;
47}