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

System.Runtime.Intrinsics.X86.Bmi2 - ADCX and ADOX instructions missing. #72423

Closed
vsfeedback opened this issue Jul 19, 2022 · 7 comments
Closed
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.Intrinsics
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


System.Runtime.Intrinsics.X86.Bmi2.X64 supports MULX as:

public static ulong MultiplyNoFlags(ulong left, ulong right);
public static ulong MultiplyNoFlags(ulong left, ulong right, ulong\* low);
  

But not the corresponding instructions: ADCX and ADOX.

It could help to improve a new NET7 development: dotnet/runtime/71791

Or is it that the compiler generates corresponding code automatically?
I haven’t found anything documented about this.
Is there any other way to use the feature or is somthing planned?


Original Comments

Feedback Bot on 7/10/2022, 11:22 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 19, 2022
@ghost
Copy link

ghost commented Jul 19, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics
See info in area-owners.md if you want to be subscribed.

Issue Details

This issue has been moved from a ticket on Developer Community.


System.Runtime.Intrinsics.X86.Bmi2.X64 supports MULX as:

public static ulong MultiplyNoFlags(ulong left, ulong right);
public static ulong MultiplyNoFlags(ulong left, ulong right, ulong\* low);
  

But not the corresponding instructions: ADCX and ADOX.

It could help to improve a new NET7 development: dotnet/runtime/71791

Or is it that the compiler generates corresponding code automatically?
I haven’t found anything documented about this.
Is there any other way to use the feature or is somthing planned?


Original Comments

Feedback Bot on 7/10/2022, 11:22 PM:

(private comment, text removed)


Original Solutions

(no solutions)

Author: vsfeedback
Assignees: -
Labels:

area-System.Runtime.Intrinsics, untriaged

Milestone: -

@c-ohle
Copy link

c-ohle commented Jul 19, 2022

I can offer to test trial-versions since I have currently the perfect environment for this. Multiply is the main bottleneck in my solution for arbitrary arithmetic, could I double the speed the overall performance would double. I know it's difficult, I've implemented special algorithms in C++ before and this was difficult enough and not possible without inline ASM and lot of trials. But once it works and the right sequences found, the effect is amazing. It would be so nice to see the same in C#.

@c-ohle
Copy link

c-ohle commented Jul 19, 2022

@danmoseley Many thanks for the help with the issue - delegated to the right ones.
There is another main issue what is currently in the pipe: .NET7 C# CLR support for op_Assign.
I found a solution to bypass this but it does not match the styling rules.
But it can show how easy it would be to get a dramatic performance boost, not only for special cases.
It could save so much work and time, would avoid entire builder classes for the user to deal with.
Only some lines of code for the compiler-devs and could be done in hour (or two).

@dakersnar dakersnar added this to the Future milestone Jul 19, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 19, 2022
@dakersnar dakersnar added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Jul 19, 2022
@tannergooding tannergooding added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jul 19, 2022
@tannergooding
Copy link
Member

There is nothing to do here right now. This issue needs to be fleshed out into a "proper" API proposal before it can move forward.

ADCX and ADOX in particular will have similar issues as ADC itself, which is that "add with carry" is difficult to model as an intrinsic. The C++ signature is unsigned char _addcarry_u32 (unsigned char c_in, unsigned int a, unsigned int b, unsigned int * out) and so the "logical counterpart" in C# would be bool AddWithCarry(bool carry, uint left, uint right, out uint result);. However, this requires the JIT to understand and optimize that the bool result is mapped to the "carry flag".

@c-ohle
Copy link

c-ohle commented Jul 19, 2022

@tannergooding Sure. this is difficult for C#, I have done this in C++ and there it was difficult too, lots of trials and inline ASM to find the right sequences in combination with the right algorithms. Found something like a standard sequence that works for several multiplier. Maybe this could exposed as meta function for X64.Bmi2. I will write a proposal.

@dakersnar
Copy link
Contributor

Closing this in favor of a future formal API proposal, as discussed above.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2022
@tannergooding tannergooding removed the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Jun 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.Intrinsics
Projects
None yet
Development

No branches or pull requests

5 participants