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

expose GMP bit-flipping operations (tstbit, combit, etcetera) #53793

Open
stevengj opened this issue Mar 20, 2024 · 2 comments
Open

expose GMP bit-flipping operations (tstbit, combit, etcetera) #53793

stevengj opened this issue Mar 20, 2024 · 2 comments
Labels
domain:bignums BigInt and BigFloat

Comments

@stevengj
Copy link
Member

stevengj commented Mar 20, 2024

GMP provides some bit-fiddling operations that we don't currently export, e.g. to directly test or set the n-th bit.

You can simulate these operations by doing bit operations with BigInt(1) << n, but that requires constructing an intermediate BigInt.

Apparently these operations show up in some crypto algorithms, so it might be nice to expose a high-level interface.

@stevengj stevengj added the domain:bignums BigInt and BigFloat label Mar 20, 2024
@stevengj
Copy link
Member Author

stevengj commented Mar 21, 2024

Note that in the short term it would also be perfectly reasonable for someone to create a package that simply exports and documents a bunch of low-level GMP functions.

@fatteneder
Copy link
Contributor

fatteneder commented Mar 21, 2024

A comparison with the methods form the link and what is/isn't available in Base.GMP.MPZ:

Not yet implemented:

  • combit
  • clrbit
  • hamdist

Implemented, exported and documented:

  • popcount via count_zeros/count_ones
  • and/xor/ior/com as &, xor, |, ~
  • scan0/scan1 via trailing_zeros/trailing_ones

Implemented, but unexported and undocumented:

  • setbit!
  • tstbit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:bignums BigInt and BigFloat
Projects
None yet
Development

No branches or pull requests

2 participants