Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* cc vs cc -migrate on Digital Unix
@ 1996-06-18  4:00 James Bonfield
  1996-06-20  4:00 ` Kevin Oberman
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: James Bonfield @ 1996-06-18  4:00 UTC (permalink / raw)




I've been trying to work out the difference between cc and cc -migrate.
They seem to produce suprisingly different code than each other. As an
example here's a simple byte swapping routine.

#define swap_int4(src, dst) \
do { \
    ((char *)&(dst))[0] = ((char *) &(src))[3];\
    ((char *)&(dst))[1] = ((char *) &(src))[2];\
    ((char *)&(dst))[2] = ((char *) &(src))[1];\
    ((char *)&(dst))[3] = ((char *) &(src))[0];\
} while (0)

static void swap4(int *src, int *dst, int N)
{
    for(; N; N--, src++, dst++)
        swap_int4(*src, *dst);
}

#define TEST_SIZE 250000
int main() {
    int buf_src[TEST_SIZE];
    int buf_dst[TEST_SIZE];
    int i;

    for (i = 0; i < 100; i++) {
        swap4(buf_src, buf_dst, TEST_SIZE);
    }

    return 0;
}

Compiling and running this with both cc and cc -migrate gives the following
results.

Command			Time, best of 3 runs (150Mhz DEC 3000/500)
==================================================================
cc -O4		       10.5 user  0.1 system
cc -O4 -migrate		3.6 user  0.0 system

That's an enormous difference. Rewriting the above macro as below yields
further results.

#define swap_int4(src, dst) \
do { \
    dst = ((src & 0x000000ff) << 24) + \
          ((src & 0x0000ff00) <<  8) + \
          ((src & 0x00ff0000) >>  8) + \
          ((src & 0xff000000) >> 24); \
} while (0)

Command			Time, best of 3 runs (150Mhz DEC 3000/500)
==================================================================
cc -O4			3.7 user  0.1 system
cc -O4 -migrate		3.0 user  0.1 system

Looks like it's a better macro for both programs and cc has now got around
that terrible performance hit. cc -migrate still has the edge.

I then noticed that the "do {...} while (0)" construct wasn't so useful in the
new macro as it's 1 C statement anyway, so I changed the macro again to the
following and recompiled.

#define swap_int4(src, dst) \
    dst = ((src & 0x000000ff) << 24) + \
          ((src & 0x0000ff00) <<  8) + \
          ((src & 0x00ff0000) >>  8) + \
          ((src & 0xff000000) >> 24);

Command			Time, best of 3 runs (150Mhz DEC 3000/500)
==================================================================
cc -O4			3.3 user  0.1 system
cc -O4 -migrate		3.0 user  0.0 system

So it appears that having a "do {...} while (0)" around a statement causes a
penalty for optimising with cc, but none for cc -migrate.
At the end of this it appears that cc -migrate is definitely the superior
compiler. Why does using this flag change things so much!? I suspect that cc
-migrate is actually an entirely different compiling engine. If it's really
better (obviously my benchmarks are one specialist and trivial case) why isn't
it the default system? I haven't got gcc compiled up on my system and I
haven't got the real c89 either so I haven't compared these.

Trying gcc on Solaris and cc on Irix I find that all these pieces of source
compile and optimise to give the same efficiency.

Any suggestions on which compiler to use for real production software?

Cheers,

	James
--
James Bonfield (jkb@mrc-lmb.cam.ac.uk)   Tel: 01223 402499   Fax: 01223 412282
Medical Research Council - Laboratory of Molecular Biology,
Hills Road, Cambridge, CB2 2QH, England.
Also see Staden Package WWW site at http://www.mrc-lmb.cam.ac.uk/pubseq/



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1996-06-20  4:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-06-18  4:00 cc vs cc -migrate on Digital Unix James Bonfield
1996-06-20  4:00 ` Kevin Oberman
1996-06-20  4:00 ` Jeff Donsbach
1996-06-20  4:00 ` Petri Kaukasoina
1996-06-20  4:00 ` Burkhard Neidecker-Lutz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox