Skip to content

Commit

Permalink
Correctly handle Indexs fromInteger# and maxBound# for large li…
Browse files Browse the repository at this point in the history
…terals

VHDL would be incorrect for values larger than 2^MACHINE_WIDTH
  • Loading branch information
christiaanb committed Jul 19, 2016
1 parent b7ab5c4 commit 6b365dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clash-vhdl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog for the [`clash-vhdl`](http://hackage.haskell.org/package/clash-vhdl) package

## 0.6.15
## 0.6.15 *July 19th 2016*
* Fixes bugs:
* Incorrect primitive for `Index`s `*#`
* Incorrect handling of `Index`s `fromInteger#` and `maxBound#` primitives for values larger than 2^MACHINE_WIDTH

## 0.6.14 *July 15th 2016*
* New features:
Expand Down
15 changes: 15 additions & 0 deletions clash-vhdl/src/CLaSH/Backend/VHDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,21 @@ expr_ _ (BlackBoxE pNm _ bbCtx _)
, [Literal _ (NumLit n), Literal _ i] <- extractLiterals bbCtx
= exprLit (Just (BitVector (fromInteger n),fromInteger n)) i

expr_ _ (BlackBoxE pNm _ bbCtx _)
| pNm == "CLaSH.Sized.Internal.Index.fromInteger#"
, [Literal _ (NumLit n), Literal _ i] <- extractLiterals bbCtx
, Just k <- clogBase 2 n
, let k' = max 1 k
= exprLit (Just (Unsigned k',k')) i

expr_ _ (BlackBoxE pNm _ bbCtx _)
| pNm == "CLaSH.Sized.Internal.Index.maxBound#"
, [Literal _ (NumLit n)] <- extractLiterals bbCtx
, n > 0
, Just k <- clogBase 2 n
, let k' = max 1 k
= exprLit (Just (Unsigned k',k')) (NumLit (n-1))

expr_ _ (BlackBoxE pNm _ bbCtx _)
| pNm == "GHC.Types.I#"
, [Literal _ (NumLit n)] <- extractLiterals bbCtx
Expand Down

0 comments on commit 6b365dc

Please sign in to comment.