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

Low-level refactoring #175

Merged
merged 15 commits into from Feb 13, 2022
Merged

Low-level refactoring #175

merged 15 commits into from Feb 13, 2022

Conversation

mratsim
Copy link
Owner

@mratsim mratsim commented Feb 13, 2022

This refactors the low-level Montgomery rperesentation:

  • Fix the ADX autodetection Buggy ADX detection #174, this brings over 30% perf boost
    • Before
      image
    • After:
      image
  • Use the convention "operation_domain" like addmod and mulmont.
  • Add a specific fromMont conversion with x86 assembly and MULX/ADCX/ADOX to speedup by 2x conversion to/from the Montgomery domain

Performance currently sits at:

  • 475µs for pairings, 157µs for hashToG2 (Both are needed for BLS verification)
  • 60µs for scalar mul on G1 (BLS: Pubkey on G2 and Signature on G1)
  • 107µs for scalar mul on G2 (BLS: Pubkey on G1 and Signature on G2) like Ethereum

image

Unfortunately 2 low-level optimizations failed and were stashed.

  1. Trying to prefetch data from inputs in Montgomery multiplication by rolling working set of registers and preloading them with the next inputs a couple iterations in advance. Unsure if the memory load didn't have enough execution port next to a MULX/ADCX/ADOX cycle or an issue with filling the instruction cache.
  2. Trying to skip the final substraction in addition chains to accelerate square root which is a bottleneck in hashToG2 and point deserialization.

@mratsim
Copy link
Owner Author

mratsim commented Feb 13, 2022

BLST, with Clang and --march=native to ensure ADX on the same machine:

image

image

@mratsim mratsim merged commit 14af7e8 into master Feb 13, 2022
@mratsim mratsim deleted the mont_repr_refactor branch February 13, 2022 23:17
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.

None yet

1 participant