Skip to content

Crate reorganization and upgrade to Rust 2018 #36

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

Closed
wants to merge 86 commits into from
Closed
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
a517523
Prepare crate structure for refactor
AaronKutch Jul 9, 2019
fcca12f
Preparation fixes
AaronKutch Jul 9, 2019
a8f8d42
ll.rs is no longer used, and lib.rs already updated
AaronKutch Jul 11, 2019
61c0385
Delete check.rs, since only bitpos.rs is used
AaronKutch Jul 11, 2019
a2c5b7e
Move bitpos.rs
AaronKutch Jul 11, 2019
c97afff
Move bitwidth.rs
AaronKutch Jul 11, 2019
8531f5b
Move digit_seq.rs
AaronKutch Jul 11, 2019
159ae38
Move Digit.rs
AaronKutch Jul 11, 2019
9d91fee
Update digit.rs
AaronKutch Jul 11, 2019
4b6ee00
Move errors.rs
AaronKutch Jul 11, 2019
6e1ea5a
Move int.rs
AaronKutch Jul 11, 2019
5c91e5b
Update int.rs, will add missing functions at a later date
AaronKutch Jul 11, 2019
03b9729
Move uint.rs
AaronKutch Jul 11, 2019
d18a8a8
Update uint.rs
AaronKutch Jul 11, 2019
73c5b8e
Move radix.rs
AaronKutch Jul 11, 2019
28c358b
Update radix.rs
AaronKutch Jul 11, 2019
9e7d034
Move the upper level utils.rs
AaronKutch Jul 11, 2019
a83a45d
Update utils.rs
AaronKutch Jul 11, 2019
2f72c58
Move to_primitive.rs
AaronKutch Jul 11, 2019
f1e13d8
Update to_primitive.rs
AaronKutch Jul 11, 2019
eec268c
Factor out shiftamount.rs
AaronKutch Jul 11, 2019
a02552b
Update shiftamount.rs
AaronKutch Jul 11, 2019
18e0444
Move shift.rs
AaronKutch Jul 11, 2019
7ca2e35
Update shift.rs
AaronKutch Jul 11, 2019
0327128
Move serialization.rs
AaronKutch Jul 11, 2019
cd7b9ab
Update serialization.rs
AaronKutch Jul 11, 2019
03cdd53
Move serde_impl.rs
AaronKutch Jul 11, 2019
fbacc3e
Update serde_impl.rs
AaronKutch Jul 11, 2019
6298fd8
Move rand_impl.rs
AaronKutch Jul 11, 2019
6f69974
Update rand_impl.rs
AaronKutch Jul 11, 2019
9d0c709
Factor out add_sub code
AaronKutch Jul 11, 2019
18edd3b
Update add_sub.rs
AaronKutch Jul 11, 2019
ecac1f5
Move general fuzzing code
AaronKutch Jul 11, 2019
4954bf1
Update fuzz.rs
AaronKutch Jul 11, 2019
c1a0653
Factor out multiplication code
AaronKutch Jul 11, 2019
d834f7f
Update mul.rs
AaronKutch Jul 11, 2019
34788fc
Factor out standard ops implementations
AaronKutch Jul 11, 2019
d9bb9ea
Update traits.rs to not use internal cloning
AaronKutch Jul 11, 2019
a829ba1
Move out division code and delete the old `arithmetic.rs`
AaronKutch Jul 11, 2019
fb1bf70
Update div.rs
AaronKutch Jul 11, 2019
aa799ad
Move bitwise.rs
AaronKutch Jul 11, 2019
1550b7a
Update bitwise.rs
AaronKutch Jul 11, 2019
8e4a2c7
Move relational.rs
AaronKutch Jul 11, 2019
1457fd3
Update cmp.rs
AaronKutch Jul 11, 2019
088aea5
Delete relational.rs
AaronKutch Jul 11, 2019
1d6a26a
Move casting operations
AaronKutch Jul 12, 2019
5da82ee
Update casting.rs
AaronKutch Jul 12, 2019
bee6162
Moving constructing operations
AaronKutch Jul 12, 2019
dd81c0c
These will go in apint.rs
AaronKutch Jul 12, 2019
deb75d1
Update constructors.rs and put some of it in apint.rs
AaronKutch Jul 12, 2019
0cce16f
Move the rest of casting.rs
AaronKutch Jul 12, 2019
9f8e02e
Move the rest of constructors.rs
AaronKutch Jul 12, 2019
1d8f203
Move the rest of mod.rs
AaronKutch Jul 12, 2019
9dbec21
Move the Width trait
AaronKutch Jul 12, 2019
c77e0b3
Move some more methods into apint.rs
AaronKutch Jul 12, 2019
f0bef79
Update apint.rs
AaronKutch Jul 12, 2019
29fe69e
Move traits.rs
AaronKutch Jul 12, 2019
7d6bb7e
Move storage.rs
AaronKutch Jul 12, 2019
f2420a8
Move into access.rs
AaronKutch Jul 12, 2019
286b583
Update access.rs and move some methods to utils.rs
AaronKutch Jul 12, 2019
dfc4eae
Update utils.rs
AaronKutch Jul 12, 2019
00cee3a
fix some refactoring artifacts
AaronKutch Jul 12, 2019
cc84a7b
Delete old_src
AaronKutch Jul 12, 2019
8740896
Finish Refactoring and Upgrading to Rust Edition 2018
AaronKutch Jul 12, 2019
eb8abca
fix rebase artifacts
AaronKutch Jul 12, 2019
ea3d9ff
Update dependencies
AaronKutch Jul 12, 2019
9d60b57
Update README.md
AaronKutch Jul 14, 2019
d0a4b97
Fix various problems with the README.md
AaronKutch Jul 14, 2019
9ec29ab
Update src/construction/constructors.rs
AaronKutch Jul 14, 2019
9b706e6
convert unneccessary `pub(crate)` to `pub`
AaronKutch Jul 14, 2019
04dba4b
add Safety section header
AaronKutch Jul 14, 2019
dd8cb0f
Update src/data/digit.rs
AaronKutch Jul 15, 2019
0ae8a31
Apply suggestions from code review
AaronKutch Jul 15, 2019
754af78
This needs to be undone, or else it leaks a private type
AaronKutch Jul 15, 2019
20f3b5d
Move the Hash impl
AaronKutch Jul 15, 2019
b7b6d00
More fixes
AaronKutch Jul 15, 2019
ef47a28
Apply suggestions from code review
AaronKutch Jul 15, 2019
cac4b48
Unnecessary
AaronKutch Jul 15, 2019
379d64b
Apply suggestions from code review
AaronKutch Jul 15, 2019
b0092f0
Update div.rs
AaronKutch Jul 15, 2019
8058e22
Update Cargo.toml
AaronKutch Jul 15, 2019
3bbab35
Update apint.rs
AaronKutch Jul 15, 2019
2a9532d
Apply suggestions from code review
AaronKutch Jul 15, 2019
ec1513c
break up multiplication function and improve a few things
AaronKutch Aug 20, 2019
f029095
make drop_digits private
AaronKutch Aug 20, 2019
d7ba1a4
Break up the divider functions
AaronKutch Aug 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.2.0" # Don't forget to update html_root_url in lib.rs.
authors = ["Robin Freyler <robbepop@web.de>", "Aaron Kutch <aaronkutch@att.net>"]
license = "MIT/Apache-2.0"
readme = "README.md"
edition = "2018"

keywords = ["int", "integer", "precision", "arbitrary"]

Expand All @@ -13,15 +14,17 @@ description = """Arbitrary precision integers library."""
categories = ["data-structures"]

[dependencies]
smallvec = { version = "0.6.5" }
specialized-div-rem = { version = "0.0.2", optional = true }
rand = { version = "0.5.5", optional = true }
serde = { version = "1.0.75", optional = true }
serde_derive = { version = "1.0.75", optional = true }
smallvec = { version = "0.6.10" }
specialized-div-rem = { version = "0.0.5", optional = true }
rand = { version = "0.7.0", features = ["small_rng"], optional = true }

serde = { version = "1.0.94", optional = true }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally it is best to avoid concrete version names unless you need a feature that is designated to a specific minor version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed this

serde_derive = { version = "1.0.94", optional = true }

[dev-dependencies]
serde_test = "1.0.75"
itertools = "0.7.8"
rand_xoshiro = { version = "0.3.0" }
serde_test = "1.0.94"
itertools = "0.8.0"

[features]
default = ["rand_support", "serde_support", "specialized-div-rem"]
Expand Down
69 changes: 47 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
ApInt - Arbitrary Precision Integer
===================================
# ApInt - Arbitrary Precision Integer

| Linux | Windows | Codecov | Coveralls | Docs | Crates.io |
|:-------------------:|:-------------------:|:--------------------:|:--------------------:|:----------------:|:--------------------:|
| [![travisCI][1]][2] | [![appveyor][3]][4] | [![codecov][15]][16] | [![coveralls][5]][6] | [![docs][11]][12] | [![crates][13]][14] |

**Development in progress:** *The implementation has not been finished and may not work.*

**A**rbitrary **p**recision **Int**egers (**ApInt**) represent integers that have an arbitrary but
**A**rbitrary **p**recision **Int**egers (**ApInt**) represent integers that have an arbitrary but
fixed runtime bit-width and offers two's complement modulo arithmetic equal to machine integers.

The integer types offered by this library are:
Expand All @@ -24,19 +23,27 @@ The API is based on the LLVM [`APInt`](http://llvm.org/doxygen/classllvm_1_1APIn
- SMT solvers may use this as an underlying model for the theory of bitvectors.
- Operations and backend for cryptographic keys.
- Also usable as a simple bitset with runtime length information.
- Use it like any other big integer library, with the difference that the user manages the bit
widths of all instances, and numbers can be purposely overflowed like machine integers.

## Internals

The design focus is at efficiency and robustness.
`ApInt` instances are small-value-optimized. This means that only `ApInt` instances with a bit-width larger than 64 bits allocate dynamic memory.
An `ApInt` constists of a sequence of `Digit`s.
A `Digit` is currently `u64`, but in the future a feature could be added to allow changing this.
The `Digit` struct is never going to be made public for this reason and other internal reasons,
although the term is used often in documentation to convey what happens inside the public interface.
`ApInt` instances are small-value-optimized. This means that only `ApInt` instances with a bit-width
larger than the number of bits in a `Digit` allocate dynamic memory.

An `ApInt` constists of a sequence of 64-bit `Digit`s.
Computations are done within their 128-bit `DoubleDigit` form to prevent bit-loss on over- or underflows.
This implies a dependency on 128-bit integers which are currently unstable in Rust.
By default, very little `unsafe` is used outside of managing internal `union`s. The robustness of
`ApInt` operations is backed by extensive fuzz testing (including unit, regression, random input,
and edge case testing in multiple flag modes).

## Differences & Parallels

The below table lists public and internal differences between `ApInt` and `num::BigInt`.
The below table lists public and internal differences between `ApInt` and `num::BigInt`. Pointer
widths of 64 bits are assumed.

| Topic | `num::BigInt` | `ApInt` |
|:------------------------:|:------------------------------------------|:----------------------------------------|
Expand All @@ -45,16 +52,17 @@ The below table lists public and internal differences between `ApInt` and `num::
| Small Value Optimization | No | Yes: Up to 64-bits. |
| Building Blocks | 32-bit `BigDigit` aka `u32` | 64-bit `Digit` |
| Compute Unit | 64-bit `DoubleBigDigit` aka `u64` | 128-bit `DoubleDigit` |
| Signed | Yes: `num::BigUint` is for unsigned. | No: Operations know signedness instead. |
| `mem::size_of<..>` | About 24 bytes + some signedness info. | Exactly 128 bits (16 bytes). |
| Signed | Yes: `num::BigUint` is for unsigned | No: Operations know signedness instead |
| `mem::size_of<..>` | About 24 bytes + some signedness info | Exactly 128 bits |
| Width interoperability | No restriction to operate between `BigInt` instances with different bit-widths. | Only `ApInt` instances with the same bit-width can interoperate. |
| Memory footprint | Determined by current value stored. | Determined by bit-width. |
| Can grow and shrink? | Yes | No, see above. |
| Unstable features? | None | Stable as of Rust 1.26. |
| Memory footprint | Determined by current value stored | Determined by bit-width |
| Auto-resize | Yes | No |
| Unstable features? | None | Stable as of Rust 1.36 |

## Current State

Currently only a few parts of the implementation are done - especially the implementation of `ApInt`'s with bit-widths greater than 64 bits is incomplete.
Currently only a few parts of the implementation are done - especially the implementation of
`ApInt`'s with bit-widths greater than 64 bits is incomplete.

State of the API modules implemented so far:

Expand All @@ -75,25 +83,30 @@ State of the API modules implemented so far:
## Planned Features

- Full and efficient `ApInt` implementation and decent test coverage.
- Mid-level `ApsInt` wrapper around `ApInt` that stores a run-time sign information.
This is different from `Int` and `UInt` since those types store
their sign immutable in their type. This is the same as LLVM's `APSInt` data type.
- Mid-level `ApsInt` wrapper around `ApInt` that stores a run-time sign information. This is the
same as LLVM's `APSInt` data type. These allow for constant time complexity changes in sign and
more efficient operations on negative numbers in some cases.
- Low level unsafe functions that have no bounds checking, allow for `ApInt`s of different bit
widths to be operated on, and have access to reusing internal allocations for calculations that
require allocated temporaries.
- More efficient operations.

## License

Licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0,
([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)

at your option.

### Dual licence: [![badge][7]](LICENSE-MIT) [![badge][8]](LICENSE-APACHE)

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the
work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.

[1]: https://travis-ci.org/Robbepop/apint.svg?branch=master
Expand Down Expand Up @@ -123,6 +136,16 @@ additional terms or conditions.

## Release Notes

### Version 0.3.0 TODO

- Rename many functions from `_checked_` to `_wrapping_` and clarified documentation.
- Added multiplication and division functions.
- Add circular shift functions like `rotate_left_assign`.
- Removed `Bit`, changed `ApInt::from_bit` to `ApInt::from_bool`.
- reorganized internals with updated dependencies and better performance all around.
- Corrected README.md for markdown lints.
- Fixed all Clippy warnings

### Version 0.2.0 - 2018-05-16

- Add `Binary`, `LowerHex` and `UpperHex` impls to `Int`, `UInt` and `ApInt`.
Expand All @@ -134,7 +157,9 @@ additional terms or conditions.
- Add `into_bitnot` to `ApInt`, `Int` and `UInt`.
- Add division-by-zero error and managing around it for respective operations.
- Add a crate prelude module for simple usage of commonly used types.
- Fixed bug in `ApInt::sign_extend` and `Int::extend` (issue [#15](https://github.com/Robbepop/apint/issues/15)). Thanks [AaronKutch](https://github.com/AaronKutch) for reporting!
- Fixed bug in `ApInt::sign_extend` and `Int::extend`
(issue [#15](https://github.com/Robbepop/apint/issues/15)).
Thanks [AaronKutch](https://github.com/AaronKutch) for reporting!
- Fixed markdown headers of many public impl blocks.
- Fixed several documentation comments of public APIs, like `ApInt::from_{i128, u128}`.
- Fixed several minor bugs due to forwarding to wrong implementation methods.
Loading