Mail Archives: djgpp/1996/06/13/21:32:22
In article <4pmscu$nrt AT rs18 DOT hrz DOT th-darmstadt DOT de>,
lehmann AT mathematik DOT th-darmstadt DOT de says...
>
>Richard Young (richard DOT young AT crc DOT doc DOT ca) wrote:
>: A question for the optimization experts:
>
>: For moving data, is it faster to use
>
>: a) memcpy(x,y,n*sizeof(x[0]))
>
>: or
>
>: b) for (i = 0; i < n; i++) x[i] = y[i];
>
>: or are they basically the same speed.
>
>: With C++ is it better code practice to use b) over a)?
>
>(a) uses the function dj_movedata, which will use the repeat
>instruction to copy 4 byte values, which should be pretty fast.
>
>(b) requires a lots of address calculations, unless the compiler is
>very smart (I don't think so), but it can be sped up a bit at least
>(assuming that x and y are of type foo):
>
>foo *px,*py;
>int i;
>
>for(i=n,px=x,py=y; i ; i--) *py++=*px++;
>
>You still don't not get a repeat instruction, but at least you save
>the index calculations.
>
>
>bye, Alexander
>
>--
>Alexander Lehmann, | "On the Internet,
>alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows
>lehmann AT mathematik DOT th-darmstadt DOT de (plain) | you're a dog."
>!!CHANGED!! <URL:http://www.mathematik.th-darmstadt.de/~lehmann/>
With the powerful offset addressing modes of today's processors I find it hard
to believe that
for(i=n,px=x,py=y; i ; i--) *py++=*px++;
is faster than
for (i = 0; i < n; i++) x[i] = y[i];
I would also expect that the code optimizers should be able to invoke repeat
instructions for tight loops. Just how good or bad are the optimizers?
- Raw text -