From: Alexander Holler <holler@ahsoftware.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2] memcpy/memmove: Do not copy to same address
Date: Mon, 23 May 2011 23:07:23 +0200 [thread overview]
Message-ID: <4DDACC8B.6090507@ahsoftware.de> (raw)
In-Reply-To: <1306141435-24001-1-git-send-email-weisserm@arcor.de>
Hello,
Am 23.05.2011 11:03, schrieb Matthias Weisser:
> In some cases (e.g. bootm with a elf payload which is already at the right
> position) there is a in place copy of data to the same address. Catching this
> saves some ms while booting.
>
> Signed-off-by: Matthias Weisser<weisserm@arcor.de>
> ---
> Changes since V1:
> - Made subject more informative
> - Removed the optimization from bcopy as bcopy is not used anywhere
>
> lib/string.c | 6 ++++++
> 1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/lib/string.c b/lib/string.c
> index b375b81..2c4f0ec 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -467,6 +467,9 @@ void * memcpy(void *dest, const void *src, size_t count)
> unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
> char *d8, *s8;
>
> + if (src == dest)
> + return dest;
> +
here is the same, as in the patch I've commented before. There exist no
reason to add a check for identity to memcpy() because memcpy doesn't
support overlapping regions (and identity is just a special case of
overlapping regions). If something might call memcpy() with overlapping
or identical regions, it should use memmove().
> /* while all data is aligned (common case), copy a word at a time */
> if ( (((ulong)dest | (ulong)src)& (sizeof(*dl) - 1)) == 0) {
> while (count>= sizeof(*dl)) {
> @@ -497,6 +500,9 @@ void * memmove(void * dest,const void *src,size_t count)
> {
> char *tmp, *s;
>
> + if (src == dest)
> + return dest;
> +
> if (dest<= src) {
Here it is ok, but the check <= could be modified to < too.
Just to clarify my reasoning: the only reason why memcpy() exists, is
because it should have been a faster version of memmove() without the
necessary checks.
So if a bug proof of version of memcpy() is wanted, there is no need to
have a different implementation for memcpy() and memcpy() could just be
an alias for memmove().
But adding a check for identity to memcpy() is unnecessary.
Sorry, but I had to comment this after having read to many comments in a
bug about something similiar in
https://bugzilla.redhat.com/show_bug.cgi?id=638477
(Be aware, reading that bug might hurt your brain)
Regards,
Alexander
next prev parent reply other threads:[~2011-05-23 21:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-12 6:58 [U-Boot] [PATCH] Do not copy to same address Matthias Weisser
2011-04-12 7:05 ` Mike Frysinger
2011-04-12 7:16 ` Matthias Weißer
2011-04-12 7:06 ` Albert ARIBAUD
2011-04-12 7:13 ` Matthias Weißer
2011-04-12 7:27 ` Albert ARIBAUD
2011-04-12 7:49 ` Matthias Weißer
2011-04-14 6:28 ` Albert ARIBAUD
2011-05-23 9:03 ` [U-Boot] [PATCH V2] memcpy/memmove: " Matthias Weisser
2011-05-23 21:07 ` Alexander Holler [this message]
2011-05-23 21:55 ` Wolfgang Denk
2011-05-23 22:12 ` Alexander Holler
2011-05-23 22:22 ` Wolfgang Denk
2011-05-23 22:38 ` Alexander Holler
2011-05-24 3:47 ` Mike Frysinger
2011-05-24 13:03 ` Alexander Holler
2011-05-24 19:37 ` Scott Wood
2011-05-24 20:39 ` Wolfgang Denk
2011-06-14 6:18 ` Matthias Weißer
2011-06-16 16:04 ` Matthias Weisser
2011-06-30 6:31 ` Matthias Weißer
2011-07-25 22:28 ` Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DDACC8B.6090507@ahsoftware.de \
--to=holler@ahsoftware.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.