-
Notifications
You must be signed in to change notification settings - Fork 5k
[API Proposal]: MemoryExtensions.BitwiseAnd/Or/Xor/Not #75578
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
Comments
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsBackground and motivationBitArray has And, Or, and Xor methods that combine another BitArray's bits with this BitArray's bits, and a Not method that operates on the BitArray's bits. These are vectorized and operate on the BitArray's internal int[]. But such And/Or/Xor/Not operations are more general, and as long as we've gone to the trouble to implement these efficiently, we can expose those operations for others to use as well. API Proposalnamespace System;
public class MemoryExtensions
{
public static void BitwiseAnd(this Span<byte> span, ReadOnlySpan<byte> other); // span[i] &= other[i];
public static void BitwiseOr(this Span<byte> span, ReadOnlySpan<byte> other); // span[i] |= other[i];
public static void BitwiseXor(this Span<byte> span, ReadOnlySpan<byte> other); // span[i] ^= other[i];
public static void BitwiseNot(this Span<byte> span); // span[i] = ~span[i];
} Notes:
API Usagee.g. BitArray.And would become: public unsafe BitArray And(BitArray value)
{
...
Span<byte> thisSpan = MemoryMarshal.AsBytes(m_array.AsSpan(0, count));
Span<byte> valueSpan = MemoryMarshal.AsBytes(value.m_array.AsSpan(0, count));
thisSpan.And(valueSpan);
_version++;
return this;
} Alternative DesignsNo response RisksNo response
|
As a point of some previous discussion, there is a similar proposal for this at #26651 that expresses interest in this functionality. |
Thanks; I searched but somehow missed that. Will close this in favor of that one since it's preexisting and has existing discussion. |
Uh oh!
There was an error while loading. Please reload this page.
Background and motivation
BitArray has And, Or, and Xor methods that combine another BitArray's bits with this BitArray's bits, and a Not method that operates on the BitArray's bits. These are vectorized and operate on the BitArray's internal int[]. But such And/Or/Xor/Not operations are more general, and as long as we've gone to the trouble to implement these efficiently, we can expose those operations for others to use as well.
API Proposal
Notes:
API Usage
e.g. BitArray.And would become:
Alternative Designs
ReadOnlySpan<byte>
sources and a thirdSpan<byte>
destination. Such an overload could also be instead of the two-arg overloads if we document that the same span can be used as both a source and destination input.Risks
No response
The text was updated successfully, but these errors were encountered: