Commit Graph

79 Commits

Author SHA1 Message Date
Mamy Ratsimbazafy 0ee1fb3ec8
Fix #30 - modulo failures (#32)
* Add corner cases to test suite

* Add failing div2n1n case

* Fix test and fix #30

* Add to tests

* Fix failing tests due to Nim string change between Apr 27 and Apr 29 (doc: 5237ef4f52)
2018-05-02 17:49:31 +02:00
mratsim d68c0bf44a Fix failing tests due to Nim string change between Apr 27 and Apr 29 (doc: 5237ef4f52) 2018-05-02 17:24:17 +02:00
Mamy Ratsimbazafy fd0482180f
Add bigint serialization (hex and decimal) (#29)
* Add serialization for decimal and hex

* Fix carry bug in signed add

* Add parsing test

* Improve highlow for int, remove most_significant_word_mut

* make conversion toString compile

* Add division corner case test

* Remove a buggy division shortcut

* Fix decimal string conversion

* Fix hex dumping

* Fix power of 2 division (what was I thinking?)

* Add hexdump test

* Move runtime check to compile-time

* Fix static assert check

* more compile-time asserts

* Fix parsing of negative hex numbers, add test_io to the suite

* dump default to bigEndian, split toString in Stint and Stuint

* Add (failing) tests with big ints conversion

* Temporarily remove all the noInit pragma
2018-04-30 13:38:55 +02:00
Mamy Ratsimbazafy f520f7817b
Merge pull request #27 from status-im/signed-integers
Add Signed integers
2018-04-26 13:06:51 +02:00
mratsim 5ac6e229a0 update signed multiplication comment 2018-04-26 12:34:28 +02:00
mratsim 6d2562ff5f Implement absolute value and signed modulo/division 2018-04-26 12:27:02 +02:00
mratsim 8727adfcf6 Implement signed multi-precision multiplication + tests 2018-04-25 22:48:25 +02:00
mratsim ee02de16fd Fix one, it impacted signed int negation and uint division (why was it not catched?). Signed int pass the full test suite 2018-04-25 21:58:10 +02:00
mratsim 37ebd13dd4 Implement add, sub, neg with proper overflow detection 2018-04-25 21:21:58 +02:00
mratsim d690923310 Update Stint in header + mention unsigned vs signed int in tests 2018-04-25 21:21:25 +02:00
mratsim 0296b5eca9 Add sub, proper negate bound checking, high and low, most significant word mutation 2018-04-25 19:51:14 +02:00
mratsim 8b412b879d Add tests for negative numbers 2018-04-25 17:58:55 +02:00
mratsim b34019c0b5 Add signed initialization, bitwise ops, addition, negation 2018-04-25 17:50:53 +02:00
mratsim e2ab2dbf59 Add signed word iteration 2018-04-25 17:02:44 +02:00
mratsim 97fbe56353 Add most significant bit and isNegative proc 2018-04-25 15:41:59 +02:00
mratsim b3dedf7824 Split initialization and conversion proc 2018-04-25 14:43:24 +02:00
mratsim 40c2215804 Add the IntImpl type. Rename uint_type to datatypes 2018-04-25 14:27:55 +02:00
mratsim f189d13b42 Prefix repo with nim 2018-04-25 14:08:31 +02:00
mratsim 00a634d2f2 Don't use single letter function like u(256) 2018-04-25 13:36:56 +02:00
Mamy Ratsimbazafy 102a1b0f0c
Rename the library to Stint (#26) 2018-04-25 12:52:00 +02:00
mratsim 52a1849075 Add (deactivated) test vs ttmath 2018-04-24 19:07:22 +02:00
mratsim d0606a338f fix travis / nimble version 2018-04-24 18:40:41 +02:00
mratsim 0987af4467 Fix #25 (binary shift change from bit_length to clz). Div/mod is now correct. Full test suite is passing 2018-04-24 18:18:36 +02:00
mratsim 0dc0b82220 Fix https://github.com/status-im/nim-mpint/issues/23 shr and shl max limit triggering undefined behaviour 2018-04-24 17:21:16 +02:00
Mamy Ratsimbazafy bfa8393878
Add property based testing (#24)
* Add property-based testing

* Reorder by testing what is most dependant (likely to go wrong) later

* Update with quickcheck support of uint: https://github.com/alehander42/nim-quicktest/issues/2

* parametrize itercount

* Add debug and release test to property testing see aliasing: https://github.com/status-im/nim-mpint/issues/23

* move `*` up as less likely to fail
2018-04-24 16:52:13 +02:00
Mamy Ratsimbazafy d5794ffbe1
Use word iteration for bitwise op (#22) + 10% perf improvement.
* Try with iterator (failing)

* Type resolution in macro for generic return values in iterators is broken ...

* Use iterators for bit operations. Optimize MpUint initialization

* Fix add_sub
2018-04-21 17:21:14 +02:00
mratsim 4ed4252af2 Use iterator for word size iteration. 2018-04-21 13:50:43 +02:00
Mamy Ratsimbazafy a2220617a0
update benchmark result 2018-04-21 12:16:26 +02:00
Mamy Ratsimbazafy 1749e0e575
[WIP] Division and multiplication optimization (#21)
* Clean-up code, part 1

* Managed to get best borrow code for the not inlined substraction #10

* Implement in place substraction in terms of substraction #10

* Another unneed proc removal/temporary step

* more cleanup

* Upgrade benchmark to Uint256

* Special case when divisor is less than halfSize x2 speed 🔥 (still 4x slower than ttmath on Uint256)

* Division: special case if dividend can overflow. 10% improvement.

* forgot to undo normalization (why did the test pass :??)

* 1st part, special cases of fast division

* Change bitops, simplify bithacks to detect new fast division cases

* 25% speed increase. Within 3x of ttmath

* Reimplement multiplication with minimum allocation

* Fix call. Now only 2x slower than ttmath

* Prepare for optimizing comparison operators

* Comparison inlining and optimization. 25% speed increase. 50% slower than ttmath now 🔥

* Fix comparison, optimize one()

* inline initMpUintImpl for another 20% speed. Only 20% slower than ttmath without ASM
2018-04-21 12:12:05 +02:00
mratsim 7a5fc76561 typo 2018-04-20 12:14:36 +02:00
mratsim 8a06bb28a0 Improve codegen for borrow. Fix #10 2018-04-20 11:55:15 +02:00
Mamy Ratsimbazafy 6eeba3d41a
Division: Fix recursive divide-and-conquer (#20)
* Simplify div2n1n

* Revert borrow detection, needed a cleverer scheme.

* Getting inspired by uint128 didn't work for recursive. Use recursive algo from the get go

* Fix shl bug ... (need fuzzy testing)

* divmod fixed for single nesting (?)

* Almost there

* Fix one part of div3n2n

* Division is wooorrrrkkinnnggg 🔥

* Fix compilation for the nested version

* forgot to not multiply by 8 the size

* Add another failing shift test

* Fix countLeadingZero for nested uint

* Cleanup: remove debugecho

* Move debug utils in a specific folder

* Fix forward declaration

* Move division it's own file
2018-04-20 11:13:47 +02:00
mratsim 55dd38c67c Fix borrow border case: see https://github.com/status-im/mpint/issues/10 2018-03-30 14:25:04 +02:00
mratsim 6c21b54a87 Significantly improve carry/borrow assembly generation https://github.com/status-im/mpint/issues/10 2018-03-30 01:40:30 +02:00
mratsim 03cb394b5d Fix xn vs x in div 2018-03-30 01:08:13 +02:00
mratsim 0417b30e56 Remove some debug leftovers 2018-03-28 21:59:16 +02:00
mratsim 4e12596295 500% division speed increase with bigint twice the size 2018-03-28 20:50:17 +02:00
Mamy Ratsimbazafy 24bd2fc986
Recursive init + bitwise as test + fix shr (#9)
* Recursive init compiles

* fix bitshift. Missing rolling over

* Strange shift required

* debug msg leftover
2018-03-28 20:45:39 +02:00
Mamy Ratsimbazafy c8190df152
Faster division algorithm (#8)
* cosmetic changes

* fix zero conversion

* Div using divided and conquer algorithm. (Compiles but doesn't work)

* Passes test with production flag
2018-03-28 17:15:36 +02:00
mratsim 2b47647019 Force checking sizes at compile-time 2018-03-26 17:39:34 +02:00
mratsim 49b3ee1006 Make the tests green again 2018-03-26 16:47:04 +02:00
mratsim 3e84c7e697 Benchmark was slowed down by Nim adding GenericResetAux 2018-03-26 16:16:07 +02:00
mratsim 34b25fd697 faster isZero 2018-03-26 16:09:31 +02:00
mratsim a809768854 Fix https://github.com/status-im/mpint/issues/7 17% speedup on modular division 2018-03-26 16:05:19 +02:00
mratsim f1935fd673 Improve speed by 90% by inline shr/shl 2018-03-26 14:46:38 +02:00
mratsim 0e7ecaef7a Add bench of modulo op 2018-03-26 12:50:50 +02:00
mratsim c65ab16512 Conversion fixes for <uint64. Also closes #4 and #5 2018-03-26 12:45:10 +02:00
mratsim 98b2086262 Use Status docker for continuous integration 2018-03-26 11:48:21 +02:00
Mamy Ratsimbazafy 3a1e5b1151
Make bits part of type (#6)
* Small reorg of conversion proc

* Rework with bits as type. Pass endianess test

* tests_comparison compiles and succeed

* Fix init with int for mpint_test compilation flag

* All tests green 🔥
2018-03-26 11:46:24 +02:00
mratsim 8b8f2a55c4 Relicense under dual Apache/MIT 2018-03-02 11:48:08 +01:00