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

[WIP] Spannified internals of BigInteger #19672

Closed

Conversation

monojenkins
Copy link
Contributor

!! This PR is a copy of dotnet/runtime#35565, please do not edit or review it in this repo !!
Do not automatically approve this PR:

* Consider how the changes affect configurations in this repo,
* Check effects on files that are not mirrored,
* Identify test cases that may be needed in this repo.

!! Merge the PR only after the original PR is merged !!



Proposed refactoring according with issue: dotnet/runtime#22609. The implementation plan consists of the following steps:

  • Replace unmanaged pointers with managed ones as well as remove unsafe code and pinning
  • Beautify stack allocation
  • Use spans wherever possible, especially for memory slicing
  • Simplify (or probably remove at all) BitsBuffer value type
  • Spannify FastReducer value type
  • Attempt to replace some array allocations with span slicing
  • Square, Multiply and bitwise operations use heap-based allocation of arrays if their length is greater than or equal to stack allocation threshold. Maybe replace it with array pooling using shared ArrayPool<T>?
  • BMI intrinsics??

Spannified versions of internal and private static methods look pretty nice. However, I'm not sure about performance of passing span to the method. If RyuJIT uses scalar replacement then it's good news. Otherwise, maybe pass length and managed pointer to the first element as separate arguments to ensure that they passed through registers. This version was implemented in the first commit. I need advice here as well as preliminary code review because further work fully based on signatures of spannified methods.

cc @tannergooding , @stephentoub

Proposed refactoring according with issue: dotnet/runtime#22609. The implementation plan consists of the following steps:

- [x] Replace unmanaged pointers with managed ones as well as remove unsafe code and pinning
- [x] Beautify stack allocation
- [x] Use spans wherever possible, especially for memory slicing
- [ ] Simplify (or probably remove at all) `BitsBuffer` value type
- [ ] Spannify `FastReducer` value type
- [ ] Attempt to replace some array allocations with span slicing
- [ ] Square, Multiply and bitwise operations use heap-based allocation of arrays if their length is greater than or equal to stack allocation threshold. Maybe replace it with array pooling using shared `ArrayPool<T>`?
- [ ] BMI intrinsics??

Spannified versions of internal and private static methods look pretty nice. However, I'm not sure about performance of passing span to the method. If RyuJIT uses scalar replacement then it's good news. Otherwise, maybe pass length and managed pointer to the first element as separate arguments to ensure that they passed through registers. This version was implemented in the first commit. I need advice here as well as preliminary code review because further work fully based on signatures of spannified methods.

cc @tannergooding , @stephentoub
@sakno
Copy link

sakno commented Apr 29, 2020

This is my mistake. Sorry, guys. I did rebase instead of regular pull. As a result, this PR has been created. I think it can be closed.

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.

3 participants