-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Implement most SIMD intrinsics in const-eval #146568
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred to the platform-builtins intrinsics. Make sure the cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to the CTFE machinery Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
r? @davidtwco rustbot has assigned @davidtwco. Use |
|
} | ||
|
||
fn main() { | ||
const X2: i32x2 = i32x2::from_array([20, 21]); |
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.
please add checks for length 3 and 6 since portable-simd wants to support non-powers-of-2. length 3 since it's odd and length 6 because it's the smallest where the simd type's alignment is not equal to either the simd type's size or to the element's size.
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.
Should I also add these to the tests/ui/simd
file, I just copied the test cases from there?
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.
sure if you like. I mostly just figured while you're writing the code is a good time to add it to the code you're changing. I'll leave it up to the const-eval people to decide if they want it everywhere. shuffles do get a bunch of testing in portable-simd for miri (and normal compilation), but we don't explicitly test const-eval shuffles in portable-simd because they didn't exist yet.
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.
Miri and const-eval will use the same implementation so in principle it is covered.
Instead of duplicating tests we usually prefer making the existing tests run both inside and outside consts. We have some infrastructure for that in the std test suite -- is there a reason this has to be a ui test?
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.
Idts, this should be in coretests, but the tests for simd_insert
and simd_extract
was in this directory so I just put these there. I will port these to coretests
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.
Yeah many old tests haven't been moved to the proper place yet, which would be library/coretests/tests/floats/mod.rs
. But we shouldn't be adding new such tests if possible.
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.
I have moved all the tests to coretests, and enabled const-eval tests for them
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.
If you plan to add more SIMD intrinsics, then please start putting them in a new file (intrinsics/simd.rs
) to avoid this file growing too big. (You can make this part a separate follow-up PR if you prefer.)
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.
In that case, as all intrinsics are already implemented in miri, can we just port all of them to const_eval? Is there a reason most SIMD intrinsic implementations are in miri but not in const_eval, afaiu they use the same ctfe machinery
Edit: or at least the ones that don't use floats
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.
Yeah we could port them all. They are only in Miri because so far we didn't attempt to support them in const.
Floats are allowed in consts so even those can be moved over. However, sin/cos/... should not be available in const.
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.
I also noticed that the FMA implementation has a nondeterministic component, what should I do when porting it? const-eval shouldn't have any nondeterminism, but in that case what implementation should we use - a * b + c
or a.mul_add(b, c)
?
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.
I think we should leave anything that has any questions about it for future PRs. indeed I am not certain that what Ralf said was meant to suggest increasing the scope of this PR.
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 were fairly trivial to port, so I guess I will limit this PR to these, the few remaining ones can be done 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.
Yeah let's hold off on the FMA one for now.
Which PR is that? Always good to cross-reference things. :) Or if the PR doesn't exist yet, what are your stdarch plans that need this? |
I want to make some stdarch functions available on const-contexts (for now, we are doing mostly constructors, but the |
I think we discussed creating a |
Also I know I mentioned it but please do not get into introducing such a new intrinsic here (a new PR, maybe!), as there are other good reasons to make this const so that we don't have to haggle over the many possible reasons (it is a truth universally acknowledged that |
Anyways, that aside, I'm basically good with this so it's mostly going to be haggling with Ralf, so r? RalfJung |
…ation to rustc_const_eval) Remaining: Math functions (`fsqrt`, `fsin`, `fcos`, `fexp`, `fexp2`, `flog`, `flog2`, `flog10`), Funnel Shifts, `dyn` extract-inserts and FMA
8c569d6
to
ac970b6
Compare
The Miri subtree was changed cc @rust-lang/miri |
simd_shuffle
in const_evalpub const fn from_array(a: [T; N]) -> Self { | ||
Simd(a) | ||
} | ||
|
||
pub const fn splat(value: T) -> Self | ||
where | ||
T: Copy, | ||
{ | ||
Self([value; N]) | ||
} |
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.
you need to use mem::transmute
instead of accessing the field inside a repr(simd)
struct, since last I knew the compiler doesn't properly handle the field accesses in all cases
pub const fn from_array(a: [T; N]) -> Self { | |
Simd(a) | |
} | |
pub const fn splat(value: T) -> Self | |
where | |
T: Copy, | |
{ | |
Self([value; N]) | |
} | |
pub const fn from_array(a: [T; N]) -> Self { | |
// Safety: same shape | |
unsafe { mem::transmute(a) } | |
} | |
pub const fn splat(value: T) -> Self | |
where | |
T: Copy, | |
{ | |
// Safety: same shape | |
unsafe { mem::transmute([value; N]) } | |
} |
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.
afaik constructing them is fine, projecting is the problematic part
This comment has been minimized.
This comment has been minimized.
bd2544a
to
85efca6
Compare
85efca6
to
de2aa11
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
Ported the implementation of most SIMD intrinsics from Miri to rustc_const_eval. Remaining are