Agner Fog wrote:
Michael Matz wrote:
You must be doing something wrong. If the compiler decides to inline the string ops it either knows the size or you told it to do it anyway (-minline-all-stringops or -minline-stringops-dynamically). In both cases will it use wider than byte moves when possible.
g++ (v. 4.2.3) without any options converts memcpy with unknown size to rep movsb
g++ with option -fno-builtin calls memcpy in libc

The rep movs, stos, scas, cmps instructions are slower than function calls except in rare cases. The compiler should never use the string instructions. It is OK to use mov instructions if the size is known, but not string instructions.
I assume Agner is talking about the i386 target defaults, while Michael was talking about other target defaults. People who code for i386 must often use memcpy for short or medium length unaligned strings, and should be aware of the issues of long memcpy strings. Even for i386, the compiler should recognize where, for example, a single int move is explicitly the right thing. The rep string issue has been prominent enough for newer CPUs to be designed to recover some of the performance.

Reply via email to