Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!brutus.cs.uiuc.edu!lll-winken!muslix!jac From: jac@muslix.llnl.gov (James Crotinger) Newsgroups: comp.lang.c++ Subject: Re: inline and vectorization Keywords: C++, vector syntax, vectorization. Message-ID: <41451@lll-winken.LLNL.GOV> Date: 13 Dec 89 17:43:53 GMT References: <40827@lll-winken.LLNL.GOV> <2239@dataio.Data-IO.COM> <1061@amc-gw.amc.com> Sender: usenet@lll-winken.LLNL.GOV Reply-To: jac@muslix.UUCP (James Crotinger) Organization: Lawrence Livermore National Laboratory/UC Davis Lines: 53 In article <1061@amc-gw.amc.com> jimm@amc-gw.amc.com (Jim McElroy) writes: >The kind of optimizations that you are hoping for would be very >difficult for a language that tries to be general purpose. ... >The compiler would have to know that the operations (*, +, etc.) >had no side effects that the programmer was counting on. > But if the operations are inlined, then the compiler can figure this out! >There is, however, a way. Suppose we have a set of vector and ...describes method where, if I understand it, the operators would build up a syntax tree, and when a value was finally required (e.g. operator=()) the syntax tree would be optimized and then evaluated. I've read this suggestion before, but in a different context as a method to optimize complex vector expressions. (e.g. d = a + b + c) This is related since currently d = a + b + c would compile into something like (I believe -- I really should check to make sure). tmp = a + b; d = tmp + c which, if inlined, would become (fortran notation) do i = 1, n tmp(i) = a(i) + b(i) end do do i = 1, n d(i) = tmp(i) + c(i) end do Now, if these loops were jammed and if the compiler can figure out that tmp is unused in the rest of the program, it can optimize this to do i = 1, n d(i) = a(i) + b(i) + c(i) end do which is exactly what we want. So, if we can inline loops, and if the optimizers can be made smart enough to do optimizations like the above, then I suspect that the above solution is better than the one which would build up a parse tree out of the operators and then have the class itself try to optimize the parse tree when operator=() is called. >How far can this idea be pushed? Loop unrolling? I think our C compiler already does this. Certainly our Fortran compilers do. >Jim McElroy