-
Notifications
You must be signed in to change notification settings - Fork 270
Translate builtin_assume
and unaligned SIMD intrinsics
#1132
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
Open
thedataking
wants to merge
1
commit into
master
Choose a base branch
from
perl/builtin_assume
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,9 @@ impl<'c> Translation<'c> { | |
pub fn import_simd_typedef(&self, name: &str) -> TranslationResult<bool> { | ||
Ok(match name { | ||
// Public API SIMD typedefs: | ||
"__m128i" | "__m128" | "__m128d" | "__m64" | "__m256" | "__m256d" | "__m256i" => { | ||
"__m64" | "__m128i" | "__m128i_u" | "__m128" | "__m128d" | "__m128_u" | "__m256" | ||
| "__m256d" | "__m256_u" | "__m256i" | "__m256i_u" | "__m512 " | "__m512d" | ||
| "__m512i" | "__m512i_u" | "__m512_u" => { | ||
// __m64 and MMX support were removed from upstream Rust. | ||
// See https://github.com/immunant/c2rust/issues/369 | ||
if name == "__m64" { | ||
|
@@ -100,6 +102,21 @@ impl<'c> Translation<'c> { | |
).into()); | ||
} | ||
|
||
// Drop the `_u` suffix for unaligned SIMD types as they have | ||
// no equivalents in Rust. Warn the user about possible probems. | ||
Comment on lines
+105
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use this for unaligned SIMD types? use core::arch::x86_64::__m256;
use core::mem;
#[unsafe(no_mangle)]
pub fn aligned() -> usize {
mem::align_of::<__m256>()
}
#[repr(packed)]
pub struct UnalignedM256(pub __m256);
#[unsafe(no_mangle)]
pub fn unaligned() -> usize {
mem::align_of::<UnalignedM256>()
}
|
||
let name = if name.ends_with("_u") { | ||
warn!( | ||
"Unaligned SIMD type {} has no equivalent in Rust. \ | ||
Emitting {} instead. This likely means the potential \ | ||
for miscompilation has been introduced.", | ||
name, | ||
&name[..name.len() - 2] | ||
); | ||
&name[..name.len() - 2] | ||
} else { | ||
name | ||
}; | ||
|
||
self.with_cur_file_item_store(|item_store| { | ||
add_arch_use(item_store, "x86", name); | ||
add_arch_use(item_store, "x86_64", name); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When you do implement this, note that Rust (as of 1.81.0) now has
core::hint::assert_unchecked
, which should be the equivalent of__builtin_assume
.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.
@kkysen do you want to add support for
__builtin_assume
into a separate PR with a test?It seems my PR is trying to do two things and only one is blocked on what rust provides, so that's messy.
WDYT about landing the rest of this PR? Should the warning reference the PR folkert opened?
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.
We're still stuck on the old nightly, so adding support for newer features like this is tricky. That said, we could merge #1227, which would use
stable
forc2rust-transpile
and let us start targeting newer Rust versions for just the transpiler. #1227 didn't work before, but now that CI is on GitHub Actions, it works without much modifications, so it wouldn't be too much work to review and merge that. If we do that, I can add support for it.