Should optimizing compilers automatically assign registers?
Istvan Mohos
istvan at hhb.UUCP
Mon May 7 02:24:58 AEST 1990
main() { /* prog1, compile with: /bin/cc -O prog1.c -o reg */
static unsigned char buf[4096];
register unsigned char *p;
for (p = buf + 4096; --p >= buf;)
for (; *p < 255; ++*p);
}
main() { /* prog2, compile with: /bin/cc -O prog2.c -o nonreg */
static unsigned char buf[4096];
unsigned char *p;
for (p = buf + 4096; --p >= buf;)
for (; *p < 255; ++*p);
}
Prog1 and prog2 are identical except that prog1 requests the
assignment of the auto variable p to a hardware register.
I mistakenly assumed that by using the -O flag, the compiler
would optimize prog2, and generate identical objects from
prog1 and prog2. Of the systems I tried this on, the Pyramid90X,
the Sparcstation1, and a SystemV 6300+ PC, proved this to be true.
A VAX Ultrix and a Sun3 proved me wrong. Here are some execution
times for the reg and nonreg objects, gotten on quiescent systems
using
/bin/time ./[non]reg >& [non]regtime
Ultrix:
regtime 15.8 real 3.1 user 0.9 sys
nonregtime 21.6 real 3.7 user 1.2 sys
6300+: 7.9 real 7.8 user 0.1 sys
Pyramid: 4.8 real 4.6 user 0.1 sys
Sun3:
regtime 1.7 real 1.6 user 0.0 sys
nonregtime 2.2 real 2.2 user 0.0 sys
Sparcstation1: 0.9 real 0.8 user 0.0 sys
Is the automatic allocation of a few variables into registers
too much to ask from an optimizing compiler?
--
Istvan Mohos
...uunet!pyrdc!pyrnj!hhb!istvan
RACAL-REDAC/HHB 1000 Wyckoff Ave. Mahwah NJ 07430 201-848-8000
======================================================================
More information about the Comp.unix.wizards
mailing list