-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Use Unsafe.ReadUnaligned
for vector creation in SpanHelpers.Fill
#111091
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to this area: @dotnet/area-system-memory |
fe6f0ed
to
1eb387c
Compare
1eb387c
to
7ec2876
Compare
7ec2876
to
93e46f0
Compare
src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs
Outdated
Show resolved
Hide resolved
This reverts commit 93e46f0.
Unsafe.BitCast
to avoid taking addressUnsafe.BitCast
in SpanHelprs.Fill
Unsafe.BitCast
in SpanHelprs.Fill
Unsafe.BitCast
in SpanHelpers.Fill
Unsafe.BitCast
in SpanHelpers.Fill
SpanHelpers.Fill
SpanHelpers.Fill
Unsafe.ReadUnaligned
for vector creation in SpanHelpers.Fill
@@ -34,29 +34,29 @@ public static unsafe void Fill<T>(ref T refData, nuint numElements, T value) | |||
|
|||
if (sizeof(T) == 1) | |||
{ | |||
vector = new Vector<byte>(Unsafe.As<T, byte>(ref tmp)); | |||
vector = Vector.Create(Unsafe.As<T, byte>(ref tmp)); |
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.
these should rather use Vector.LoadUnsafe(ref tmp).AsByte()
or similar.
We should be explicit that its a load API and not do extra or other things that the JIT has to elide or reason about
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.
Ah nevermind, I see the issue here. This is doing a broadcast and is reinterpreting the ref to a supported T
This pattern in general is not great and something that we probably should have a centralized helper or some other API around...
We should use
Unsafe.ReadUnaligned
instead ofUnsafe.As<T, ushort>(ref tmp)
as the alignment of a typeT
may be less than its size.Zero code generation diffs.