Commit Graph

6092 Commits

Author SHA1 Message Date
Dave Collins
5f7eb93f64
docs: Update for database v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2021-11-19 23:32:34 -06:00
Dave Collins
a01ee5d769
peer: Prepare v3.0.0.
This updates the peer module dependencies, the copyright year in the
files modified since the previous release, and serves as a base for
peer/v3.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/txscript/v4@v4.0.0

The full list of updated direct dependencies since the previous
peer/v2.2.0 release are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/txscript/v4@v4.0.0
- github.com/decred/dcrd/wire@v1.5.0
- github.com/decred/slog@v1.2.0

Finally, all modules in the repository that depend on the module are
tidied to ensure they are updated to use the latest versions hoisted
forward as a result.
2021-11-19 23:26:29 -06:00
Dave Collins
78d3590592
docs: Update for peer v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2021-11-19 23:26:26 -06:00
Dave Collins
8f3fd5a020
uint256: Add README.md. 2021-11-19 17:31:39 -06:00
Dave Collins
7abc0d9496
uint256: Add basic usage example.
This adds an example of calculating the result of dividing a max
unsigned 256-bit integer by a max unsigned 128-bit integer and
outputting that result in hex with leading zeros.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:31:39 -06:00
Dave Collins
3d83510579
uint256: Add conversion from stdlib big int benchmark.
The following shows the typical performance of converting a standard
library big integer that has already been reduced modulo 2^256 to a
uint256:

Uint256SetBig   26944130   44.45 ns/op   0 B/op   0 allocs/op

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:31:39 -06:00
Dave Collins
8dbc97e178
uint256: Add conversion from stdlib big int support.
This adds a convenience method for converting a standard library big
integer to a uint256 (modulo 2^256) along with associated tests to
ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:31:38 -06:00
Dave Collins
15eac536d1
uint256: Add conversion to stdlib big int benchmark.
The following shows the typical performance of converting a uint256 to a
standard library big integer using one that already exists:

Uint256PutBig   43651442   27.29 ns/op   0 B/op   0 allocs/op

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:31:38 -06:00
Dave Collins
6065dd8c4d
uint256: Add conversion to stdlib big int support.
This adds convenience methods for converting a uint256 to a standard
library big integer along with associated tests to ensure proper
functionality.

It includes a method that allows an existing big integer to be reused
thereby potentially saving allocations as well as a method that returns
a new big integer.  The latter is often more convenient to use, but is
also virtually guaranteed to cause an allocation.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:31:37 -06:00
Dave Collins
4653cbc774
uint256: Add text formatting benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name             old time/op     new time/op     delta
---------------------------------------------------------------------------
Text/base_2      579ns ± 3%      496ns ± 2%      -14.37%  (p=0.000 n=10+10)
Text/base_8      266ns ± 1%      227ns ± 1%      -14.58%  (p=0.000 n=10+10)
Text/base_10     536ns ± 1%      458ns ± 2%      -14.58%  (p=0.000 n=10+10)
Text/base_16     205ns ± 2%      180ns ± 4%      -11.90%  (p=0.000 n=10+10)
Format/base_2    987ns ±15%      852ns ± 2%      -13.64%  (p=0.000 n=10+10)
Format/base_8    620ns ± 6%      544ns ± 3%      -12.31%  (p=0.000 n=10+10)
Format/base_10   888ns ± 1%      726ns ± 1%      -18.25%  (p=0.000 n=10+10)
Format/base_16   565ns ± 1%      449ns ± 1%      -20.41%  (p=0.000 n=10+10)

name             old allocs/op   new allocs/op   delta
--------------------------------------------------------------------------
Text/base_2      2.00 ± 0%       2.00 ± 0%         ~     (all equal)
Text/base_8      2.00 ± 0%       2.00 ± 0%         ~     (all equal)
Text/base_10     3.00 ± 0%       2.00 ± 0%      -33.33%  (p=0.000 n=10+10)
Text/base_16     2.00 ± 0%       2.00 ± 0%         ~     (all equal)
Format/base_2    5.00 ± 0%       3.00 ± 0%      -40.00%  (p=0.000 n=10+10)
Format/base_8    5.00 ± 0%       3.00 ± 0%      -40.00%  (p=0.000 n=10+10)
Format/base_10   6.00 ± 0%       3.00 ± 0%      -50.00%  (p=0.000 n=10+10)
Format/base_16   5.00 ± 0%       3.00 ± 0%      -40.00%  (p=0.000 n=10+10)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:19 -06:00
Dave Collins
4f7eaa879f
uint256: Add text formatting support.
This adds full support for formatting a uint256 along with associated
tests to ensure proper functionality.

It includes a fmt.Formatter that supports the full suite of the fmt
package format flags for integral types, a fmt.Stringer, and a separate
Text method that accepts an output base directly and produces the
relevant output with fewer allocations than using the standard fmt
methods.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:19 -06:00
Dave Collins
37b4c65dcd
uint256: Add bit length benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name       old time/op     new time/op     delta
---------------------------------------------------------------------
bits_64    2.24ns ± 1%     1.94ns ± 3%     -13.04%  (p=0.000 n=10+10)
bits_128   2.25ns ± 2%     1.96ns ± 2%     -13.17%  (p=0.000 n=10+10)
bits_192   2.25ns ± 1%     1.60ns ± 1%     -28.65%  (p=0.000 n=10+10)
bits_255   2.26ns ± 2%     1.61ns ± 1%     -29.04%  (p=0.000 n=10+10)

name       old allocs/op   new allocs/op   delta
------------------------------------------------------------
bits_64    0.00            0.00            ~     (all equal)
bits_128   0.00            0.00            ~     (all equal)
bits_192   0.00            0.00            ~     (all equal)
bits_255   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:18 -06:00
Dave Collins
c0854f6f17
uint256: Add bit length support.
This adds support for determining the minimum number of bits required to
represent the current value of a uint256 along with associated tests to
ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:18 -06:00
Dave Collins
7ba863dff6
uint256: Add bitwise xor benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name   old time/op     new time/op     delta
-----------------------------------------------------------------
Xor    17.9ns ± 5%     3.4ns ± 6%      -80.91%  (p=0.000 n=10+10)

name   old allocs/op   new allocs/op   delta
--------------------------------------------------------
Xor    0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:18 -06:00
Dave Collins
d17692072d
uint256: Add bitwise xor support.
This adds support to compute the bitwise xor of two uint256s along with
associated tests to ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:17 -06:00
Dave Collins
275afa2272
uint256: Add bitwise and benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name   old time/op     new time/op     delta
-----------------------------------------------------------------
And    16.7ns ± 5%     3.4ns ± 6%      -79.93%  (p=0.000 n=10+10)

name   old allocs/op   new allocs/op   delta
--------------------------------------------------------
And    0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:17 -06:00
Dave Collins
97bdac8ad4
uint256: Add bitwise and support.
This adds support to compute the bitwise and of two uint256s along with
associated tests to ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:16 -06:00
Dave Collins
33601a06d3
uint256: Add bitwise or benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name   old time/op     new time/op     delta
-----------------------------------------------------------------
Or     17.9ns ± 5%     3.4ns ± 6%      -80.94%  (p=0.000 n=10+10)

name   old allocs/op   new allocs/op   delta
--------------------------------------------------------
Or     0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:16 -06:00
Dave Collins
269eee2069
uint256: Add bitwise or support.
This adds support to compute the bitwise or of two uint256s along with
associated tests to ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:15 -06:00
Dave Collins
3ce3e33056
uint256: Add bitwise not benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name   old time/op     new time/op     delta
-----------------------------------------------------------------
Not    25.4ns ± 2%     3.3ns ± 2%      -86.79%  (p=0.000 n=10+10)

name   old allocs/op   new allocs/op   delta
--------------------------------------------------------
Not    0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:15 -06:00
Dave Collins
a42b8c89bf
uint256: Add bitwise not support.
This adds support to compute the bitwise not of a uint256 along with
associated tests to ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:15 -06:00
Dave Collins
6fd319eb3d
uint256: Add bitwise right shift benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name           old time/op     new time/op     delta
-------------------------------------------------------------------------
Rsh/bits_0     8.76ns ± 2%     2.57ns ± 1%     -70.63%  (p=0.000 n=10+10)
Rsh/bits_1     14.4ns ± 2%     4.3ns ± 2%      -70.28%  (p=0.000 n=10+10)
Rsh/bits_64    12.8ns ± 1%     2.9ns ± 2%      -77.31%  (p=0.000 n=10+10)
Rsh/bits_128   11.8ns ± 0%     2.9ns ± 2%      -75.51%  (p=0.000 n=10+10)
Rsh/bits_192   10.5ns ± 2%     2.6ns ± 1%      -75.17%  (p=0.000 n=10+10)
Rsh/bits_255   10.5ns ± 3%     2.8ns ± 2%      -73.89%  (p=0.000 n=10+10)
Rsh/bits_256   5.50ns ± 1%     2.58ns ± 2%     -53.15%  (p=0.000 n=10+10)

name           old allocs/op   new allocs/op   delta
----------------------------------------------------------------
Rsh/bits_0     0.00            0.00            ~     (all equal)
Rsh/bits_1     0.00            0.00            ~     (all equal)
Rsh/bits_64    0.00            0.00            ~     (all equal)
Rsh/bits_128   0.00            0.00            ~     (all equal)
Rsh/bits_192   0.00            0.00            ~     (all equal)
Rsh/bits_255   0.00            0.00            ~     (all equal)
Rsh/bits_256   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:14 -06:00
Dave Collins
0084625efe
uint256: Add bitwise right shift support.
This adds support for uint256 bitwise right shifting along with
associated tests to ensure proper functionality.

It includes right shifting an existing uint256 (a >> b) and assigning
the result of right shifting a uint256 to a second one (a >>= b).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:14 -06:00
Dave Collins
78444894a8
uint256: Add bitwise left shift benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name           old time/op     new time/op     delta
-------------------------------------------------------------------------
Lsh/bits_0      7.1ns ± 3%     2.58ns ± 1%     -63.94%  (p=0.000 n=10+10)
Lsh/bits_1     14.8ns ± 1%     4.2ns ± 1%      -71.40%  (p=0.000 n=10+10)
Lsh/bits_64    16.7ns ± 1%     2.7ns ± 1%      -84.00%  (p=0.000 n=10+10)
Lsh/bits_128   16.9ns ± 2%     2.7ns ± 0%      -84.21%  (p=0.000 n=10+10)
Lsh/bits_192   16.6ns ± 1%     2.6ns ± 1%      -84.19%  (p=0.000 n=10+10)
Lsh/bits_255   16.3ns ± 2%     2.8ns ± 2%      -83.11%  (p=0.000 n=10+10)
Lsh/bits_256   16.9ns ± 2%     2.6ns ± 2%      -84.77%  (p=0.000 n=10+10)

name           old allocs/op   new allocs/op   delta
----------------------------------------------------------------
Lsh/bits_0     0.00            0.00            ~     (all equal)
Lsh/bits_1     0.00            0.00            ~     (all equal)
Lsh/bits_64    0.00            0.00            ~     (all equal)
Lsh/bits_128   0.00            0.00            ~     (all equal)
Lsh/bits_192   0.00            0.00            ~     (all equal)
Lsh/bits_255   0.00            0.00            ~     (all equal)
Lsh/bits_256   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:13 -06:00
Dave Collins
1114a414e7
uint256: Add bitwise left shift support.
This adds support for uint256 bitwise left shifting along with
associated tests to ensure proper functionality.

It includes left shifting an existing uint256 (a << b) and assigning the
result of left shifting a uint256 to a second one (a <<= b).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:13 -06:00
Dave Collins
66e2409d9b
uint256: Add is odd benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name    old time/op     new time/op     delta
------------------------------------------------------------------
IsOdd   3.62ns ± 4%     1.64ns ± 1%     -54.65%  (p=0.000 n=10+10)

name    old allocs/op   new allocs/op   delta
---------------------------------------------------------
IsOdd   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:13 -06:00
Dave Collins
944a8889d6
uint256: Add is odd support.
This adds the ability to determine if a uint256 is odd along with
associated tests to ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:12 -06:00
Dave Collins
768cf62763
uint256: Add negation benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name     old time/op     new time/op     delta
-------------------------------------------------------------------
Negate   47.3ns ± 2%     1.5ns ± 2%      -96.91%  (p=0.000 n=10+10)

name     old allocs/op   new allocs/op   delta
----------------------------------------------------------
Negate   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:12 -06:00
Dave Collins
d92a3307fd
uint256: Add negation support.
This adds support for uint256 negation (modulo 2^256) along with
associated tests to ensure proper functionality.

It includes negating an existing uint256 (a = -a) and assigning the
result of negating a uint256 to a second one (a = -b).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:11 -06:00
Dave Collins
ff68ec7b43
uint256: Add division benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name              old time/op     new time/op     delta
----------------------------------------------------------------------------
Div/num_lt_den     75.4ns ± 1%     3.4ns ± 1%     -95.51%  (p=0.000 n=10+10)
Div/num_eq_den    253.0ns ± 2%     4.0ns ± 3%     -98.56%  (p=0.000 n=10+10)
Div/1_by_1_near    53.8ns ± 2%     4.5ns ± 2%     -91.63%  (p=0.000 n=10+10)
Div/1_by_1_far     31.4ns ± 2%    14.6ns ± 2%     -53.64%  (p=0.000 n=10+10)
Div/2_by_1_near    36.9ns ± 1%    10.1ns ± 2%     -72.63%  (p=0.000 n=10+10)
Div/2_by_1_far     49.1ns ± 1%    28.8ns ± 1%     -41.29%  (p=0.000 n=10+10)
Div/3_by_1_near    43.2ns ± 1%    13.7ns ± 3%     -68.24%  (p=0.000 n=10+10)
Div/3_by_1_far     57.0ns ± 1%    43.6ns ± 1%     -23.59%  (p=0.000 n=10+10)
Div/4_by_1_near    49.7ns ± 4%    18.0ns ± 1%     -63.87%  (p=0.000 n=10+10)
Div/4_by_1_far     65.2ns ± 4%    57.8ns ± 2%     -11.41%  (p=0.000 n=10+10)
Div/2_by_2_near   237.0ns ± 1%    22.0ns ± 3%     -90.81%  (p=0.000 n=10+10)
Div/2_by_2_far    237.0ns ± 1%    30.0ns ± 3%     -87.17%  (p=0.000 n=10+10)
Div/3_by_2_near   258.0ns ± 1%    29.0ns ± 1%     -88.60%  (p=0.000 n=10+10)
Div/3_by_2_far    257.0ns ± 1%    50.0ns ± 2%     -80.42%  (p=0.000 n=10+10)
Div/4_by_2_near   312.0ns ± 2%    40.0ns ± 3%     -87.27%  (p=0.000 n=10+10)
Div/4_by_2_far    310.0ns ± 1%    71.0ns ± 3%     -77.19%  (p=0.000 n=10+10)
Div/3_by_3_near   239.0ns ± 2%    21.0ns ± 2%     -91.39%  (p=0.000 n=10+10)
Div/3_by_3_far    242.0ns ± 4%    33.0ns ± 3%     -86.33%  (p=0.000 n=10+10)
Div/4_by_3_near   279.0ns ± 6%    31.0ns ± 1%     -89.01%  (p=0.000 n=10+10)
Div/4_by_3_far    271.0ns ± 1%    46.0ns ± 3%     -82.99%  (p=0.000 n=10+10)
Div/4_by_4_near   252.0ns ± 3%    20.0ns ± 3%     -91.99%  (p=0.000 n=10+10)
Div/4_by_4_far    249.0ns ± 2%    36.0ns ± 2%     -85.65%  (p=0.000 n=10+10)
DivRandom         202.0ns ± 1%    23.0ns ± 1%     -88.43%  (p=0.000 n=10+10)
DivUint64         129.0ns ± 1%    47.0ns ± 0%     -63.34%  (p=0.000 n=10+10)

name              old allocs/op   new allocs/op   delta
-----------------------------------------------------------------------------
Div/num_lt_den    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/num_eq_den    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/1_by_1_far    0.00            0.00                ~     (all equal)
Div/1_by_1_near   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/2_by_1_far    0.00            0.00                ~     (all equal)
Div/2_by_1_near   0.00            0.00                ~     (all equal)
Div/3_by_1_far    0.00            0.00                ~     (all equal)
Div/3_by_1_near   0.00            0.00                ~     (all equal)
Div/4_by_1_far    0.00            0.00                ~     (all equal)
Div/4_by_1_near   0.00            0.00                ~     (all equal)
Div/2_by_2_far    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/2_by_2_near   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/3_by_2_far    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/3_by_2_near   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/4_by_2_far    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/4_by_2_near   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/3_by_3_far    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/3_by_3_near   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/4_by_3_far    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/4_by_3_near   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/4_by_4_far    1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
Div/4_by_4_near   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
DivRandom         1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
DivUint64         1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:11 -06:00
Dave Collins
7ef9c18a92
uint256: Add division support.
This adds support for uint256 division (modulo 2^256) along with
associated tests to ensure proper functionality.

It includes dividing an existing uint256 by a second one (a /= b),
dividing two uint256s and assigning the result to a third (a = b/c), and
dividing an existing uint256 by a uint64 (a /= uint256(b)).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:04:11 -06:00
Dave Collins
8d27f653cd
uint256: Add squaring benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name     old time/op     new time/op     delta
-------------------------------------------------------------------
Square   418ns ± 0%      7ns ± 2%        -98.39%  (p=0.000 n=10+10)

name     old allocs/op   new allocs/op   delta
--------------------------------------------------------------------
Square   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:14 -06:00
Dave Collins
dc2a08f477
uint256: Add squaring support.
This adds support for uint256 squaring (modulo 2^256) along with
associated tests to ensure proper functionality.

It includes squaring an existing uint256 (a *= a) and assigning the
result of squaring a uint256 to a second one (a = b*b).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:14 -06:00
Dave Collins
fa9f70e76e
uint256: Add multiplication benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name        old time/op     new time/op     delta
----------------------------------------------------------------------
Mul         419ns ± 1%      10ns ± 1%      -97.64%  (p=0.000 n=10+10)
MulUint64   263ns ± 1%       4ns ± 1%      -98.30%  (p=0.000 n=10+10)

name        old allocs/op   new allocs/op   delta
-----------------------------------------------------------------------
Mul         1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)
MulUint64   1.00 ± 0%       0.00            -100.00%  (p=0.000 n=10+10)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:13 -06:00
Dave Collins
8cfc4dc0a4
uint256: Add multiplication support.
This adds support for uint256 multiplication (modulo 2^256) along with
associated tests to ensure proper functionality.

It includes multiplying a uint256 with an existing one (a *= b),
multiplying two uint256s and assigning the result to a third (a = b *
c), and multiplying an existing uint256 with a uint64 (a *= uint256(b)).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:13 -06:00
Dave Collins
fe684af77f
uint256: Add subtraction benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name        old time/op     new time/op     delta
---------------------------------------------------------------------
Sub         53.9ns ± 1%    2.1ns ± 1%      -96.12%  (p=0.000 n=10+10)
SubUint64   44.8ns ± 1%    3.4ns ± 2%      -92.37%  (p=0.000 n=10+10)

name        old allocs/op   new allocs/op   delta
-------------------------------------------------------------
Sub         0.00            0.00            ~     (all equal)
SubUint64   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:12 -06:00
Dave Collins
90d4ba8020
uint256: Add subtraction support.
This adds support for uint256 subtraction (modulo 2^256) along with
associated tests to ensure proper functionality.

It includes subtracting a uint256 from an existing one (a -= b),
subtracting two uint256s and assigning the result to a third (a = b -
c), and subtracting a uint64 from an existing uint256 (a -= uint256(b)).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:12 -06:00
Dave Collins
e6b423b0ab
uint256: Add addition benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name        old time/op     new time/op     delta
----------------------------------------------------------------------
Add         158.0ns ± 2%    2.0ns ± 1%      -98.67%  (p=0.000 n=10+10)
AddUint64    44.4ns ± 3%    3.4ns ± 2%      -92.27%  (p=0.000 n=10+10)

name        old allocs/op   new allocs/op   delta
-------------------------------------------------------------
Add         0.00            0.00            ~     (all equal)
AddUint64   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:12 -06:00
Dave Collins
ff8c41c25b
uint256: Add addition support.
This adds support for uint256 addition (modulo 2^256) along with
associated tests to ensure proper functionality.

It includes adding a uint256 to an existing one (a += b), adding two
uint256s and assigning the result to a third (a = b + c), and adding a
uint64 to an existing uint256 (a += uint256(b)).

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:11 -06:00
Dave Collins
5b089289bc
uint256: Add general comparison benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name        old time/op     new time/op     delta
----------------------------------------------------------------------
Cmp         12.6ns  ± 1%    7.7ns ± 1%      -39.01%  (p=0.000 n=10+10)
CmpUint64    5.93ns ± 2%    3.7ns ± 1%      -37.60%  (p=0.000 n=10+10)

name        old allocs/op   new allocs/op   delta
-------------------------------------------------------------
Cmp         0.00            0.00            ~     (all equal)
CmpUint64   0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:11 -06:00
Dave Collins
2d86902ba7
uint256: Add general comparison support.
This adds the ability to compare a uint256 to another uint256 or a
uint64 along with associated tests to ensure proper functionality.

The comparison logic is the usual logic where -1 is returned when the
uint256 is less than the value being compared to, 0 when it is equal,
and 1 when it is greater.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:10 -06:00
Dave Collins
e8ba80ed6a
uint256: Add greater or equals comparison support.
This adds the ability to determine if a uint256 is greater than or equal
to another uint256 or a uint64 along with associated tests to ensure
proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:10 -06:00
Dave Collins
dd40c5759a
uint256: Add greater than comparison benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name   old time/op     new time/op     delta
-----------------------------------------------------------------
Gt     12.6ns ± 1%     3.0ns ± 1%      -75.91%  (p=0.000 n=10+10)

name   old allocs/op   new allocs/op   delta
--------------------------------------------------------
Gt     0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:10 -06:00
Dave Collins
c1b94c2394
uint256: Add greater than comparison support.
This adds the ability to determine if a uint256 is greater than another
uint256 or a uint64 along with associated tests to ensure proper
functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:09 -06:00
Dave Collins
4831b21278
uint256: Add less or equals comparison support.
This adds the ability to determine if a uint256 is less than or equal to
another uint256 or a uint64 along with associated tests to ensure proper
functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:09 -06:00
Dave Collins
7e9ed058af
uint256: Add less than comparison benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name   old time/op     new time/op     delta
-----------------------------------------------------------------
Lt     12.6ns ± 1%     3.0ns ± 1%      -75.96%  (p=0.000 n=10+10)

name   old allocs/op   new allocs/op   delta
--------------------------------------------------------
Lt     0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:08 -06:00
Dave Collins
e574a5f695
uint256: Add less than comparison support.
This adds the ability to determine if a uint256 is less than another
uint256 or a uint64 along with associated tests to ensure proper
functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:08 -06:00
Dave Collins
393c7d6df1
uint256: Add equality comparison benchmarks.
The following is a comparison between stdlib big integers (old) and the
specialized type (new) averaging 10 runs each:

name   old time/op     new time/op     delta
-----------------------------------------------------------------
Eq     12.7ns ± 1%     2.1ns ± 1%      -83.72%  (p=0.000 n=10+10)

name   old allocs/op   new allocs/op   delta
--------------------------------------------------------
Eq     0.00            0.00            ~     (all equal)

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:08 -06:00
Dave Collins
ed6ef23d0a
uint256: Add equality comparison support.
This adds the ability to determine if a uint256 represents the same
value as another uint256 or as a uint64 along with associated tests to
ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:07 -06:00
Dave Collins
b46ff5ef5b
uint256: Add uint64 casting support.
This adds the ability to determine if a uint256 can be converted to a
uint64 without any loss of precision as well a method to cast it along
with associated tests to ensure proper functionality.

This is part of a series of commits to fully implement the uint256
package.
2021-11-19 17:00:07 -06:00