Author: Dieter Buerssner
Date: 10:31:41 05/14/03
Go up one level in this thread
On May 14, 2003 at 11:59:52, Ulrich Tuerke wrote: >On Intel architectures, the "memcpy" function usually maps to an assembler >instruction to copy bytes (iirc "movsb"). Uli, they are a bit more sophisticated now. I looked at MSVC 6 and at GCC 3.2 (DJGPP). The library memcpy function will try to align the destination at a dword boundary (and copy up to 3 single bytes to achieve this), then use rep movsd, and for the remaining bytes use rep movsb (again at most 3 bytes). Both compilers can inline memcpy (and will typically do). With -O, for small memory regions gcc will use some normal mov(s). For longer memory regions, it will use rep movsd, and for very large memory regions, it will call the memcpy library function. If letting it optimize for Pentium 4 or Athlon, in the cases I checked it did not use rep movsd but rather normal mov(s) for intermediate sizes, where "normal" optimization would have used rep movsd. I guess the compiler writers know what they are doing here, and this is actually faster (but needs more code). For structure assignements, basically the same pattern. So, to me it seems a good idea to trust the compiler here. It seems to try hard to produce very decent code. But this has not too much to do anymore with the original question, and even less with computer chess. >In case one has really large arrays or structures to be copied it could be >worthwhile to use an assembler routine which invokes the instruction to copy >long words ("movsd"). I think, it is actually clever of gcc to not inline very large copies. The function call overhead will be neglible, and the compiler trusts the library writer here, who can optimize for larger memory and do the beforementioned tricks, which would be too much hassle for small memory. It may even be again dependent on specific compiler options, but I did not check this. I also did not check, what happens with structures that have gaps for alignment (Heiner's remark). >I could imagine that an itelligent compiler implementation maps "=" in case of >structures to the "movsd". But one has to check. Yes, it does this. Cheers, Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.