Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Lustrec - public version
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
LustreC
Lustrec - public version
Commits
73ccaf2f
Commit
73ccaf2f
authored
6 years ago
by
Pierre Loic Garoche
Browse files
Options
Downloads
Patches
Plain Diff
Merge branch 'cocospec' of
https://cavale.enseeiht.fr/git/lustrec
into cocospec
parent
2d27eedd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
doc/integer_division.org
+4
-10
4 additions, 10 deletions
doc/integer_division.org
src/backends/C/c_backend_common.ml
+8
-6
8 additions, 6 deletions
src/backends/C/c_backend_common.ml
src/backends/Horn/horn_backend_printers.ml
+13
-9
13 additions, 9 deletions
src/backends/Horn/horn_backend_printers.ml
with
25 additions
and
25 deletions
doc/integer_division.org
+
4
−
10
View file @
73ccaf2f
...
...
@@ -26,20 +26,14 @@ Some properties:
* From C to Euclidian
a mod_M b = (a mod_C b) + (a < 0 ? abs(b) : 0)
a mod_M b = (a mod_C b) + (a
mod_C b
< 0 ? abs(b) : 0)
a div_M b = (a - (a mod_M b)) div_C b
= (a - ((a mod_C b) + (a < 0 ? abs(b) : 0))) div_C b
= (a - ((a mod_C b) + (a
mod_C b
< 0 ? abs(b) : 0))) div_C b
* From Euclidian to C
a mod_C b = (a >= 0 ? a mod_M b : - ((-a) mod_M b))
(using math def to ensure positiveness of remainder))
= (a mod_M b) - (a < 0 ? abs(b) : 0)
(using the def of mod_M above)
a mod_C b = a mod_M b - ((a mod_M b <> 0 && a <= 0) ? abs(b) : 0)
a div_C b = (a - (a mod_C b)) div_M b
= (a - ((a mod_M b) - (a < 0 ? abs(b) : 0))) div_M b
Let's chosse the second, simpler, def of mod_C
= (a mod_M b <> 0 && a <= 0)?((a - a mod_M b + abs(b)) div_M b) :((a - a mod_M b) div_M b)
This diff is collapsed.
Click to expand it.
src/backends/C/c_backend_common.ml
+
8
−
6
View file @
73ccaf2f
...
...
@@ -110,19 +110,21 @@ let pp_machine_step_name fmt id = fprintf fmt "%s_step" id
let
pp_mod
pp_val
v1
v2
fmt
=
if
!
Options
.
integer_div_euclidean
then
(* (a mod_C b) + (a < 0 ? abs(b) : 0) *)
Format
.
fprintf
fmt
"((%a %% %a) + (%a < 0?(abs(%a)):0))"
(* (a mod_C b) + (a
mod_C b
< 0 ? abs(b) : 0) *)
Format
.
fprintf
fmt
"((%a %% %a) +
(
(%a
%% %a)
< 0?(abs(%a)):0))"
pp_val
v1
pp_val
v2
pp_val
v1
pp_val
v2
pp_val
v2
else
(* Regular behavior: printing a % *)
Format
.
fprintf
fmt
"(%a %% %a)"
pp_val
v1
pp_val
v2
let
pp_div
pp_val
v1
v2
fmt
=
if
!
Options
.
integer_div_euclidean
then
(* (a - ((a mod_C b) + (a < 0 ? abs(b) : 0))) div_C b *)
Format
.
fprintf
fmt
"(%a - ((%a %% %a) + (%a < 0 ? abs(%a) : 0))) / %a"
pp_val
v1
pp_val
v1
pp_val
v2
pp_val
v1
pp_val
v2
pp_val
v2
(* (a - ((a mod_C b) + (a mod_C b < 0 ? abs(b) : 0))) div_C b *)
Format
.
fprintf
fmt
"(%a - %t) / %a"
pp_val
v1
(
pp_mod
pp_val
v1
v2
)
pp_val
v2
else
(* Regular behavior: printing a / *)
Format
.
fprintf
fmt
"(%a / %a)"
pp_val
v1
pp_val
v2
...
...
This diff is collapsed.
Click to expand it.
src/backends/Horn/horn_backend_printers.ml
+
13
−
9
View file @
73ccaf2f
...
...
@@ -67,22 +67,26 @@ let rec pp_default_val fmt t =
let
pp_mod
pp_val
v1
v2
fmt
=
if
Types
.
is_int_type
v1
.
value_type
&&
not
!
Options
.
integer_div_euclidean
then
(* C semantics: converting it
to
Euclid
i
an operators
(a mod_M b) - (a < 0 ? abs(b) : 0)
(* C semantics: converting it
from
Euclid
e
an operators
(a mod_M b) - (
(a mod_M b > 0 &&
a < 0
)
? abs(b) : 0)
*)
Format
.
fprintf
fmt
"(- (mod %a %a) (ite (< %a 0) (abs %a) 0))"
pp_val
v1
pp_val
v2
pp_val
v1
pp_val
v2
Format
.
fprintf
fmt
"(- (mod %a %a) (ite (and (> (mod %a %a) 0) (< %a 0)) (abs %a) 0))"
pp_val
v1
pp_val
v2
pp_val
v1
pp_val
v2
pp_val
v1
pp_val
v2
else
Format
.
fprintf
fmt
"(mod %a %a)"
pp_val
v1
pp_val
v2
let
pp_div
pp_val
v1
v2
fmt
=
if
Types
.
is_int_type
v1
.
value_type
&&
not
!
Options
.
integer_div_euclidean
then
(* C semantics: converting it
to
Euclid
i
an operators
(a -
(
(a mod_
M
b)
- (a < 0 ? abs(b) : 0))
) div_M b
(* C semantics: converting it
from
Euclid
e
an operators
(a - (a mod_
C
b)) div_M b
*)
Format
.
fprintf
fmt
"(div (- %a (- (mod %a %a) (ite (< %a 0) (abs %a) 0))) %a)"
pp_val
v1
pp_val
v1
pp_val
v2
pp_val
v1
pp_val
v2
pp_val
v2
Format
.
fprintf
fmt
"(div (- %a %t) %a)"
pp_val
v1
(
pp_mod
pp_val
v1
v2
)
pp_val
v2
else
Format
.
fprintf
fmt
"(div %a %a)"
pp_val
v1
pp_val
v2
...
...
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