factorial: let's get ahead of jhc! :)

Simon Peyton-Jones simonpj at microsoft.com
Fri Feb 24 11:41:47 EST 2006


| i have found my investiations in this area. that is the C-- code
| generated for fac worker:
| 
| Fac_zdwfac_entry() {
|     c1C0:
|         _s1BD = I32[Sp + 0];
|         if (_s1BD != 1) goto c1C4;
|         R1 = I32[Sp + 4];
|         Sp = Sp + 8;
|         jump (I32[Sp + 0]);
|     c1C4:
|         _s1BI = _s1BD * I32[Sp + 4];
|         _s1BF = _s1BD - 1;
|         I32[Sp + 4] = _s1BI;
|         I32[Sp + 0] = _s1BF;
|         jump c1C0;
| }

Once we do the A/B split of the code generator that I referred to, we
should get something like this from the A part

fac(n,m) {
  if n!=1 goto L
  return(m)
L: jump fac( n-1, n*m ) 
}

The B part will introduce the Sp nonsense.

I think you'll find this a much easier optimisation target.

Simon
-users


More information about the Glasgow-haskell-users mailing list