Skip to content

Instantly share code, notes, and snippets.

@wyager
Created December 16, 2014 06:51
Show Gist options
  • Save wyager/838946a34b72bede63f9 to your computer and use it in GitHub Desktop.
Save wyager/838946a34b72bede63f9 to your computer and use it in GitHub Desktop.
{-# LANGUAGE BangPatterns #-}
fib' :: Int -> Int -> Int -> Int
fib' !0 !a !_ = a
fib' !n !a !b = fib' (n-1) (b) (a+b)
fib :: Int -> Int
fib !n = fib' n 0 1
main = print $ fib (1000*1000*1000)
-- Generated:
{-
[section "data" {
Main.$wfib'_closure:
const Main.$wfib'_info;
},
Main.$wfib'_entry() // [R4, R3, R2]
{ info_tbl: [(c3Jp,
label: Main.$wfib'_info
rep:HeapRep static { Fun {arity: 3 fun_type: ArgSpec 16} })]
stack_info: arg_space: 8 updfr_space: Just 8
}
{offset
c3Jp:
_s3IV::I64 = R4;
_s3IU::I64 = R3;
_s3IT::I64 = R2;
goto c3Jr;
c3Jr:
if (_s3IT::I64 != 0) goto c3Jn; else goto c3Jo;
c3Jn:
_s3IY::I64 = _s3IU::I64 + _s3IV::I64;
_s3IU::I64 = _s3IV::I64;
_s3IV::I64 = _s3IY::I64;
_s3IT::I64 = _s3IT::I64 - 1;
goto c3Jr;
c3Jo:
R1 = _s3IU::I64;
call (P64[Sp])(R1) args: 8, res: 0, upd: 8;
}
}]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment