-
Notifications
You must be signed in to change notification settings - Fork 309
Use a generic type to implement SIMD types in core_arch::simd and avoid unsafe fn in more tests
#1987
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: main
Are you sure you want to change the base?
Use a generic type to implement SIMD types in core_arch::simd and avoid unsafe fn in more tests
#1987
Conversation
|
|
||
| $(#[$stability])+ | ||
| impl crate::convert::From<crate::core_arch::simd::Simd<$elem_type, $len>> for $name { | ||
| #[inline(always)] | ||
| fn from(simd: crate::core_arch::simd::Simd<$elem_type, $len>) -> Self { | ||
| unsafe { crate::mem::transmute(simd) } | ||
| } | ||
| } | ||
|
|
||
| $(#[$stability])+ | ||
| impl crate::convert::From<$name> for crate::core_arch::simd::Simd<$elem_type, $len> { | ||
| #[inline(always)] | ||
| fn from(simd: $name) -> Self { | ||
| unsafe { crate::mem::transmute(simd) } | ||
| } | ||
| } |
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.
This is now easy to include thanks to the generic core_arch::simd::Simd type.
| // `#[derive(Clone)]` causes ICE "Projecting into SIMD type core_arch::simd::Simd is banned by MCP#838" | ||
| impl<T: SimdElement, const N: usize> Clone for Simd<T, N> { | ||
| #[inline] | ||
| fn clone(&self) -> Self { | ||
| *self | ||
| } | ||
| } |
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 don't know why the ICE with #[derive(Clone)] did not happen with non-generic types.
5c7b4fc to
3ddd60e
Compare
This allows the `types` macro to easily implement `From<Simd<T, N>>` and `Into<Simd<T, N>>`
e08cdf5 to
c6fa637
Compare
| test_vcombine!(test_vcombine_f16 => vcombine_f16([3_f16, 4., 5., 6.], | ||
| [13_f16, 14., 15., 16.])); | ||
| #[cfg_attr(target_arch = "arm", simd_test(enable = "neon,fp16"))] | ||
| #[cfg_attr(not(target_arch = "arm"), simd_test(enable = "neon"))] | ||
| fn test_vcombine_f16() { | ||
| let a = f16x4::from_array([3_f16, 4., 5., 6.]); | ||
| let b = f16x4::from_array([13_f16, 14., 15., 16.]); | ||
| let e = f16x8::from_array([3_f16, 4., 5., 6., 13_f16, 14., 15., 16.]); | ||
| let c = f16x8::from(vcombine_f16(a.into(), b.into())); | ||
| assert_eq!(c, e); | ||
| } |
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.
No longer uses the test_vcombine due to the need of specifying "fp16" depending on ARM version.
c6fa637 to
f51739a
Compare
f51739a to
ccfe133
Compare
| ;; | ||
| armv7-*eabihf | thumbv7-*eabihf) | ||
| export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+neon" | ||
| export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+neon,+fp16" |
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.
Since fp16 cannot be checked at runtime (at least is_arm_feature_detected does not support it), we enable it at compile time.
No description provided.