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

p384: const fn field arithmetic #589

Merged
merged 1 commit into from
Jun 2, 2022
Merged

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Jun 2, 2022

Uses the fiat-constify tool to mechanically transform fiat-crypto generated field implementations into const fn:

https://github.com/RustCrypto/utils/tree/master/fiat-constify

Resulting code has been run through rustfmt prior to checking it in:

rustfmt 1.4.38-stable (fe5b13d6 2022-05-18)

The following are criterion benchmarks after the translation. While these values are within the threshold of noise I experience running them on a semi-busy desktop computer (MacBook w\ 2.3 GHz 8-Core Intel Core i9) they do paint a picture of a slight performance regression (~5%).

field element operations/mul

time: [60.361 ns 60.755 ns 61.170 ns]
change: [+3.0611% +4.1805% +5.1398%] (p = 0.00 < 0.05)
Performance has regressed.

field element operations/square

time: [59.143 ns 59.508 ns 59.924 ns]
change: [+4.8440% +5.5441% +6.2283%] (p = 0.00 < 0.05)
Performance has regressed.

field element operations/invert

time: [49.713 us 50.069 us 50.481 us]
change: [+14.227% +15.283% +16.277%] (p = 0.00 < 0.05)
Performance has regressed.

field element operations/sqrt

time: [24.936 us 25.064 us 25.206 us]
change: [+3.0874% +3.9261% +4.7805%] (p = 0.00 < 0.05)
Performance has regressed.

point operations/point-scalar mul

time: [532.24 us 535.29 us 538.62 us]
change: [+2.4804% +3.2221% +3.9748%] (p = 0.00 < 0.05)
Performance has regressed.

scalar operations/sub

time: [7.1834 ns 7.2272 ns 7.2688 ns]
change: [+13.036% +13.817% +14.551%] (p = 0.00 < 0.05)
Performance has regressed.

scalar operations/add

time: [9.5314 ns 9.5797 ns 9.6287 ns]
change: [+1.2331% +1.9875% +2.6816%] (p = 0.00 < 0.05)
Performance has regressed.

scalar operations/mul

time: [59.303 ns 59.530 ns 59.779 ns]
change: [+5.0340% +5.6533% +6.2711%] (p = 0.00 < 0.05)
Performance has regressed.

scalar operations/negate

time: [6.6648 ns 6.6915 ns 6.7244 ns]
change: [+0.1937% +1.0485% +1.8021%] (p = 0.01 < 0.05)
Change within noise threshold.

scalar operations/invert

time: [49.255 us 49.365 us 49.489 us]
change: [+12.196% +13.079% +13.937%] (p = 0.00 < 0.05)
Performance has regressed.

Uses the `fiat-constify` tool to mechanically transform `fiat-crypto`
generated field implementations into `const fn`:

https://github.com/RustCrypto/utils/tree/master/fiat-constify

Resulting code has been run through `rustfmt` prior to checking it in:

    rustfmt 1.4.38-stable (fe5b13d6 2022-05-18)

The following are criterion benchmarks after the translation. While
these values are within the threshold of noise I experience running them
on a semi-busy desktop computer (MacBook w\ 2.3 GHz 8-Core Intel Core i9)
they do paint a picture of a slight performance regression.

field element operations/mul
                        time:   [60.361 ns 60.755 ns 61.170 ns]
                        change: [+3.0611% +4.1805% +5.1398%] (p = 0.00 < 0.05)
                        Performance has regressed.

field element operations/square
                        time:   [59.143 ns 59.508 ns 59.924 ns]
                        change: [+4.8440% +5.5441% +6.2283%] (p = 0.00 < 0.05)
                        Performance has regressed.

field element operations/invert
                        time:   [49.713 us 50.069 us 50.481 us]
                        change: [+14.227% +15.283% +16.277%] (p = 0.00 < 0.05)
                        Performance has regressed.

field element operations/sqrt
                        time:   [24.936 us 25.064 us 25.206 us]
                        change: [+3.0874% +3.9261% +4.7805%] (p = 0.00 < 0.05)
                        Performance has regressed.

point operations/point-scalar mul
                        time:   [532.24 us 535.29 us 538.62 us]
                        change: [+2.4804% +3.2221% +3.9748%] (p = 0.00 < 0.05)
                        Performance has regressed.

scalar operations/sub   time:   [7.1834 ns 7.2272 ns 7.2688 ns]
                        change: [+13.036% +13.817% +14.551%] (p = 0.00 < 0.05)
                        Performance has regressed.

scalar operations/add   time:   [9.5314 ns 9.5797 ns 9.6287 ns]
                        change: [+1.2331% +1.9875% +2.6816%] (p = 0.00 < 0.05)
                        Performance has regressed.

scalar operations/mul   time:   [59.303 ns 59.530 ns 59.779 ns]
                        change: [+5.0340% +5.6533% +6.2711%] (p = 0.00 < 0.05)
                        Performance has regressed.

scalar operations/negate
                        time:   [6.6648 ns 6.6915 ns 6.7244 ns]
                        change: [+0.1937% +1.0485% +1.8021%] (p = 0.01 < 0.05)
                        Change within noise threshold.

scalar operations/invert
                        time:   [49.255 us 49.365 us 49.489 us]
                        change: [+12.196% +13.079% +13.937%] (p = 0.00 < 0.05)
                        Performance has regressed.
@tarcieri tarcieri force-pushed the p384/const-fn-field-arithmetic branch from 9c4b922 to 309984a Compare June 2, 2022 16:16
@tarcieri tarcieri merged commit 593ec93 into master Jun 2, 2022
@tarcieri tarcieri deleted the p384/const-fn-field-arithmetic branch June 2, 2022 16:26
tarcieri added a commit that referenced this pull request Jun 3, 2022
Now that #589 is landed, it's possible to add `const fn` implementations
of all core field operations, including conersions to/from Montgomery
form as well as arithmetic operations: add, double, sub, mul, neg, square
tarcieri added a commit that referenced this pull request Jun 3, 2022
Now that #589 is landed, it's possible to add `const fn` implementations
of all core field operations, including conersions to/from Montgomery
form as well as arithmetic operations: add, double, sub, mul, neg, square
@tarcieri tarcieri mentioned this pull request Jun 3, 2022
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.

1 participant