From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,ab3048d7983050df,start X-Google-Attributes: gid1164f8,public From: jkb@mrc-lmb.cam.ac.uk (James Bonfield) Subject: cc vs cc -migrate on Digital Unix Date: 1996/06/18 Message-ID: <4q6pvi$s5m@lyra.csx.cam.ac.uk>#1/1 X-Deja-AN: 160861760 distribution: world organization: MRC Laboratory of Molecular Biology, Cambridge UK newsgroups: comp.sys.dec 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/