You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's quite common to want to convert a Span to Vector. It's possible to open code such conversion, but the code is a bit tricky and people do it commonly enough that we shoudl just add a helper to SpanExtensions
while(span.Length>=Vector<byte>.Count){Vector<byte>vec=span.AsVector();// stuff with vecspan=span.Slice(0,Vector<byte>.Count);}
presumably it's followed by a loop on the remaining bytes:
while(span.Length>=Vector<byte>.Count){Vector<byte>vec=span.AsVector();// stuff with vecspan=span.Slice(0,Vector<byte>.Count);}for(inti=0;i<span.Length;i++){// stuff with span[i]}
What does that look like with this Span<Vector<T>> version?
Span<T>span;Span<Vector<T>>vSpan=Convert(span);for(inti=0;i<vSpan.Length;i++){// Do stuff with vSpan[i]}span=span.Slice(Vector<T>.Count*vSpan.Length);for(inti=0;i<span.Length;i++){// stuff with span[i]}
What does that look like with this Span<Vector> version?
Depends if slice first or hard fail on conversion
varvSpan=span.Slice(0,span.Length%Vector<byte>.Count).AsVectorSpan();for(vari=0;i<vSpan.Length;i++){varvec=vSpan[i];// stuff with vec}span=span.Slice(Vector<byte>.Count*vSpan.Length);for(inti=0;i<span.Length;i++){// stuff with span[i]}
or as part of a Try call that does a partial amount
if(span.TryAsVectorSpan(outvarvSpan)){for(vari=0;i<vSpan.Length;i++){varvec=vSpan[i];// stuff with vec}span=span.Slice(Vector<byte>.Count*vSpan.Length);}for(inti=0;i<span.Length;i++){// stuff with span[i]}
.AsVector forces it to local var; which has the advantage of more likely dealing with vector registers; however would require the (Vector size) bounds check to be hoisted across slicing which may be more tricky? Also updating the Vector in the span would be harder for writes.
.AsVectorSpan the bounds check (at Vector size) is manually hoisted via the api; and write backs are easier; so if you wanted to apply a in-place masking on a stream you could do
To make sure I understand the ask and, the conclusion in the recording... this is a constructor that "copies" the contents of the span into the vector; no re-interpretation of span's is expected here...
EDIT: I had code ready, based on the understanding, I have raised the PR. Kindly review and let me know.
Activity
mellinoe commentedon Sep 29, 2017
Is converting your
Span<T>into aSpan<Vector<T>>a viable / safe option? That would let you use the span normally, through the indexer.benaadams commentedon Sep 29, 2017
Don't need the
ReadUnaligned?What would the usage be? Something like:
Something like?
mellinoe commentedon Sep 29, 2017
Right, and then you could just read and write directly to the indexer.
benaadams commentedon Sep 29, 2017
Merging the two... What about
AsVectorSpanso you don't need to invokeNonPortableCast(as a user)?stephentoub commentedon Sep 29, 2017
With the earlier example:
presumably it's followed by a loop on the remaining bytes:
What does that look like with this
Span<Vector<T>>version?mellinoe commentedon Sep 29, 2017
I think it would be something like this:
benaadams commentedon Sep 30, 2017
Depends if slice first or hard fail on conversion
or as part of a Try call that does a partial amount
With a
TryAsVectorSpanMay also have predetermined fixed sized Vector processing that has no extra elements
Probably the extensions should live in namespace
System.Numerics?benaadams commentedon Sep 30, 2017
.AsVectorforces it to local var; which has the advantage of more likely dealing with vector registers; however would require the (Vector size) bounds check to be hoisted across slicing which may be more tricky? Also updating the Vector in the span would be harder for writes..AsVectorSpanthe bounds check (at Vector size) is manually hoisted via the api; and write backs are easier; so if you wanted to apply a in-place masking on a stream you could doThough it may lead to more direct operations on the Vector elements, so shunting from memory and registers more?
ahsonkhan commentedon Oct 28, 2017
@KrzysztofCwalina, is the proposal ready for review?
terrajobst commentedon Dec 5, 2017
Video
We should align it with the existing APIs, so I'd rather make this a ctor on
Vector<T>itself:karelz commentedon Dec 5, 2017
FYI: The API review discussion was recorded - see https://youtu.be/BI3iXFT8H7E?t=5251 (11 min duration)
karelz commentedon Dec 5, 2017
Top post updated with approved API shape above https://github.com/dotnet/corefx/issues/24343#issuecomment-349418624.
WinCPP commentedon Jan 21, 2018
To make sure I understand the ask and, the conclusion in the recording... this is a constructor that "copies" the contents of the span into the vector; no re-interpretation of span's is expected here...
Issue #24343 Vector Ctor using Span
13 remaining items
CoreFX #24343 Vector Ctor using Span (dotnet/coreclr#16733)
CoreFX #24343 Vector Ctor using Span (dotnet/coreclr#16733)
CoreFX #24343 Vector Ctor using Span (dotnet/coreclr#16733)
CoreFX #24343 Vector Ctor using Span (dotnet/coreclr#16733)
Issue #24343 Vector Ctor using Span
Issue #24343 Vector Ctor using Span
Issue #24343 Vector Ctor using Span
Issue #24343 Vector Ctor using Span
Issue #24343 Vector Ctor using Span
Revert "Issue #24343 Vector Ctor using Span"
CoreFX #24343 Vector Ctor using Span (dotnet/coreclr#16733)