Commit Graph

297 Commits

Author SHA1 Message Date
mratsim c296e14dde Merge branch 'master' of https://github.com/status-im/nim-stint 2018-05-08 13:50:05 +02:00
mratsim 2efaf3e623 Export zero and one proc 2018-05-08 13:49:58 +02:00
Mamy Ratsimbazafy adb75b32b8
[IO]: Add readUintBE, hexToUint, toByteArrayBE
* Add readUintBE and toByteArrayBE proc

* Add readUintBE, hexToUint, to ByteArrayBE and reorder parse arguments + tests
2018-05-08 13:21:04 +02:00
Mamy Ratsimbazafy 1653a8815f
Restrict pragma: use C, C++, VCC + GCC + LLVM compatible syntax (#41) 2018-05-08 11:46:21 +02:00
mratsim 1b7423eacd Export countLeadingZeroBits 2018-05-06 23:02:50 +02:00
mratsim 7dad3f89d8 Export string parsing shortcut "u256" 2018-05-06 22:41:49 +02:00
mratsim 1ff544eabf Remove the fooPragma placeholder (for noinit) 2018-05-06 22:29:08 +02:00
mratsim 0dae6897b1 high/low was missing the internal proc 2018-05-06 22:24:51 +02:00
mratsim 8c0d830acf Export high and low proc 2018-05-06 22:19:00 +02:00
mratsim b5e3e316cb use a more reasonable 10000 tests by default 2018-05-04 10:02:46 +02:00
mratsim 0a1129b36a Update comment displayed in property-based testing 2018-05-04 00:20:32 +02:00
mratsim 40f33238d9 Update uint256 to display the number of iterations 2018-05-04 00:14:51 +02:00
Mamy Ratsimbazafy 4c055e42a7
Add uint256 fuzz test vs TTMath (#34) + Fix multiplication carry bug #36
* Add uint256 fuzz test vs TTMath

* fix the compilation of property_based_uint256

* Fix multiplication carry bug #35

* Change comment in test
2018-05-04 00:11:07 +02:00
Zahary Karadjov c6b55f168f fix the compilation of property_based_uint256 2018-05-03 21:10:55 +03:00
mratsim 4a827027b7 Fix Travis script 2018-05-03 11:35:07 +02:00
mratsim b731108b1c Update Quicktest & Continuous Integration configuration to latest. 2018-05-03 11:07:33 +02:00
mratsim 18e73e7168 Merge branch 'master' of https://github.com/status-im/nim-stint 2018-05-02 18:02:17 +02:00
mratsim c9cba06db1 Make ttmath testing compile 2018-05-02 18:02:13 +02:00
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