Created
December 2, 2011 07:01
-
-
Save LeventErkok/1422133 to your computer and use it in GitHub Desktop.
use of uninterpreted functions for code generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.SBV | |
shiftLeft :: SWord32 -> SWord32 -> SWord32 | |
shiftLeft = cgUninterpret "SBV_SHIFTLEFT" cCode hCode | |
where cCode = ["#define SBV_SHIFTLEFT(x, y) ((x) << (y))"] | |
hCode x y = select [x * literal (bit b) | b <- [0.. bitSize x - 1]] (literal 0) y | |
tstShiftLeft :: SWord32 -> SWord32 -> SWord32 -> SWord32 | |
tstShiftLeft x y z = x `shiftLeft` z + y `shiftLeft` z | |
genCCode :: IO () | |
genCCode = compileToC (Just "ddd") "tst" $ do | |
[x, y, z] <- cgInputArr 3 "vs" | |
cgReturn $ tstShiftLeft x y z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment