Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!bacchus!mit-eddie!uw-beaver!uw-june!entropy!dataio!bright From: bright@dataio.Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: Re: Optimizing Floating-Point Expression Evaluation Message-ID: <1290@dataio.Data-IO.COM> Date: Tue, 14-Apr-87 14:47:03 EST Article-I.D.: dataio.1290 Posted: Tue Apr 14 14:47:03 1987 Date-Received: Sun, 19-Apr-87 04:12:54 EST References: <16646@sun.uucp> Reply-To: bright@dataio.UUCP (Walter Bright) Organization: Data I/O - FutureNet Corp., Redmond, WA Lines: 44 Keywords: float point expression In article <16646@sun.uucp> dgh%dgh@Sun.COM (David Hough) writes: > I think this and other aspects of optimization are encapsulated >in the following proposition: optimizing compilers should be designed to >improve carefully-written code by means that can not be readily expressed >in the source language. I would have thought that most experienced C >programmers would agree with that proposition, but some recent postings >suggest otherwise: that a major purpose of optimizing compilers is to clean >up after careless coders and thereby encourage careless coding. I disagree completely, for the following reasons: o Some ways of writing expressions work well on one CPU architecture, and some work well on others. Witness the recent discussions on various ways of coding strcpy(). Having the programmer investigate which of (*p++ = c) or ((*p = c),p++) is more efficient is a waste of time. o You imply that non-optimal code is careless. That could be true, however, it is frequently not true. The goals of readability and maintainability are not the same as optimality. An example would be writing heavily optimized assembler. Few would argue that the resulting code is usually extremely fragile and obtuse. The same thing happens when doing source code tuning. For example, I believe that: for (i = 0; i < MAX; i++) array[i] = j * k - 5 + 10; is more readable and maintainable than: temp = j * k + 5; p = &array[0]; do { *p = temp; ++p; } while (p < &array[MAX]); which is what my compiler does. o Trying to do register allocation by coloring by hand is a real pain! o Source code optimization takes programmer time, which is more expensive than optimizer time. o I have been writing C, assembly code and optimizing compilers for years. Everything I know I try to build into the optimizer and the code generator. This means that all the users of my compiler get the benefit of my knowledge of the 8088.