-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Bitvec.modular
function
#1394
Merged
ivg
merged 24 commits into
BinaryAnalysisPlatform:master
from
bmourad01:adds-bitvec-modular
Jan 7, 2022
+43
−5
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
06ee098
Update LLVM backend to work with version 12
bmourad01 c3f1f26
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 3b8b06c
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 53677fc
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 4695b07
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 c6c89c1
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 a1fb592
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 fa3c6da
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 d5dc07f
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 896a34d
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 3cce21b
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 96874e4
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 c25c801
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 cf3352a
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 9cc0b14
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 5a38191
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 542ba10
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 14e4b38
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 2e5ff40
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 6c98118
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 a57a83a
Merge branch 'BinaryAnalysisPlatform:master' into master
bmourad01 baff49c
Adds the `Bitvec.modulus` function
88cbd5e
Fixes typo in docstring
f10ddec
Adds since version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Adds the
Bitvec.modulus
function
It's a bit clumsy to construct a Bitvec instance when the bit width is not statically known, e.g.: ``` let add n x y = let module M = Bitvec.Make(struct let modulus = Bitvec.modulus n end) in M.(x + y) ``` Instead, we can create a first-class module more concisely: ``` let add n x y = let open (val Bitvec.modular n) in x + y ``` Unrelatedly, this also adds the missing `Bitvec.M16` specialization and its corresponding modulus.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,9 @@ val m1 : modulus | |||||||||||
(** [m8 = modulus 8] = $255$ is the modulus of bitvectors with size [8] *) | ||||||||||||
val m8 : modulus | ||||||||||||
|
||||||||||||
(** [m16 = modulus 16] = $65535$ is the modulus of bitvectors with size [16] *) | ||||||||||||
val m16 : modulus | ||||||||||||
|
||||||||||||
(** [m32 = modulus 32] = $2^32-1$ is the modulus of bitvectors with size [32] *) | ||||||||||||
val m32 : modulus | ||||||||||||
|
||||||||||||
|
@@ -566,14 +569,15 @@ module Make(M : Modulus) : sig | |||||||||||
include S with type 'a m = 'a | ||||||||||||
end | ||||||||||||
|
||||||||||||
module type D = S with type 'a m = 'a | ||||||||||||
|
||||||||||||
(** [M1] specializes [Make(struct let modulus = m1 end)] | ||||||||||||
|
||||||||||||
The specialization relies on a few arithmetic equalities | ||||||||||||
and on an efficient implementation of the modulo operation | ||||||||||||
as the [even x] aka [lsb x] operation. | ||||||||||||
*) | ||||||||||||
module M1 : S with type 'a m = 'a | ||||||||||||
module M1 : D | ||||||||||||
|
||||||||||||
(** [M8] specializes [Make(struct let modulus = m8 end)] | ||||||||||||
|
||||||||||||
|
@@ -582,7 +586,17 @@ module M1 : S with type 'a m = 'a | |||||||||||
calls to the underlying arbitrary precision arithmetic | ||||||||||||
library. | ||||||||||||
*) | ||||||||||||
module M8 : S with type 'a m = 'a | ||||||||||||
module M8 : D | ||||||||||||
|
||||||||||||
|
||||||||||||
(** [M16] specializes [Make(struct let modulus = m16 end)] | ||||||||||||
|
||||||||||||
This specialization relies on a fact, that 8 bitvectors | ||||||||||||
always fit into OCaml integer representation, so it avoids | ||||||||||||
calls to the underlying arbitrary precision arithmetic | ||||||||||||
library. | ||||||||||||
ivg marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
*) | ||||||||||||
module M16 : D | ||||||||||||
|
||||||||||||
|
||||||||||||
(** [M32] specializes [Make(struct let modulus = m32 end)] | ||||||||||||
|
@@ -592,7 +606,7 @@ module M8 : S with type 'a m = 'a | |||||||||||
calls to the underlying arbitrary precision arithmetic | ||||||||||||
library. | ||||||||||||
*) | ||||||||||||
module M32 : S with type 'a m = 'a | ||||||||||||
module M32 : D | ||||||||||||
|
||||||||||||
|
||||||||||||
(** [M64] specializes [Make(struct let modulus = m64 end)] | ||||||||||||
|
@@ -602,4 +616,8 @@ module M32 : S with type 'a m = 'a | |||||||||||
will not overflow the OCaml int representation. | ||||||||||||
|
||||||||||||
*) | ||||||||||||
module M64 : S with type 'a m = 'a | ||||||||||||
module M64 : D | ||||||||||||
|
||||||||||||
(** [modular n] returns a module [M] which implements | ||||||||||||
all operations in [S] modulo the bitwitdh [n]. *) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
val modular : int -> (module D) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.