Skip to content

Replace Unsafe.As with Unsafe.BitCast in SpanHelpers.Fill #116221

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

Merged
merged 3 commits into from
Jun 3, 2025

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Jun 2, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 16:46
Copy link
Contributor

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

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces all uses of Unsafe.As with Unsafe.BitCast in SpanHelpers.Fill<T> to streamline vector creation and improve performance.

  • Removed the temporary tmp variable and switched to Unsafe.BitCast<T, U>(value) for all supported element sizes.
  • Updated special-case branches for float and double to use BitCast.
  • Simplified vector creation for 128-bit, 256-bit, and 512-bit cases by bit-casting value directly.
Comments suppressed due to low confidence (1)

src/libraries/System.Private.CoreLib/src/System/SpanHelpers.T.cs:36

  • Consider adding unit tests for Fill<T> covering each branch of Unsafe.BitCast for different T sizes to ensure the fill behavior remains correct across all cases.
vector = new Vector<byte>(Unsafe.BitCast<T, byte>(value));

@jkotas
Copy link
Member Author

jkotas commented Jun 2, 2025

Context #111091 (comment)

@jkotas jkotas requested review from tannergooding and EgorBo June 2, 2025 16:47
@jkotas jkotas requested a review from MihaZupan June 3, 2025 15:36
@jkotas
Copy link
Member Author

jkotas commented Jun 3, 2025

/ba-g timeouts, deadletter

@jkotas jkotas merged commit 8091e60 into dotnet:main Jun 3, 2025
137 of 142 checks passed
@jkotas jkotas deleted the fill-bitcast branch June 3, 2025 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants