Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
test-primops
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
test-primops
Commits
d6699e6a
Commit
d6699e6a
authored
3 years ago
by
Ben Gamari
Browse files
Options
Downloads
Patches
Plain Diff
Add testing of MO_MulMayOflo
parent
5e35523d
No related branches found
No related tags found
1 merge request
!5
Test MO_MulMayOflo
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Main.hs
+2
-0
2 additions, 0 deletions
src/Main.hs
src/MulMayOverflow.hs
+62
-0
62 additions, 0 deletions
src/MulMayOverflow.hs
test-primops.cabal
+1
-0
1 addition, 0 deletions
test-primops.cabal
with
65 additions
and
0 deletions
src/Main.hs
+
2
−
0
View file @
d6699e6a
...
...
@@ -21,6 +21,7 @@ import CallishOp
import
CCall
import
RunGhc
import
Expr.Parse
import
MulMayOverflow
basicCompiler
::
FilePath
->
Compiler
basicCompiler
ghcPath
=
...
...
@@ -72,6 +73,7 @@ compilerTests name comp = testGroup name
$
quotRemProp
@
w
(
ghcDynInterpreter'
comp
)
|
SomeWidth
(
_
::
Proxy
w
)
<-
allWidths
]
,
prop_mul_may_oflo_correct
comp
]
newtype
RunItPath
=
RunItPath
FilePath
...
...
This diff is collapsed.
Click to expand it.
src/MulMayOverflow.hs
0 → 100644
+
62
−
0
View file @
d6699e6a
-- | Test the @MulMayOflo@ machop.
module
MulMayOverflow
(
prop_mul_may_oflo_correct
)
where
import
Data.Proxy
import
Test.QuickCheck
import
Test.Tasty
import
Test.Tasty.QuickCheck
import
Width
import
RunGhc
import
ToCmm
import
Number
import
Expr
-- | @MO_MulMayOflo@ tests whether a signed product may overflow the target
-- width. It:
--
-- - Must return nonzero if the result overflows
-- - May return zero otherwise
--
-- We cannot test this like other MachOps since its result is not well-defined.
prop_mul_may_oflo_correct
::
Compiler
->
TestTree
prop_mul_may_oflo_correct
comp
=
testGroup
"MulMayOflo"
[
testProperty
(
show
(
knownWidth
@
w
))
(
prop
@
w
comp
Proxy
)
|
SomeWidth
(
_
::
Proxy
w
)
<-
allWidths
]
prop
::
forall
w
.
(
KnownWidth
w
)
=>
Compiler
->
Proxy
w
->
Expr
w
->
Expr
w
->
Property
prop
comp
Proxy
x
y
=
ioProperty
$
do
r
<-
evalMulMayOflo
comp
x
y
let
does_oflo
=
r
/=
0
return
$
counterexample
(
show
prod
)
(
does_overflow
==>
does_oflo
)
where
(
min_bound
,
max_bound
)
=
signedBounds
(
knownWidth
@
w
)
prod
=
toSigned
(
interpret
x
)
*
toSigned
(
interpret
y
)
does_overflow
=
prod
<
min_bound
||
prod
>
max_bound
evalMulMayOflo
::
forall
w
.
(
KnownWidth
w
)
=>
Compiler
->
Expr
w
->
Expr
w
->
IO
(
Number
WordSize
)
evalMulMayOflo
comp
x
y
=
fromUnsigned
<$>
evalCmm
comp
cmm
where
cmm
=
unlines
[
"test ( "
<>
cmmWordType
<>
" buffer ) {"
,
" "
<>
cmmType
w
<>
" ret, x, y;"
,
" x = "
++
exprToCmm
x
++
";"
,
" y = "
++
exprToCmm
y
++
";"
,
" ret = %mulmayoflo(x,y);"
,
" return ("
++
widenOp
++
"(ret));"
,
"}"
]
widenOp
=
"%zx"
++
show
(
widthBits
wordSize
)
w
=
knownWidth
@
w
This diff is collapsed.
Click to expand it.
test-primops.cabal
+
1
−
0
View file @
d6699e6a
...
...
@@ -19,6 +19,7 @@ executable test-primops
ToCmm,
CallishOp,
CCall,
MulMayOverflow,
RunGhc
build-depends: base,
QuickCheck,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment