Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Speeding code

Author: Ulrich Tuerke

Date: 08:59:52 05/14/03

Go up one level in this thread


On May 12, 2003 at 14:49:21, Dieter Buerssner wrote:

>On May 12, 2003 at 14:43:00, Tom Kerrigan wrote:
>
>>On May 12, 2003 at 10:38:57, Fermin Serrano wrote:
>>>	Question 3:
>>>	-----------------
>>>	To copy a structure into other, what is faster, doing by copy each of his
>>>elements or use a memcpy?
>>
>>Use memcpy. It may not be faster on your system, but it's optimized on other
>>systems that you might use later. If you copy individual elements yourself,
>>there's no chance it will be optimized on any system.

On Intel architectures, the "memcpy" function usually maps to an assembler
instruction to copy bytes (iirc "movsb").
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").

The latter one uses 1/4 of the processor cycles used by the 1st one (iirc this
had been the number for the good old 80386).

I could imagine that an itelligent compiler implementation maps "=" in case of
structures to the "movsd". But one has to check.

Uli


>
>I don't agree. Use the assignment operator ("=")! It should never do worse than
>memcpy or copying individual members. On many compilers, it will make no
>difference (especially compilers that inline memcpy). I can see, that memcpy can
>produce worse code (depending on struct size). I really cannot see, that with
>any decent compiler the very obvious and clear assignment can produce worse
>code.
>
>Regards,
>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.