[uClibc] uclibc for the desktop

Joakim Tjernlund joakim.tjernlund at lumentis.se
Wed Nov 5 10:10:18 UTC 2003


Here is an optimized memcpy I posted earlier. It requires unaligned reads to
to work.

 Jocke
PS.
   Please CC me as I not on the list.

[SNIP]
> 
> Here is a C version which generates assembler which is very close
> to the memcpy in the linux kernel for PPC(gcc 2.95.3).
> Not tested, but compiles. What do you think?
> 
>  Jocke
> 
> void *memcpy(void *to, const void *from, size_t n)
> {
> 	unsigned long rem, chunks, tmp1, tmp2;
> 	void *tmp_to;
> 
> 	chunks = n / 8;
> 	from -= 4;
> 	tmp_to = to - 4;
> 	if (!chunks)
> 		goto lessthan8;
> 	rem = (unsigned long )tmp_to % 4;
> 	if (rem)
> 		goto align;
>  copy_chunks:
> 	do {
> 		tmp1 = *(unsigned long *)(from+4);
> 		from += 8;
> 		tmp2 = *(unsigned long *)from;
> 		*(unsigned long *)(tmp_to+4) = tmp1;
> 		tmp_to += 8;
> 		*(unsigned long *)tmp_to = tmp2;
> 	} while (--chunks);
>  lessthan8:
> 	n = n % 8;
> 	if (n >= 4) {
> 		*++(unsigned long *)tmp_to = *++(unsigned long *)from;
> 		n = n-4;
> 	}
> 	if (!n ) return to;
> 	from += 3;
> 	tmp_to += 3;
> 	do {
> 		*++(unsigned char *)tmp_to = *++(unsigned char *)from;
> 	} while (--n);
> 	
> 	return to;
>  align:
> 	rem = 4 - rem;
> 	n = n-rem;
> 	do {
> 		*(unsigned char *)(tmp_to+4) = *(unsigned char *)(from+4);
> 		++from;
> 		++tmp_to;
> 	} while (--rem);
> 	chunks = n / 8;
> 	if (chunks)
> 		goto copy_chunks;
> 	goto lessthan8;
> }
> 



More information about the uClibc mailing list