Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use u128 for bigint limbs #9

Merged
merged 2 commits into from
Jul 25, 2018
Merged

use u128 for bigint limbs #9

merged 2 commits into from
Jul 25, 2018

Conversation

andresilva
Copy link

@andresilva andresilva commented Jul 25, 2018

This PR updates the bigints (U512 and U256) to use u128 for limbs.
The fields' inverses were defined over 2^64 so I had to extend them to 2^128.

benchcmp

name                         control ns/iter  variable ns/iter  diff ns/iter   diff %  speedup
 fq12_exponentiation          4,544,644        2,338,371           -2,206,273  -48.55%   x 1.94
 fq12_scalar_multiplication   14,569           7,125                   -7,444  -51.09%   x 2.04
 fr_addition                  17               13                          -4  -23.53%   x 1.31
 fr_inverses                  8,711            5,531                   -3,180  -36.51%   x 1.57
 fr_multiplication            104              41                         -63  -60.58%   x 2.54
 fr_subtraction               20               14                          -6  -30.00%   x 1.43
 g1_addition                  1,805            756                     -1,049  -58.12%   x 2.39
 g1_deserialization           768              482                       -286  -37.24%   x 1.59
 g1_scalar_multiplication     481,975          212,330               -269,645  -55.95%   x 2.27
 g1_serialization             9,898            6,428                   -3,470  -35.06%   x 1.54
 g1_serialization_normalized  549              431                       -118  -21.49%   x 1.27
 g1_subtraction               1,872            771                     -1,101  -58.81%   x 2.43
 g2_addition                  8,440            3,768                   -4,672  -55.36%   x 2.24
 g2_deserialization           1,776,474        864,284               -912,190  -51.35%   x 2.06
 g2_scalar_multiplication     2,056,874        983,488             -1,073,386  -52.19%   x 2.09
 g2_serialization             12,477           7,628                   -4,849  -38.86%   x 1.64
 g2_serialization_normalized  1,039            752                       -287  -27.62%   x 1.38
 g2_subtraction               8,388            3,820                   -4,568  -54.46%   x 2.20
 perform_pairing              5,315,023        2,644,591           -2,670,432  -50.24%   x 2.01


impl U512 {
/// Multiplies c1 by modulo, adds c0.
pub fn from(c1: &U256, c0: &U256, modulo: &U256) -> U512 {
let mut res = [0; 8];
pub fn new(c1: &U256, c0: &U256, modulo: &U256) -> U512 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why renaming?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It conflicts with the From implementation I added. I can remove the impl From<[u64; 8]> for U512 and just add it directly to U512 to avoid changing the name of this method.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok then

Copy link

@NikVolf NikVolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, though i'd prefer not to intruduce unnecessary changes from upstream

@NikVolf NikVolf merged commit 9f1acd9 into master Jul 25, 2018
@NikVolf NikVolf deleted the andre/bigint-u128 branch July 25, 2018 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants