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: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,public From: David Chase Subject: Re: Final kick at the "Merced Guessing Game" Date: 1997/10/09 Message-ID: <343C33D4.5740@world.std.com> X-Deja-AN: 278850726 Sender: news@world.std.com (Mr Usenet Himself) References: <61gr1g$kv@news-rocq.inria.fr> Organization: Natural Bridge LLC Reply-To: chase@world.std.com Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec Robert Harley wrote: > ... Aren't ignorant people like me lucky to have > mind-bogglingly condescending asses like yourself > to bray on about the error of our ways? Hey, someone's got to do it. How exactly do you want this stuff explained? How polite am I supposed to be to someone who says (incorrectly) > I think your problem is that C is too flexible for you. It doesn't > wrongly assume that there is one way of laying out and accessing > arrays that is appropriate for all purposes. This is not condescending? C's major performance fault is that as defined, and especially as used, a compiler does not have a great deal of freedom to move loads and stores around. C programmers may be very careful to avoid "unnecessary" loads and stores, but nowadays, latency is the big problem; performance is reduced if you do your loads "too late", or if a conditional branch depends on a result that you computed "too late". A "too late" load is typically a bigger performance hit than a "not necessary" load. Fortran has many fewer problems with this, because the aliasing rules make life much easier for compilers. The contiguously-allocated multi-dimensional arrays help with this very much, too, because it is easier to infer that A(i,w,x) addresses different storage than A(i+1,y,z) than it is to infer that pa+i*n*p+w*p+x != pa+(i+1)*n*p+y*p+z Modern hardware goes to some trouble to reduce these costs in the local sense, by predicting branches and starting loads early, but this only gets you so much. Parallelization can get you superlinear speedup (as in, when I worked at Sun, a happy customer observed superlinear speedup on one of their dusty decks on a 16-processor machine) on a very good day. Has anyone anywhere ever taken a dusty C deck, dropped it on a multiprocessor, asked the compiler to parallelize it, and obtained even a linear speedup? Sun's Fortran compiler, back in 1994, would take care of loop interchange for better cache use. The dependence analysis finds many "vector" operations, and these are specially code-generated as software pipelines to get the best possible performance. You can get this sometimes for C (it helps if the loop contains no stores to globally-accessible variables) but you'll get it more often for Fortran. Fortran performance is also pulling ahead on the newer processors -- friends (former colleagues) told me that the then-new version of the compilers improved Fortran performance by 160% over the older compilers, but C and C++, not nearly so much (I do not recall the figure). The superoptimizer (converts control flow to very tricky data flow) is looking better and better on these new machines, but the combinatorial costs of searching ever-longer instruction sequences limits usefulness (and the conditional instructions added to many new processors also expands the search space, though they also increase the chances of hitting with a short sequence). A decent combination of cache blocking, register blocking, and software pipelining can get you a 20x speedup over unoptimized code (if I recall, the large-matrix multiply unoptimized ran at something like 1.5 Mflops). C compilers, lacking the restrict keyword, cannot do that (everyone who knows what the restrict keyword is and what it does, raise your hand.) You can do this in C -- I did this in C, apparently ineptly, since a Fortran program beat me -- but it is incredibly tedious work, and the peak performance is not portable (a conservative coding will improve performance by quite a lot on most machines). Cache blocking parameters depend on the cache size, associativity, and line size. Register blocking parameters depend on how many registers you have, and registers used for blocking are stolen from registers used for pipelining. Pipelining depends on the latency of the loads and CPU operations, and on where the operands are expected to come from (dcache? ecache? main memory? contiguous addresses that can be prefetched or fetched in a burst?) And, again, this is slow and tedious work; I normally write something like 100 lines of debugged code (C, Java, x86 assembly language) per day over long periods of time (I can count the lines of code that I have written in the last nine months), but writing this stuff, my rate falls down to something under 10 lines per day. Someone writing similar code in i860 assembly language at Dana/Ardent/Stardent quoted me a figure of one line of code per day, for a general case version of the code (this one someone working on pipelined implementations of vectorized transcendental functions). If you were designing a new programming language ( to get back to the original thread ) it would be a good idea to figure out either how to make it easy to do alias analysis, or what "rules" should come wired into the language that are both easy for programmers to understand and obey, and useful for the compiler to exploit. Fortran 77's rules are well outside the bounds of what I'd call elegant, but they work, and the optimization benefits are substantial. Another possibility is to make it as easy as possible to discover that a program will terminate -- though this is general-case intractable, there's a large class of interesting programs for which this can be determined (for instance, all loops are "for" loops, or all recursion is governed by a strictly decreasing parameter). Or, for instance, there is some datatype that captures the notion "directed acyclic graph", so that you know that any path traversal will terminate. I'd also look into some way to make it more tractable to write programs which use dataflow instead of control flow. C* went quite some distance in that direction, and it was a relatively easy way to get decent performance out of a Connection Machine, but people always seemed to want more, and I think they tended to get it with CMF(ortran) or explicit message-passing. (And, as "boo" writes, some people programmed the vector units in their assembly language. Yuck.) -- David Chase, chase@world.std.com