Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
9ff072f7
Commit
9ff072f7
authored
3 years ago
by
Patrick Baudin
Browse files
Options
Downloads
Patches
Plain Diff
[WP] Cint.ml implements highest_bit_number in using Z.log2
parent
612bfbf5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/wp/Cint.ml
+5
-18
5 additions, 18 deletions
src/plugins/wp/Cint.ml
with
5 additions
and
18 deletions
src/plugins/wp/Cint.ml
+
5
−
18
View file @
9ff072f7
...
@@ -194,22 +194,9 @@ let match_positive_or_null e =
...
@@ -194,22 +194,9 @@ let match_positive_or_null e =
if
not
(
is_positive_or_null
e
)
then
raise
Not_found
;
if
not
(
is_positive_or_null
e
)
then
raise
Not_found
;
e
e
let
highest_bit_number
=
let
match_log2
x
=
let
hsb
p
=
if
p
land
2
=
0
then
0
else
1
(* undefined for 0 and negative values *)
in
let
hsb
p
=
let
n
=
p
lsr
2
in
if
n
=
0
then
hsb
p
else
2
+
hsb
n
Integer
.
of_int
(
try
Z
.
log2
x
with
_
->
raise
Not_found
)
in
let
hsb
p
=
let
n
=
p
lsr
4
in
if
n
=
0
then
hsb
p
else
4
+
hsb
n
in
let
hsb
=
Array
.
init
256
hsb
in
let
hsb
p
=
let
n
=
p
lsr
8
in
if
n
=
0
then
hsb
.
(
p
)
else
8
+
hsb
.
(
n
)
in
let
hsb
p
=
let
n
=
Integer
.
shift_right
p
Integer
.
sixteen
in
Integer
.
of_int
(
if
Integer
.
is_zero
n
then
hsb
(
Integer
.
to_int_exn
p
)
else
16
+
hsb
(
Integer
.
to_int_exn
n
))
in
let
rec
hsb_aux
p
=
let
n
=
Integer
.
shift_right
p
Integer
.
thirtytwo
in
if
Integer
.
is_zero
n
then
hsb
p
else
Integer
.
add
Integer
.
thirtytwo
(
hsb_aux
n
)
in
hsb_aux
let
match_power2
,
match_power2_minus1
=
let
match_power2
,
match_power2_minus1
=
let
is_power2
k
=
(* exists n such that k == 2**n? *)
let
is_power2
k
=
(* exists n such that k == 2**n? *)
...
@@ -217,14 +204,14 @@ let match_power2, match_power2_minus1 =
...
@@ -217,14 +204,14 @@ let match_power2, match_power2_minus1 =
(
Integer
.
equal
k
(
Integer
.
logand
k
(
Integer
.
neg
k
)))
(
Integer
.
equal
k
(
Integer
.
logand
k
(
Integer
.
neg
k
)))
in
let
rec
match_power2
e
=
match
F
.
repr
e
with
in
let
rec
match_power2
e
=
match
F
.
repr
e
with
|
Logic
.
Kint
z
|
Logic
.
Kint
z
when
is_power2
z
->
e_zint
(
highest_bit_number
z
)
when
is_power2
z
->
e_zint
(
match_log2
z
)
|
Logic
.
Fun
(
f
,
[
n
;
k
]
)
|
Logic
.
Fun
(
f
,
[
n
;
k
]
)
when
Fun
.
equal
f
f_lsl
&&
is_positive_or_null
k
->
when
Fun
.
equal
f
f_lsl
&&
is_positive_or_null
k
->
e_add
k
(
match_power2
n
)
e_add
k
(
match_power2
n
)
|
_
->
raise
Not_found
|
_
->
raise
Not_found
in
let
match_power2_minus1
e
=
match
F
.
repr
e
with
in
let
match_power2_minus1
e
=
match
F
.
repr
e
with
|
Logic
.
Kint
z
when
is_power2
(
Integer
.
succ
z
)
->
|
Logic
.
Kint
z
when
is_power2
(
Integer
.
succ
z
)
->
e_zint
(
highest_bit_number
(
Integer
.
succ
z
))
e_zint
(
match_log2
(
Integer
.
succ
z
))
|
_
->
match_power2
(
e_add
e_one
e
)
|
_
->
match_power2
(
e_add
e_one
e
)
in
match_power2
,
match_power2_minus1
in
match_power2
,
match_power2_minus1
...
...
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