From 77b3625763ae4d5aa6aaa9d44fbc1bfec6b29335 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 6 Aug 2014 04:26:52 -0400 Subject: 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 --- firmware/asm/mempcpy.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 firmware/asm/mempcpy.c (limited to 'firmware/asm/mempcpy.c') 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 @@ +/* +FUNCTION + <>---copy memory regions and return end pointer + +ANSI_SYNOPSIS + #include + void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); + +TRAD_SYNOPSIS + void *mempcpy(<[out]>, <[in]>, <[n]> + void *<[out]>; + void *<[in]>; + size_t <[n]>; + +DESCRIPTION + This function copies <[n]> bytes from the memory region + pointed to by <[in]> to the memory region pointed to by + <[out]>. + + If the regions overlap, the behavior is undefined. + +RETURNS + <> returns a pointer to the byte following the + last byte copied to the <[out]> region. + +PORTABILITY +<> is a GNU extension. + +<> requires no supporting OS subroutines. + + */ + +#include "config.h" +#include "_ansi.h" /* for _DEFUN */ +#include + +/* This may be conjoined with memcpy in /memcpy.S to get it nearly for + free */ + +_PTR +_DEFUN (mempcpy, (dst0, src0, len0), + _PTR dst0 _AND + _CONST _PTR src0 _AND + size_t len0) +{ + return memcpy(dst0, src0, len0) + len0; +} -- cgit v1.2.3