Skip to content

Instantly share code, notes, and snippets.

@LeventErkok
Created December 2, 2011 07:01
Show Gist options
  • Save LeventErkok/1422133 to your computer and use it in GitHub Desktop.
Save LeventErkok/1422133 to your computer and use it in GitHub Desktop.
use of uninterpreted functions for code generation
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