Another silly question
Pete Holsberg
pjh at mccc.UUCP
Wed May 24 02:32:17 AEST 1989
In article <25711 at amdcad.AMD.COM> tim at amd.com (Tim Olson) writes:
=However, if instead you wrote them like:
=
= int a[MAX]; int a[MAX];
= int i; int *p;
= for (i=0; i<MAX; ++i) for (p=&a[0]; p<&a[MAX]; ++p)
= a[i] = 0; *p=0;
=
=Then you indeed might get different assembly language generated. The
=second pointer version has had a "loop induction" optimization performed
=by hand. On some compiler/machine combinations, this will run faster,
=because the scaling operation and base/offset addition have been
=eliminated; on others it may run slower, because a specific addressing
=mode cannot be used.
Tim,
Here's the actual code. I think you've hit the nail on the head.
#define IMAX 10
#define LOOP 10000
main()
{
int a[IMAX];
register int * p;
int v=0;
while (v++ < LOOP)
for (p=a; p < &a[IMAX];)
*p++=v;
}
--
Pete Holsberg, Mercer County Community College, Trenton, NJ 08690
{backbone}!rutgers!njin!princeton!njsmu!mccc!pjh
More information about the Comp.lang.c
mailing list