On Tuesday 13 December 2005 01:53, Daniel Néri wrote: > Andrew Paulsen <andrew.paul...@gmail.com> writes: > > On 12/10/05, Dmitry <di...@spec.ru> wrote: > >> This is strange... > >> This bug has been fixed a while ago ... > >> Try to lower optimization to -O > > > > I tried this and it did not help. Any other suggestions? > > In my slightly hacked libc, I've replaced that over-engineered (at > least for MSP430) memcpy implementation with the following:
Your modified memcpy works for most situations, but doesn't handle overlapping arrays properly, if src < dst. If the arrays overlap, then the copy to dst will overwrite the end of src before it is copied. This is why the libc memcopy has a block for "copy backwards" if src < dst. The rest of libc's memcpy is a bit of logic to align to a word boundary so that word operations can be used for the copy, cutting the number of loops in half. Copying large blocks of memory would be considerably faster with word operations, but the overhead of aligning to a word boundary would be significant if the block is very short. Considering the MSP430's small RAM, most uses of memcpy probably involve short buffer lengths. Neil