TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DARIN MCBRIDE
from: HERMAN SCHONFELD
date: 1997-04-23 17:52:00
subject: DJGPP OPTIMIZATIONS

 HS> compilers compiling that fastest code possible".
 HS> Lets see now, where did I say that a compiler doesn't optimize?
 HS> Does a compiler change a *256 to a <<8?
You "obviously" are wrong, so why not admit it?
DM> 001c  8b 45 f8                          mov     eax,-8H[ebp]
DM> 001f  c1 e0 08                          shl     eax,08H
DM> 0022  89 45 fc                          mov     -4H[ebp],eax
DM>I believe you owe Carey an apology.  And yourself a little more
DM>education.
That basic example does not get optimized by most compilers, Darin.
Most compilers optimize code well, but just about all don't optimize
the fastest.
Since you obviously fail to comprehend this I shall demonstrate.
Loop1 :-
#define bSize(99999)
int bufSize = bSize;
char buf1[bSize];
char buf2[bSize];
int i;
for (i = 0; i < bufSize; i++)
{
  buf1[i] = buf2[i];
};
Thats the kind of code that I often see in source code.
Not very fast is it?
Oh, but you being so proffessional and all, you probably implement
loops that look like this..
Loop2 :-
int i;
char *p1, *p2;
p1 = &buf1[0];
p2 = &buf2[0];
for (i = 0; i < bufSize; i++)
{
 *p1++ = *p2++;
};
Pretty fast is it not? You'd probably be satisfied with that and let the
compiler do the rest of the work.
But some people (such as myself) had a reason for buying fast expensive
machines, they like to get the fastest possible performance.
I would optimize that loop to..
Loop3 :-
int i;
char *p1, *p2, *lst;
p1 = &buf[0];
lst = &buf1[bufSize - 1];
p2 = &buf2[0];
switch(bufSize & 0x3)
{
 case 3:
   *p1++ = *p2++;
 case 2:
   *p1++ = *p2++;
 case 1:
   *p1++ = *p2++;
}
if (p1 <= lst)
{
  do
  {
    *p1++ = *p2++;
    *p1++ = *p2++;
    *p1++ = *p2++;
    *p1++ = *p2++;
  } while (p1 <= lst);
};
See if Watcom will do that for you.. I think not..
Watcom results :-
---------------------------+
LOOP  |   386   |  486     |
------|---------|----------+
loop1 | 81.1 cy | 35.3 cy  |
loop2 | 38.7 cy | 29.7 cy  |
loop3 | 15.9 cy | 9.5  cy  |
---------------------------+
cy are cycles incase you haven't noticed.
Now that I have taught you, you may actually want to read the thread and
then come back with your apology.
Bye for now..
... Are computer viruses cybernetic organisms?
--- 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™.