| 1 | {-# LANGUAGE MagicHash #-} |
|---|
| 2 | {-# LANGUAGE CPP #-} |
|---|
| 3 | import Prelude hiding (foldl) |
|---|
| 4 | import GHC.Prim |
|---|
| 5 | |
|---|
| 6 | -- ~0.4s real DOPEEL+DOUNROLL |
|---|
| 7 | -- ~0.4s real DOPEEL |
|---|
| 8 | -- stackoverflow without |
|---|
| 9 | main = print $ foldl (+) 0 [1..10000000::Int] |
|---|
| 10 | |
|---|
| 11 | #ifdef DOPEEL |
|---|
| 12 | #ifdef DOUNROLL |
|---|
| 13 | -- simulate INLINE foldl PEEL 1 UNROLL1 (+SAT) |
|---|
| 14 | {-# INLINE foldl #-} |
|---|
| 15 | foldl op n l = foldlW n l |
|---|
| 16 | where |
|---|
| 17 | foldlW n (a:b:t) = foldlW ((n`op`a)`op`b) t |
|---|
| 18 | foldlW n (a:t) = foldlW (n`op`a) t |
|---|
| 19 | foldlW n [] = n |
|---|
| 20 | #else |
|---|
| 21 | -- simulate INLINE foldl PEEL 1 (+SAT) |
|---|
| 22 | {-# INLINE foldl #-} |
|---|
| 23 | foldl op n l = foldlW n l |
|---|
| 24 | where |
|---|
| 25 | foldlW n (h:t) = foldlW (n`op`h) t |
|---|
| 26 | foldlW n [] = n |
|---|
| 27 | #endif |
|---|
| 28 | #else |
|---|
| 29 | foldl op n (h:t) = foldl op (h`op`n) t |
|---|
| 30 | foldl op n [] = n |
|---|
| 31 | #endif |
|---|