Professional Documents
Culture Documents
Neil Mitchell,
Colin Runciman
www.cs.york.ac.uk/~ndm/supero
The Goal
In Haskell
int main() {
int i = 0, c, last_space = 1;
while ((c = getchar()) != EOF) {
int this_space = isspace(c);
if (last_space && !this_space) i++;
last_space = this_space;
} About 3 times faster
printf("%i\n", i); than Haskell
return 0; (gcc vs ghc)
}
Why is Haskell slower?
When should
What should
we terminate?
we inline?
generalise residual
How should
we generalise?
named*
An example (specialisation)
sum x = case x of
[] → 0
x:xs → x + sum xs
sum (range 0 n)
case range 0 n of {[] → 0; x:xs → x + sum xs}
case (case 0 > n of {True → []; False → …}) of …
case 0 > n of {True → 0;False → i + sum (range (0+1) n)}
sum (range (0+1) n)
Now we terminate and generalise!
sum (range i n)
case range i n of {[] → 0; x:xs → x + sum xs}
…
The Residual Program
Haskell
Yhc
Core
Supero
Core
Yhc.Core
Haskell
GHC
Executable
GHC’s Contributions
GHC is great ☺
– Primitives (Integer etc)
– Strictness analysis and unboxing
– STG code generation
– Machine code generation
space/not
C Haskell
not/space
25
20
15 C (gcc)
sec.
Supero+GHC
10
GHC
5
0
charcount linecount wordcount
%
100
120
140
160
0
20
40
60
80
bernouilli
digits-of-e1
digits-of-e2
exp3_8
integrate
primes
queens
rfib
tak
wheel-sieve1
wheel-sieve2
x2n1
Runtime as % of GHC time
Conclusions