Skip to content
Snippets Groups Projects
Commit 1e783e15 authored by Ben Gamari's avatar Ben Gamari :turtle:
Browse files

WIP

parent d746f1b3
Branches float
No related tags found
No related merge requests found
Pipeline #46399 failed
...@@ -39,6 +39,7 @@ testCCall ...@@ -39,6 +39,7 @@ testCCall
-> CCallDesc -> CCallDesc
-> Property -> Property
testCCall comp c = testCCall comp c =
counterexample (cStub c) $ counterexample (cCallCmm c) $
ioProperty $ withTempDirectory "." "tmp" $ \tmpDir -> do ioProperty $ withTempDirectory "." "tmp" $ \tmpDir -> do
writeFile (tmpDir </> "test_c.c") (cStub c) writeFile (tmpDir </> "test_c.c") (cStub c)
writeFile (tmpDir </> "test.cmm") (cCallCmm c) writeFile (tmpDir </> "test.cmm") (cCallCmm c)
......
...@@ -17,8 +17,6 @@ module Expr ...@@ -17,8 +17,6 @@ module Expr
, genExpr , genExpr
) where ) where
import Data.Foldable (foldl')
import qualified Data.ByteString as BS
import Numeric.Natural import Numeric.Natural
import Control.Monad import Control.Monad
import Data.Bits as Bits import Data.Bits as Bits
...@@ -29,6 +27,7 @@ import Data.Proxy ...@@ -29,6 +27,7 @@ import Data.Proxy
import Prelude hiding (truncate) import Prelude hiding (truncate)
import {-# SOURCE #-} RefInterpreter import {-# SOURCE #-} RefInterpreter
import {-# SOURCE #-} FExpr
import Width import Width
import Number import Number
...@@ -100,6 +99,10 @@ data Expr (width :: Width) where ...@@ -100,6 +99,10 @@ data Expr (width :: Width) where
EZeroExt :: forall narrow wide. (KnownWidth narrow, wide `WiderThan` narrow) EZeroExt :: forall narrow wide. (KnownWidth narrow, wide `WiderThan` narrow)
=> Expr narrow -> Expr wide => Expr narrow -> Expr wide
-- | Floating-point to signed integer conversion
EFSConv :: FExpr width -> Expr width
EFRel :: FRelationalOp -> FExpr width -> FExpr width -> Expr WordSize
ELoad :: Expr WordSize -> Expr width ELoad :: Expr WordSize -> Expr width
ELit :: Number width -> Expr width ELit :: Number width -> Expr width
...@@ -165,6 +168,8 @@ instance KnownWidth width => Arbitrary (Expr width) where ...@@ -165,6 +168,8 @@ instance KnownWidth width => Arbitrary (Expr width) where
++ [ EZeroExt a ] ++ [ EZeroExt a ]
EZeroExt a -> shrinkUnOp EZeroExt a EZeroExt a -> shrinkUnOp EZeroExt a
++ [ EZeroExt b | EZeroExt b <- pure a, Wider <- pure $ e `compareWidths` b ] ++ [ EZeroExt b | EZeroExt b <- pure a, Wider <- pure $ e `compareWidths` b ]
EFSConv a -> EFSConv <$> shrink a
EFRel op a b -> EFRel op <$> shrink a <*> shrink b
ELoad a -> shrinkUnOp ELoad a ELoad a -> shrinkUnOp ELoad a
ELit a -> map ELit (shrink a) ELit a -> map ELit (shrink a)
where where
...@@ -195,6 +200,7 @@ genExpr' _width = sized gen ...@@ -195,6 +200,7 @@ genExpr' _width = sized gen
oneof $ oneof $
[ litGen [ litGen
, loadGen , loadGen
, EFSConv <$> arbitrary
] ]
++ arithmeticGens ++ arithmeticGens
++ bitwiseGens ++ bitwiseGens
...@@ -257,6 +263,8 @@ genExpr' _width = sized gen ...@@ -257,6 +263,8 @@ genExpr' _width = sized gen
| SameWidth <- Proxy @width `compareWidths` Proxy @WordSize | SameWidth <- Proxy @width `compareWidths` Proxy @WordSize
= [ do op <- arbitrary = [ do op <- arbitrary
binOp (ERel op) binOp (ERel op)
, EFRel @W32 <$> arbitrary <*> arbitrary <*> arbitrary
, EFRel @W64 <$> arbitrary <*> arbitrary <*> arbitrary
] ]
| otherwise = [] | otherwise = []
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
module Expr where module Expr where
import Width (Width) import Test.QuickCheck
import Width (Width, KnownWidth)
data Expr (width :: Width) data Expr (width :: Width)
type role Expr nominal type role Expr nominal
instance (KnownWidth width) => Arbitrary (Expr width)
...@@ -3,6 +3,7 @@ module RefInterpreter ...@@ -3,6 +3,7 @@ module RefInterpreter
, memoryContents , memoryContents
, memoryOracle , memoryOracle
, interpret , interpret
, interpretFloat
) where ) where
import Data.Bits import Data.Bits
...@@ -12,6 +13,7 @@ import Numeric.Natural ...@@ -12,6 +13,7 @@ import Numeric.Natural
import Width import Width
import Expr import Expr
import FExpr
import Number import Number
boolVal :: Bool -> Number WordSize boolVal :: Bool -> Number WordSize
...@@ -64,6 +66,17 @@ interpret (EZeroExt a) = zeroExtNumber (interpret a) ...@@ -64,6 +66,17 @@ interpret (EZeroExt a) = zeroExtNumber (interpret a)
interpret (ELoad off) = memoryOracle $ toUnsigned $ interpret off interpret (ELoad off) = memoryOracle $ toUnsigned $ interpret off
interpret (ELit n) = n interpret (ELit n) = n
interpretFloat
:: forall width. (KnownWidth width)
=> FExpr width -> FloatType width
interpretFloat (FEAdd a b) = interpretFloat a + interpretFloat b
interpretFloat (FESub a b) = interpretFloat a - interpretFloat b
interpretFloat (FEMul a b) = interpretFloat a - interpretFloat b
interpretFloat (FEQuot a b) = interpretFloat a `quot` interpretFloat b
interpretFloat (FENegate a) = negate (interpretFloat a)
interpretFloat (FFromSInt a) = realToFrac $ toSigned $ interpret a
interpretFloat (FConv a) = realToFrac (interpretFloat a)
memorySize :: Natural memorySize :: Natural
memorySize = 1 `shiftL` 22 memorySize = 1 `shiftL` 22
......
...@@ -14,6 +14,7 @@ executable test-primops ...@@ -14,6 +14,7 @@ executable test-primops
other-modules: Width, other-modules: Width,
Number, Number,
Expr, Expr,
FExpr,
Expr.Parse, Expr.Parse,
Interpreter, Interpreter,
ToCmm, ToCmm,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment