Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!amdcad!crackle!tim From: tim@crackle.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: C optimizer Message-ID: <24433@amdcad.AMD.COM> Date: 13 Feb 89 20:10:02 GMT References: <515@larry.UUCP> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc. Sunnyvale CA Lines: 28 Summary: Expires: Sender: Followup-To: In article <515@larry.UUCP> jwp@larry.UUCP (Jeffrey W Percival) writes: | | x = (1 + cos(r)) / (cos(r) * sin(r)); | y = (cos(r) - sin(r)) / (1 + sin(r)); | | I made this up, but the point is the re-use of the sin() and cos() | calls. Now, can I expect the compiler to form only one call to sin and | cos? Specifically, I am using ULTRIX 2.1 on a VS2000, but my real | question is, would *most* compilers optimize this as I'd hope, or | *some* compilers, or hardly any? I think that very few compilers currently perform this optimization. The problem is that (pre-ANSI) compilers usually have no knowledge about standard library routines -- they look just like other function calls. Therefore, the compiler does not know that sin() or cos() are "true functions", in that they will return the same values for the same inputs, and have no side-effects. ANSI-conforming C compilers will be able to perform this optimization, since the standard library routine names are reserved, and the compiler can have specific knowledge about them. I know of at least one C compiler that is tracking the proposed ANSI standard that will perform this optimization. -- Tim Olson Advanced Micro Devices (tim@crackle.amd.com)