Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RefinedC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Iris
RefinedC
Commits
7b471698
Commit
7b471698
authored
4 years ago
by
Paul
Browse files
Options
Downloads
Patches
Plain Diff
update operational semantics for shift operators
parent
dd71b4d9
No related branches found
No related tags found
No related merge requests found
Pipeline
#41950
passed
4 years ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
theories/lang/lang.v
+15
-5
15 additions, 5 deletions
theories/lang/lang.v
theories/typing/int.v
+5
-4
5 additions, 4 deletions
theories/typing/int.v
with
20 additions
and
9 deletions
theories/lang/lang.v
+
15
−
5
View file @
7b471698
...
...
@@ -919,14 +919,24 @@ Inductive eval_bin_op : bin_op → op_type → op_type → state → val → val
(* we need to take `quot` and `rem` here for the correct rounding
behavior, i.e. rounding towards 0 (instead of `div` and `mod`,
which round towards floor)*)
|
DivOp
=>
if
n2
is
0
then
None
else
Some
(
n1
`
quot
`
n2
)
|
ModOp
=>
if
n2
is
0
then
None
else
Some
(
n1
`
rem
`
n2
)
(* TODO: Figure out if these are the operations we want and what sideconditions they have *)
|
DivOp
=>
if
decide
(
n2
=
0
)
then
None
else
Some
(
n1
`
quot
`
n2
)
|
ModOp
=>
if
decide
(
n2
=
0
)
then
None
else
Some
(
n1
`
rem
`
n2
)
|
AndOp
=>
Some
(
Z
.
land
n1
n2
)
|
OrOp
=>
Some
(
Z
.
lor
n1
n2
)
|
XorOp
=>
Some
(
Z
.
lxor
n1
n2
)
|
ShlOp
=>
Some
(
n1
≪
n2
)
|
ShrOp
=>
Some
(
n1
≫
n2
)
(* For shift operators (`ShlOp` and `ShrOp`), without considering integer promotions,
behaviors are defined if:
- lhs is nonnegative, and
- rhs does not exceed the number of bits in lhs. *)
(* In other words, behaviors are undetermined if any of the below happens:
- lhs is negative (for `>>`: implementation-defined)
- rhs is negative
- rhs is greater or equal the number of bits in lhs *)
|
ShlOp
=>
if
decide
(
n1
<
0
∨
n2
<
0
∨
bits_per_int
it
≤
n2
)
then
None
else
Some
(
n1
≪
n2
)
(* NOTE: when lhs is negative, Coq's `≫` is not semantically equivalent to C's `>>`.
Counterexample: Coq `-1000 ≫ 10 = 0`; C `-1000 >> 10 == -1`.
This is because `≫` is implemented by `Z.div`. *)
|
ShrOp
=>
if
decide
(
n1
<
0
∨
n2
<
0
∨
bits_per_int
it
≤
n2
)
then
None
else
Some
(
n1
≫
n2
)
|
_
=>
None
end
=
Some
n
→
val_to_int
v1
it
=
Some
n1
→
...
...
This diff is collapsed.
Click to expand it.
theories/typing/int.v
+
5
−
4
View file @
7b471698
...
...
@@ -344,13 +344,14 @@ Section programs.
iApply
(
wp_binop_det
v
)
.
iSplit
.
-
iIntros
(
σ
v'
)
"_ !%"
.
split
.
+
destruct
op
=>
//.
all
:
inversion
1
;
destruct
n2
;
simplify_eq
/=.
all
:
inversion
1
;
simplify_eq
/=.
4
,
5
,
9
,
10
:
rewrite
decide_False
in
H1
;
last
lia
.
all
:
destruct
it
as
[?
[]];
simplify_eq
/=
=>
//.
all
:
try
by
rewrite
->
it_in_range_mod
in
*
=>
//
;
simplify_eq
.
+
move
=>
->
;
destruct
op
,
n2
=>
//
;
econstructor
=>
//
=>
//.
+
move
=>
->
;
destruct
op
=>
//
;
econstructor
=>
//
=>
//.
4
,
6
,
11
,
13
:
by
inversion
Hsc
;
rewrite
decide_False
;
last
lia
=>
//.
all
:
destruct
it
as
[?
[]];
simplify_eq
/=
=>
//.
all
:
try
by
rewrite
it_in_range_mod
;
simplify_eq
/=.
all
:
by
destruct_and
!.
all
:
try
by
rewrite
it_in_range_mod
.
-
iIntros
"!>"
.
iApply
"HΦ"
;
last
done
.
by
iPureIntro
.
Qed
.
Global
Program
Instance
type_add_int_int_inst
it
v1
n1
v2
n2
:
...
...
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