-
Notifications
You must be signed in to change notification settings - Fork 4.9k
S.R.CS.Unsafe: Add CopyBlock/CopyBlockUnaligned and InitBlock/InitBlockUnaligned for ref byte #13848
Conversation
@@ -186,6 +194,15 @@ | |||
<param name="source">The source address to copy from.</param> | |||
<param name="byteCount">The number of bytes to copy.</param> | |||
</member> | |||
<member name="M:System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned``1(``0@,``0@,System.Int32)"> | |||
<summary> | |||
Copies elements from the source address to the destination address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use a comma. Also, the specified
?
@@ -168,6 +168,14 @@ | |||
<param name="source">The source address to copy from.</param> | |||
<param name="byteCount">The number of bytes to copy.</param> | |||
</member> | |||
<member name="M:System.Runtime.CompilerServices.Unsafe.CopyBlock``1(``0@,``0@,System.Int32)"> | |||
<summary> | |||
Copies elements from the source address to the destination address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be the specified number of elements
?
We need API approval first: see https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/api-review-process.md @atsushikan @AlexGhiondea @joperezr can you please bring it for API review if you agree with the API shape? |
I am not sure whether this trap is a good idea. I would be more confortable with non-generic version that takes |
If you change it to "ref byte", we'll need overloads that take long or ulong "counts". Span's element length is restricted to 2gb, but its byte length isn't. |
The existing CopyBlock overloads that take |
…ination, ref T source, int elementCount)
6f574a6
to
f3e98f7
Compare
…ith ref byte versions and two overloads for byteCount. Add similar InitBlock/InitBlockUnaligned for (ref byte startAddress, byte value, uint/UIntPtr byteCount).
UPDATE: API has not been approved yet! @jkotas @jamesqo @benaadams @omariom please have a look. One thing is whether "address" is a suitable parameter name for |
Sorry for the misunderstanding. The comment I have added was just my response to offline question on whether I am fine with the API. I do not think they had time to look at this one yet - ready-for-review label was not flipped.
It is not ideal, but I would opt for consistency with the |
That's correct, we had only 30 mins this week (I learned yesterday). Next Tuesday we will have 2 hours. Sorry for the delay. |
Yeah, I completely misunderstood that :) @karelz A
Yes that is why I kept the name. So fine with me. |
@nietras How exactly do you think that team names (incl. fxdc) would help? What is missing in current issue workflow or api design workflow? We have area experts/owners monitoring each area. While it is not perfect system, it is IMO much better than to rely on team mentions. I grant you team names would be useful on occasion (however it is rather rare). fxdc intentionally leaves discussions to meetings (GH/email discussions tend to create lots of back-and-forth and are not super efficient ... disclaimer: It is something I am still getting used to myself and am not 100% sure I fully agree with). |
For example, CoreCLR has "dotnet/jit-contrib" that has people working on the JIT. There are area experts for register allocator, inliner, exceptions, etc. But it is useful to have a way to address all people that work on the JIT.
Having alias does not prevent you from having in person meetings. It is complementary.
You meant online discussions, right? |
Precisely, this was what triggered my request.
I think this is completely understandable you don't have to look far (HashCode https://github.com/dotnet/corefx/issues/8034 ;) to see that these discussions can keep going for a long time, at some point the key persons responsible for this, need to make a decision. However, the process would then be that an API proposal is reviewed/drafted for some duration, until a point where the API is thought final enough that FXDC could examine it and then you mention FXDC to ask them to review it in a meeting. So... as @jkotas says:
I agree completely with this. It is a means to allow easier flagging and collaboration. Also as a newbie it is often hard to know who are who and when to mention or not. with I understand this is a two edged sword. It might result in way too much mentioning (something a newbie is always concerned about since you don't want to cause to much trouble). Ideally, it would have been good if a team mention could be guarded as well, so only say a select group of people could mention `@dotnet/fxdc" for example. |
@karelz I assume this wasn't reviewed at the last FXDC meeting? A PR for |
We have just noticed that the IL spec says that the size for these IL instructions is |
The tests passed, when I made the PR. Not sure about the asm generated though. |
Note that no tests go beyond uint number if bytes. But tests work on 64-bit with |
Should we keep those (native int) overloads even though the specification does not mention them? It's not clear to me that it's valid, and other implementations might not allow it. |
Note that there does seem to be an existing |
Currently there are the following using void CopyBlock(void* destination, void* source, native unsigned int byteCount)
void CopyBlockUnaligned(void* destination, void* source, native unsigned int byteCount)
void InitBlock(void* startAddress, uint8 'value', native unsigned int byteCount)
void InitBlockUnaligned(void* startAddress, uint8 'value', native unsigned int byteCount) Sounds reasonable to remove them if not supported by the standard. Not sure if any depend on them yet. |
Yes, I think it would be a good idea to remove them. They have not shipped in a stable package yet, so it is safe to remove them. |
… taking UIntPtr as byteCount.
@jkotas removed |
<param name="source">The source address to copy from.</param> | ||
<param name="byteCount">The number of bytes to copy.</param> | ||
</member> | ||
<member name="M:System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(System.Byte@,System.Byte@,System.UIntPtr)"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The xml doc file has the docs for the UIntPtr versions. Could you please remove them there too?
@jkotas not sure how I missed those xml docs, but hope I got them all now. PTAL. |
Thank you! |
…ckUnaligned for ref byte (dotnet/corefx#13848) * S.R.CS.Unsafe: Add CopyBlock<T>/CopyBlockUnaligned<T> for (ref T destination, ref T source, int elementCount) * S.R.CS.Unsafe: Remove new and existing InitBlock/CopyBlock* overloads taking UIntPtr as byteCount. Commit migrated from dotnet/corefx@60084eb
Adds
CopyBlock
/CopyBlockUnaligned
toUnsafe
forref
parameters as discussed in https://github.com/dotnet/corefx/issues/13427Implements the generic versions of this, if this is not wanted, it can be changed to e.g.
ref byte
. Caller must know NOT to call this with aT
containing references.@jkotas @atsushikan @benaadams @jamesqo @omariom
UPDATE: For API review, basically the choice is whether to add any of the below or perhaps both. Or in any shape that FXDC finds suitable. The below has been chosen to fit existing API definitions. The functionality is needed for
Span<T>
and otherref
based scenarios for e.g. optimal performance.OR
I will change the implementation once I get word of the result of the API review. If needed I can create a separate issue for API review, but since this change is rather small I am hoping to keep it here.
Personally, I think adding both would be great. Not the least since the generic version covers the most common use case for the work I do, and because it fits
Span<T>
.