From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,45b50f14dadfce5b X-Google-Attributes: gid1164f8,public X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,public X-Google-Thread: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public From: michael.williams@arm-sponge.com (Michael Williams) Subject: Re: Final kick at the "Merced Guessing Game" Date: 1997/10/15 Message-ID: <62204j$aio@sis.cambridge.arm.com>#1/1 X-Deja-AN: 280642172 X-Disclaimer: This posting does not express the views of Advanced RISC Machines Limited, unless explicitly stated. References: <61g30t$o2n@news-rocq.inria.fr> <61uoiu$19e$1@goanna.cs.rmit.edu.au> <61vbv8$nct@sis.cambridge.arm.com> X-Address: 90 Fulbourn Road, Cherry Hinton, Cambridge, CB1 4JN, UK Organization: Advanced RISC Machines Ltd X-Note: Remove the word "sponge" from my email address before replying Reply-To: michael.williams@arm-sponge.com Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec In article , Richard Black wrote: >michael.williams@arm-sponge.com (Michael Williams) writes: >But if gcc knows the same amount of information as Fortran (i.e. that >f() is side-effect-free) it can also make the same optimisation. viz: > >extern int f(int a) __attribute__ ((const)); > >int b(int a) >{ > return 0 * f(a); >} > >becomes (since you are at ARM): > >@ Generated by gcc 2.7.2 for ARM/(generic) >rfp .req r9 >sl .req r10 >fp .req r11 >ip .req r12 >sp .req r13 >lr .req r14 >pc .req r15 >gcc2_compiled.: >___gnu_compiled_c: >.text > .align 0 > .global _b >_b: > @ args = 0, pretend = 0, frame = 0 > @ frame_needed = 1, current_function_anonymous_args = 0 > mov ip, sp > stmfd sp!, {fp, ip, lr, pc} > mov r0, #0 > sub fp, ip, #4 > ldmea fp, {fp, sp, pc} Tsk. Norcroft ARM C compiles the equivalent: extern __pure int f(int a); int b(int a) { return 0 * f(a); } to b 000000 e3a00000 MOV a1,#0 000004 e1a0f00e MOV pc,lr I thought gcc was supposed to be catching up with our compiler? ;-) Back to thread, a point to make is that neither of these programs are ANSI C any more, and what's being discussed is ANSI C vs. ISO (?) Fortran. Or, as you rightly point out "how do we make a language that ...", which is what Nick Maclaren has changed the subject to, essentially. >Fortran "solves" this problem by having a restricted type system which >makes it inappropriate for some problems (e.g. writing operating >systems and device drivers). I think what Fortran solves in this argument is that it guarantees much less than C. E.g.: void copy(char *p, char *q, int n) { while (n--) *p++ = *q++; } C defines the behaviour should p and q overlap. return 0 * f(); C defines that f is called. return f() || g(); C defines that g is not called, if f returns non-zero, and that f is called before g in any case. Fortran, from what I have read, makes none of these guarantees, which leaves more flexibility in the compiler to target the application at a given processor. Nick Maclaren's gripe appears to be virtual functions, of the type used often in C (X11, e.g.), C++ and Java. (Java's a bit of a red-herring, as JIT compiled code might be able to remove the virtual function calls, and a JVM isn't really executing the Java bytecode - it's a prefetching from the datacache problem, which is there with any programming style.) A strong type system certainly helps the compiler - but it isn't all the problem. (Though it might help with inter-procedural optimisations, which would solve some of the examples above - e.g. the compiler discovers for itself that 'f' is __pure.) Mike.