TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CAREY BLOODWORTH
from: HERMAN SCHONFELD
date: 1997-05-02 19:32:00
subject: LOW LEVEL OPTIMIZATIO 1/2

HS>CB>void memcpy(char to[], char from[], int len)
HS>CB>{ while (len--) to[len]=from[len];}
HS>First off all, try unrolling the loop, and use pointer refferencing.
CB>Unrolling can help.  Pointers slow it down.  I've timed it.  Contrary to
CB>popular convention, pointers are _not_ automatically faster than
CB>indexing.
Pointers slow down on a machine with EDO ram and pentium processor. Typical 
of software developers to aim for about 80% of the market when spending a few 
simple hours can make a program 100% useable by all.
HS>But according to you, unrolling is bad, then use Duffs Device.
CB>In some cases, yes.  In other cases no.  It depends a lot on how much
CB>the loop does.  This is especially true when you tell the compiler to
CB>unroll loops with an optimization switch such as -O3 for DJGPP.
-O3 doesn't unroll loops. hence -funroll-loops & -funroll-all-loops also 
es.
HS>CB>void memcpy(char *to, char *from,int len)
HS>CB>{ while (len--) *to++=*from++;}
HS>len needs not be used like that in a while statement like that.
HS>It uses a register (which could be used for something else) so remove
CB>it, an
HS>restructure your loop.
CB>Yes it does use a register.  But even on the register poor x86
CB>architecture, most compilers will keep all three variables in registers.
CB>Only my 8 year old QC20 doesn't bother to keep _any_ of them in
CB>registers.
Not everyone has RISC machines carey.
... HHeellpp.. II''mm ssttuucckk iinn hhaallff--dduupplleexx.
--- Ezycom V1.48g0 01fd016b
---------------
* Origin: Fox's Lair BBS Bris Aus +61-7-38033908 V34+ Node 2 (3:640/238)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.