[PATCH] Use memcpy in memmove when possible

Maxim Kuvyrkov maxim@codesourcery.com
Fri Sep 7 08:10:00 GMT 2012


On 7/09/2012, at 7:58 AM, Roland McGrath wrote:

> Definitely do not insert an extra RETURN (dest).  There's no reason for that.
> 
> You should use tail calls for the memcpy invocations.  i.e.
> 	return memcpy (dest, src, len);
> 
> To avoid more #if nonsense for the bcopy case, write:
> 	dest = memcpy (dest, src, len);
> 
> Then the compiler ought to turn it into the tail call (but verify that).
> 
> Is there really ever going to be a case for MEMCPY_OK_FOR_BWD_MEMMOVE?
> That is, will there ever be an implementation of memcpy that works for the
> overlapping case but not the nonoverlapping case?  I can't really imagine
> one.  If there isn't, then any case that would define your
> MEMCPY_OK_FOR_BWD_MEMMOVE macro should really just be making memmove an
> alias for memcpy instead.

OK, fair enough.  Attached is the simplified patch.  I confirmed that the compiler is able to optimize the tail call.

Thanks,

--
Maxim Kuvyrkov
CodeSourcery / Mentor Graphics
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Use-memcpy-in-memmove-when-possible.patch
Type: application/octet-stream
Size: 2909 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120907/f2e7106b/attachment.obj>


More information about the Libc-alpha mailing list