Skip to content
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

[mono] Adding support for Vector128::ExtractMostSignificantBits intrinsics on amd64 #89997

Merged
merged 2 commits into from
Aug 10, 2023

Conversation

matouskozak
Copy link
Member

Adding intrinsics support for Vector128::ExtractMostSignificantBits method on amd64 (miniJIT and llvm AOT).

Implementation

Extracting the most significant bits (MSBs) from Vector128 on amd64 is based on the use of _mm_movemask_epi8/ps/pd (SSE/SSE2).

  • Support for two new opcodes for vectors added:
  1. sse_movmsk: Create mask from the most significant bit of each 8/32/64-bit element (_mm_movemask_epi8/ps/pd).
  2. ssse3_shuffle: Shuffle 8-bit elements of vector according to shuffle control mask (_mm_shuffle_epi8).

Short/UShort element types

Since the _mm_movemask_epi8/ps/pd doesn't support Short/UShort element types, we first perform _mm_shuffle_epi8 (SSSE3) to shuffle odd bytes (most significant bytes of each Short/UShort) to the lower half of vector while zeroing out the upper half. Next, we use _mm_movemask_epi8 to extract MSBs from shuffled vector.

Other primitive element types

Based on the size of element type, the corresponding version of _mm_movemask_epi8/ps/pd is used to extract MSBs.

Future work

Emitting intrinsics for Vector128 of floating-point types is currently not supported in Mono. This PR adds the support for emitting it on amd64 platform but additional work must be done for arm64 and possibly for WASM before enabling it for Mono.


Contributes to #76025.

@matouskozak matouskozak marked this pull request as ready for review August 4, 2023 13:35
Copy link
Member

@ivanpovazan ivanpovazan left a comment

Choose a reason for hiding this comment

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

LGTM!

@matouskozak
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@matouskozak
Copy link
Member Author

maccatalyst-x64 Release AllSubsets_Mono build error (https://dev.azure.com/dnceng-public/public/_build/results?buildId=363584&view=logs&j=a2a39d6b-70c5-5040-933a-4b8b6e52bf19&t=7de46cbc-684f-5a34-7a8f-d5a9c81d3460) seems releated. I'll investigate further.

Copy link
Member

@jandupej jandupej left a comment

Choose a reason for hiding this comment

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

LGTM. I cannot immediately see why LLVM would fail on the i16 case.

@matouskozak matouskozak added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 7, 2023
@matouskozak matouskozak removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 8, 2023
@matouskozak
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@matouskozak
Copy link
Member Author

LGTM

@jandupej looks like it was caused by missing SSSE3 check which is weird considering SSSE3 is more than 15 years old.

@matouskozak matouskozak requested a review from vargaz August 9, 2023 08:22
@matouskozak matouskozak merged commit f465d33 into dotnet:main Aug 10, 2023
134 of 156 checks passed
@matouskozak
Copy link
Member Author

The failing CI lines are tracked on main and unrelated to this PR.

@jandupej
Copy link
Member

LGTM

@jandupej looks like it was caused by missing SSSE3 check which is weird considering SSSE3 is more than 15 years old.

If memory serves, we require the CPU to support at least SSE4.1, so this should not be an issue. Still, it is a good practice to check for ISA extension support before using it.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants