Matt Brubeck
531c2a754f
Fix documentation formatting with commonmark enabled
...
This makes formatting correct with the new pulldown-cmark Markdown
parser (rust-lang/rust#44229 ).
2017-10-17 10:16:01 -07:00
Josh Stone
2f8f952d1d
clean up unused macros
2017-09-21 17:36:21 -07:00
Josh Stone
2a9750ada4
bigint: remove an unused mut
2017-09-21 17:28:37 -07:00
Josh Stone
7679cb86fb
Remove `#[must_use]` on `__add2`
...
It doesn't actually work on functions yet, and nightly now warns that it
is experimental, behind `#[feature(fn_must_use)]`.
2017-09-21 17:26:20 -07:00
bors[bot]
4896746fec
Merge #328
...
328: Optimizing BigUint and Bigint multiplication with the Toom-3 algorithm r=cuviper a=kompass
Hi !
I finally implemented the Toom-3 algorithm ! I first tried to minimize the memory allocations by allocating the `Vec<BigDigit>` myself, as was done for Toom-2, but Toom-3 needs more complex calculations, with negative numbers. So I gave up this method, to use `BigInt` directly, and it's already faster ! I also chose a better threshold for the Toom-2 algorithm.
Before any modification :
```
running 4 tests
test multiply_0 ... bench: 257 ns/iter (+/- 25)
test multiply_1 ... bench: 30,240 ns/iter (+/- 1,651)
test multiply_2 ... bench: 2,752,360 ns/iter (+/- 52,102)
test multiply_3 ... bench: 11,618,575 ns/iter (+/- 266,286)
```
With a better Toom-2 threshold (16 instead of 4) :
```
running 4 tests
test multiply_0 ... bench: 130 ns/iter (+/- 8)
test multiply_1 ... bench: 19,772 ns/iter (+/- 1,083)
test multiply_2 ... bench: 1,340,644 ns/iter (+/- 17,987)
test multiply_3 ... bench: 7,302,854 ns/iter (+/- 82,060)
```
With the Toom-3 algorithm (with a threshold of 300):
```
running 4 tests
test multiply_0 ... bench: 123 ns/iter (+/- 3)
test multiply_1 ... bench: 19,689 ns/iter (+/- 837)
test multiply_2 ... bench: 1,189,589 ns/iter (+/- 29,101)
test multiply_3 ... bench: 3,014,225 ns/iter (+/- 61,222)
```
I think this could be optimized, but it's a first step !
2017-09-20 20:53:40 +00:00
Josh Stone
1ddbee7f37
bigint mac3: tweak thresholds between algorithms
...
It's not too rigorous, but thresholds 32 and 256 give me better results.
Before:
test multiply_0 ... bench: 87 ns/iter (+/- 0)
test multiply_1 ... bench: 11,926 ns/iter (+/- 19)
test multiply_2 ... bench: 772,178 ns/iter (+/- 3,068)
test multiply_3 ... bench: 2,034,237 ns/iter (+/- 9,618)
After:
test multiply_0 ... bench: 87 ns/iter (+/- 0)
test multiply_1 ... bench: 11,927 ns/iter (+/- 64)
test multiply_2 ... bench: 672,440 ns/iter (+/- 3,570)
test multiply_3 ... bench: 1,577,065 ns/iter (+/- 11,137)
2017-09-20 13:19:00 -07:00
Josh Stone
28d84ca3ac
Toom-3: operate more on values where possible
2017-09-20 13:17:06 -07:00
Josh Stone
2c2e46c8df
Add comments about multiplication strategy
2017-09-20 13:15:44 -07:00
Josh Stone
05dc87c041
Improve mac_digit bounds checking
...
By starting with `split_at_mut`, the hot multiplication loop runs with
no bounds checking at all! The remaining carry loop has a slightly
simpler check for when the remaining iterator runs dry.
2017-09-20 11:41:59 -07:00
Josh Stone
3c1c84307c
bigint: make sure bigand is normalized
2017-09-19 17:53:13 -07:00
Josh Stone
952dba4e06
remove unused lifetime from forward_val_assign
2017-09-19 17:36:17 -07:00
Josh Stone
953087fe4e
Fix biguint assert_assign_op for rust 1.8
...
The `$op` only seems to be accepted when used indirectly through another
macro, in this case `assert_eq`. How nice.
2017-09-19 14:00:51 -07:00
Josh Stone
98a3f17db6
Fix impl_rem_assign_scalar for rust 1.8
2017-09-19 13:47:59 -07:00
Alice Ryhl
ff8f106186
Test *Assign for BigUint
2017-09-03 10:44:17 +02:00
Alice Ryhl
555dab7d33
Implement ShrAssign and ShlAssign for BigUint
2017-09-03 09:56:29 +02:00
Alice Ryhl
2f6c0bf354
Implement BitXorAssign for BigUint
2017-09-03 09:53:33 +02:00
Alice Ryhl
8c3b2de11c
Implement BitAndAssign and BitOrAssign for BigUint
2017-09-02 23:37:54 +02:00
Alice Ryhl
23085800e0
Implement RemAssign for BigUint
2017-09-02 23:29:34 +02:00
Alice Ryhl
e85ab24567
Forward by-value biguint and scalars to {Add,Mul,Sub,Div}Assign
2017-09-02 22:38:12 +02:00
Alice Ryhl
04117fafe9
Implement DivAssign for BigUint
2017-08-26 14:50:01 +02:00
Alice Ryhl
17030ea412
Implement SubAssign for BigUint
2017-08-26 14:50:01 +02:00
Alice Ryhl
8c47ca00c7
Implement MulAssign for BigUint
2017-08-26 14:50:01 +02:00
Alice Ryhl
03d717f26f
Implement AddAssign for BigUint
2017-08-26 14:50:01 +02:00
Nicolas Kirchner
bcd76c55e8
Optimize mac_digit
2017-08-15 21:14:15 +02:00
Nicolas Kirchner
243bc6fe4c
Optimize Toom-3 algorithm
2017-08-15 19:27:22 +02:00
Nicolas Kirchner
b43c1ab258
Replace the use of a feature not yet implemented in rust 1.8
2017-08-15 01:39:43 +02:00
Nicolas Kirchner
c9c40b9402
Optimize and clean the Toom-3 algorithm and choose better thresholds
2017-08-14 20:07:35 +02:00
Nicolas Kirchner
d7554ad931
Naive implementation of the Toom-3 algorithm
...
The Toom-2 algorithm is bypassed for tests.
2017-08-13 23:32:03 +02:00
Nicolas Kirchner
cbdaf8f6f9
Optimize `BigInt::from_biguint` and `BigInt::assign_from_slice`
...
It removes useless memory allocations.
2017-08-02 22:25:21 +02:00
Nicolas Kirchner
5106fcc95a
Replace `Vec::copy_from_slice` not implemented in rust 1.8 by another method
2017-08-02 16:38:38 +02:00
Nicolas Kirchner
9b56d6667c
Implement assign_from_slice
2017-08-02 16:12:04 +02:00
Josh Stone
e5434dc659
Add assert_scalar_op! for DRYer testing
2017-07-11 21:59:10 -07:00
Josh Stone
6afac825d9
test and fix more scalar add cases
2017-07-11 17:27:19 -07:00
Josh Stone
18a5bfcd0b
fix endianness of to/from_doublebigdigit calls
2017-07-11 17:22:11 -07:00
Josh Stone
18cc1902fb
inline i32_abs_as_u32 and i64_abs_as_u64
2017-07-11 17:01:15 -07:00
Sam Cappleman-Lynes
1fb03ca18a
Make new code work on rustc-1.8.0
...
- Don't apply attributes to statements (1.12.0)
- Don't use checked_abs (1.13.0)
2017-06-30 00:39:37 +01:00
Sam Cappleman-Lynes
2a3cd41820
Add scalar ops for all remaining integer types
2017-06-29 22:18:54 +01:00
Sam Cappleman-Lynes
fd87d87db3
Fix normalization in scalar addition
2017-06-29 20:40:54 +01:00
Sam Cappleman-Lynes
99873d06e5
Scalar operations on integer types up to 32 bits
2017-06-29 18:29:14 +01:00
Sam Cappleman-Lynes
94d570697c
Add operations on i32 to BigInt
2017-06-29 17:20:17 +01:00
Sam Cappleman-Lynes
9b0392d235
Add scalar division to BigInt
2017-06-29 16:19:11 +01:00
Sam Cappleman-Lynes
8b1288ea01
Add scalar multiplication to BigInt
2017-06-29 15:46:07 +01:00
Sam Cappleman-Lynes
79448cbdf9
Add scalar subtraction to BigInt
2017-06-29 15:15:59 +01:00
Sam Cappleman-Lynes
80feea2722
Also implement scalar addition for BigInt
2017-06-29 14:07:44 +01:00
Sam Cappleman-Lynes
1e26bdde81
Remove unnecessary normalization
2017-06-29 13:53:08 +01:00
Sam Cappleman-Lynes
d0bfb54eee
All variants of dividing BigUint by BigDigit
...
Allow the division to occur with either operand order and with any
combination of owned and borrowed arguments.
2017-06-29 13:38:00 +01:00
Sam Cappleman-Lynes
51408a9b3b
All variants of subtracting BigDigit from BigUint
...
Allow the subtraction to occur with either operand order and with any
combination of owned and borrowed arguments.
2017-06-29 10:12:53 +01:00
Sam Cappleman-Lynes
5738141b7c
Distinction for commutative scalar ops
2017-06-29 09:59:42 +01:00
Sam Cappleman-Lynes
fd2f516a5d
All variants of multiplying BigUint by BigDigit
...
Allow the multiplication to occur with either operand order and with any
combination of owned and borrowed arguments.
2017-06-29 09:56:15 +01:00
Sam Cappleman-Lynes
e5ed503141
Implement all variants of adding BigDigit to BigUint
...
Allow the addition to occur with either operand order, and with any combination
of owned and borrowed arguments.
2017-06-29 08:41:46 +01:00