Commit Graph

63 Commits

Author SHA1 Message Date
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 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
mratsim fb2659703d Update License badge to Apache 2018-03-02 11:33:57 +01:00
Zahary Karadjov a9f51539b8 Set license to Apache v2 2018-02-27 19:37:29 +02:00
mratsim f53f7bd33a Missing overflow carry in multiplication (todo need test) 2018-02-27 13:40:18 +01:00
mratsim 8865ab874f init from uint of the same size 2018-02-17 18:32:23 +01:00
mratsim f06c02cf2a 5% more speed to divmod 2018-02-17 17:57:26 +01:00
mratsim 6fd471f243 Add division test + consistent Subtype conversion use 2018-02-17 12:44:51 +01:00
mratsim ac902b2a23 20% divmod improvement by using GCC Clang builtins when possible 2018-02-17 12:02:51 +01:00
mratsim 00040e4d38 45% faster division with 45% faster shifts (and maintainable). Fixes #1 2018-02-17 01:11:18 +01:00
mratsim 43cb3441bc Division/modulo 2x faster by removing shift in MpUint bit_length 2018-02-17 00:47:17 +01:00
mratsim 1c5da77a29 Add divmod i.e. division + modulo done! 2018-02-16 22:17:13 +01:00
mratsim a8f50c4dbe small quality of life fix + auto conversion of booleans 2018-02-16 21:07:51 +01:00
mratsim 834ff19a25 Add comparison operators + tests + fix shr forward declaration 2018-02-16 17:48:54 +01:00
mratsim f044d8a476 Add note about branchless shift being cryptographically preferable 2018-02-16 17:02:09 +01:00
mratsim 5886d76ebc Add alternative branchless shift implementation (TODO benchmark on ARM) 2018-02-16 16:47:52 +01:00
mratsim 6e27069298 less branching for shift ops 2018-02-16 14:30:07 +01:00
mratsim 35e80263a3 Add shift operators (WIP recursive implementation is slow) 2018-02-16 13:54:38 +01:00