Skip to content

Commit

Permalink
merged readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeizbicki committed Jun 2, 2014
2 parents 9d8cbc6 + 5019f75 commit 4fdaa3b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test1 :: Double -> Double
test1 d = d*10 + d*20
```

GHC factors out `d`, then folds the constants, producing the core:
With the `fast-math` library, GHC factors out `d`, then folds the constants, producing the core:

```
test1 :: Double -> Double
Expand All @@ -44,7 +44,7 @@ test1 = \ (d :: Double) ->
But if we make the code just a little more complicated:

```
test2 = d1*d2 + (d3 + 5)*d1 + d1*32
test2 d1 d2 = d1*10 + d1*d2 + d1*20
```

Then GHC distributes successfuly, but can't figure out how to fold the constants. It produces the core:
Expand All @@ -59,7 +59,15 @@ test2 = \ (d1 :: Double) (d2 :: Double) ->
}
```

We could fix this problem if the `RULES` pragmas could identify constants instead of variables. This would let us commute/associate the constants to the left of all computations, then GHC's standard constant folding mechanism would work successfully.
If we change the code so that the constants appear next to each other:

```
test3 d1 d2 = d1*d2 + d1*10 + d1*20
```

then GHC successfully combines the constants.

We could fix this problem if the `RULES` pragmas could identify which terms are constants and which are variables. This would let us commute/associate the constants to the left of all computations, then GHC's standard constant folding mechanism would work successfully.

**The best way to check what optimizations are actually supported is to look at the source code.** `RULES` pragmas are surprisingly readable.

Expand Down

0 comments on commit 4fdaa3b

Please sign in to comment.