Newsgroups: | comp.compilers |
From: | pardo@june.cs.washington.edu (David Keppel) |
References: | <1990Jun12.163959.2593@esegue.segue.boston.ma.us> <1990Jun13.143951.2129@esegue.segue.boston.ma.us> |
Date: | Fri, 15 Jun 90 05:13:49 GMT |
Organization: | University of Washington, Computer Science, Seattle |
Keywords: | code, optimize |
This started out as a fast vs. safe debate. I'll digress left.
moss@cs.umass.edu (Eliot Moss) writes:
>[There are optimizations that will transform a[i] to *a forms.]
And indeed, there are machines on which the cannonical strcpy
char *
strcpy (char *d, char const *s)
{
char *orig = d;
while (*d++ = *s++)
; /* VOID */
return (orig);
}
is faster as
char *
strcpy (char *d, char const *s)
{
int i = 0;
while (d[i] = s[i])
++i;
return (d);
}
The MIPS R{2,3}000 spring to mind. In fact, so does the 80386, or anything
else that isn't VAXish. A moment's consideration should (hopefully) convince
you that the first form requires two increments per iteration, while the
latter requires only one. The only case when the first is cheaper is when
two pointer increments are cheaper than one integer increment. The point
being that pointer arith. isn't always a win.
;-D on ( Poineters and patience ) Pardo
--
pardo@cs.washington.edu
{rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.