Re: memcpy_toio on i386 using byte writes even when n%2==0

From: Robert Hancock
Date: Tue May 30 2006 - 20:55:26 EST


linux-os (Dick Johnson) wrote:
If byte writes are used, they should always be last for any
odd byte. I think you found a bug in spite of the fact that
whoever made the revision to memcpy probably thinks they
did something 'cool'. This is an example of cute code causing
problems. The classic example of a proper memcpy() that uses
the ix86 built-in macros runs like this:

pushl %esi # Save precious registers
pushl %edi
movl COUNT(%esp),%ecx
movl SOURCE(%esp),%esi
movl DEST(%esp),%edi
cld
shrl $1,%ecx # Make WORDS, possibly set carry
rep movsw # Copy the words
adcl %ecx,%ecx # Any spare byte
rep movsb # Copy any spare byte
popl %edi # Restore precious registers
popl %esi

Note that there isn't any code for moving dwords because the
chances of gaining anything are slim (alignment may hurt).

I'd say the chances of gaining something from executing half as many instructions on copying a large block of memory are very good indeed..

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@xxxxxxxxxxxxx
Home Page: http://www.roberthancock.com/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/