public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chris Moore <moore@free.fr>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V3 1/3] lib_generic memcpy: copy one word at a	time if possible
Date: Mon, 12 Oct 2009 06:37:12 +0200	[thread overview]
Message-ID: <4AD2B278.4010103@free.fr> (raw)
In-Reply-To: <20091010074431.GA3732@mail.gnudd.com>

Hi Alessandro,

Alessandro Rubini a ?crit :
>>> +	unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
>>>       
>
>   
>> Nitpick: Are you sure the casts are necessary here ?
>>     
>
> Without the one on src it complains because of "const". So I write
> both for symetry.
>   

Yes, of course, you and the compiler are absolutely right.
Silly me, I completely overlooked the const :(
To me casting away const is a cardinal sin (it rather defeats the 
object) and I find that the ease with which it can be done in C is 
frightening.
So I feel obliged to (hopefully) correct my submission:

void *memcpy(void *dest, const void *src, size_t count)
{
	char *d8;
	const char *s8;
	unsigned long *dl = dest;
	const unsigned long *sl = src;

	/* while all data is aligned (common case), copy multiple bytes at a time */
	if ( (((int)(long)dest | (int)(long)src) & (sizeof(*dl) - 1)) == 0) {
		while (count >= sizeof(*dl)) {
			*dl++ = *sl++;
			count -= sizeof(*dl);
		}
	}

	d8 = (char *)dl;
	s8 = (const char *)sl;

	/* copy any remaining data byte by byte */
	while (count--)
		*d8++ = *s8++;

	return dest;
}

But this is still not even compile tested :(
I never learn :(

Cheers,
Chris

      reply	other threads:[~2009-10-12  4:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-09  9:12 [U-Boot] [PATCH V3 1/3] lib_generic memcpy: copy one word at a time if possible Alessandro Rubini
2009-10-09 10:21 ` Mike Frysinger
2009-10-09 10:50   ` Alessandro Rubini
2009-10-10  6:13 ` Chris Moore
2009-10-10  7:44   ` Alessandro Rubini
2009-10-12  4:37     ` Chris Moore [this message]

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=4AD2B278.4010103@free.fr \
    --to=moore@free.fr \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox