[Haskell-cafe] #haskell works
Tim Chevalier
catamorphism at gmail.com
Sat Dec 15 09:35:03 EST 2007
On 12/15/07, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> Hello Tim,
>
> Saturday, December 15, 2007, 7:10:26 AM, you wrote:
>
> >> with support of loop unrolling,
>
> > GHC calls this "inlining".
>
> 1. loop unrolling means generating several iterations of loop body,
> so that, say, 100 iterations of *p++=*q++ becomes 25 iterations of
> *p++=*q++; *p++=*q++; *p++=*q++; *p++=*q++;
>
I know what loop unrolling means. In a pure functional language, it
reduces to inlining, because recursion is used instead of loops, and
the inliner can do the job of inlining (a fixed number of) iterations
of a recursive function -- I don't know if it does this now, but it
would be easy to implement. You don't have to believe me -- read
section 4.6 of the inliner paper:
http://research.microsoft.com/~simonpj/Papers/inlining/
> 2. actually, ghc can't inline tail-recursive functions at all
> (although i don't checked this after 6.4)
>
It may be that GHC *doesn't* inline tail-recursive functions, but as I
pointed out above (which I'm just getting directly from the paper), it
would be easy to flip a switch and let it inline a fixed number of
iterations of them.
> there are also many more optimization tricks. i don't think that
> modern compiler with optimization level comparable to gcc can be
> delivered without many man-years of development
>
I think that's an awfully definite statement to make, given that C and
Haskell are very different languages, given how many high-level
optimizations are possible in Haskell that aren't in C, and given how
much higher programmer productivity is in Haskell than C. For example,
as above, loop unrolling turns out to be just a special case of
inlining. That's not true in C. The simplicity of Haskell (or rather,
Core) means it's easy to implement a lot of things with a great deal
of generality, an advantage that gcc doesn't have.
Or, I mean, feel free to insist things are impossible, but try not to
stand in the way of the people who are doing them while you say so.
:-)
Cheers,
Tim
--
Tim Chevalier * catamorphism.org * Often in error, never in doubt
"It's easy to consider women more emotional than men when you don't
consider rage to be an emotion." -- Brenda Fine
More information about the Haskell-Cafe
mailing list