-
Notifications
You must be signed in to change notification settings - Fork 280
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
Implement vec_perm #451
Implement vec_perm #451
Changes from 10 commits
31decb8
bdc6537
6d25f83
5b981b2
15beb5b
fb54b14
c9731aa
59f31b5
07d0cee
b5cf336
ae2ef1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,12 @@ | |
|
||
use coresimd::powerpc::*; | ||
use coresimd::simd::*; | ||
use coresimd::simd_llvm::*; | ||
|
||
#[cfg(test)] | ||
use stdsimd_test::assert_instr; | ||
|
||
use mem; | ||
|
||
types! { | ||
// pub struct vector_Float16 = f16x8; | ||
|
@@ -216,3 +222,77 @@ impl_from_bits_!( | |
vector_bool_long, | ||
vector_double | ||
); | ||
|
||
mod sealed { | ||
|
||
use super::*; | ||
|
||
pub trait VectorPermDI { | ||
unsafe fn vec_xxpermdi(self, b: Self, dm: u8) -> Self; | ||
} | ||
|
||
// xxpermdi has an big-endian bias and extended mnemonics | ||
#[inline] | ||
#[target_feature(enable = "vsx")] | ||
#[cfg_attr(all(test, target_endian="little"), assert_instr(xxmrgld, dm = 0x0))] | ||
#[cfg_attr(all(test, target_endian="big"), assert_instr(xxspltd, dm = 0x0))] | ||
unsafe fn xxpermdi(a: i64x2, b: i64x2, dm: u8) -> i64x2 { | ||
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. I think this is missing a 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. That won't work with the trait approach :/ 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. Maybe make this function and the trait method impls 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. The function exists mainly for the instruction test. The const-argument is enforced on the only part that the user sees. Probably |
||
match dm & 0b11 { | ||
0 => simd_shuffle2(a, b, [0b00, 0b10]), | ||
1 => simd_shuffle2(a, b, [0b01, 0b10]), | ||
2 => simd_shuffle2(a, b, [0b00, 0b11]), | ||
_ => simd_shuffle2(a, b, [0b01, 0b11]), | ||
} | ||
} | ||
|
||
macro_rules! vec_xxpermdi { | ||
{$impl: ident} => { | ||
impl VectorPermDI for $impl { | ||
#[inline] | ||
#[target_feature(enable = "vsx")] | ||
unsafe fn vec_xxpermdi(self, b: Self, dm: u8) -> Self { | ||
mem::transmute(xxpermdi(mem::transmute(self), mem::transmute(b), dm)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
vec_xxpermdi! { vector_unsigned_long } | ||
vec_xxpermdi! { vector_signed_long } | ||
vec_xxpermdi! { vector_bool_long } | ||
vec_xxpermdi! { vector_double } | ||
} | ||
|
||
/// Vector permute. | ||
#[inline] | ||
#[target_feature(enable = "vsx")] | ||
#[rustc_args_required_const(2)] | ||
pub unsafe fn vec_xxpermdi<T>(a: T, b: T, dm: u8) -> T | ||
where | ||
T: sealed::VectorPermDI, | ||
{ | ||
a.vec_xxpermdi(b, dm) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[cfg(target_arch = "powerpc")] | ||
use coresimd::arch::powerpc::*; | ||
|
||
#[cfg(target_arch = "powerpc64")] | ||
use coresimd::arch::powerpc64::*; | ||
|
||
use simd::*; | ||
use stdsimd_test::simd_test; | ||
|
||
#[simd_test(enable = "vsx")] | ||
unsafe fn vec_xxpermdi_u62x2() { | ||
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. Also missing tests for the other vector types. 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. As per vec_perm, it it would test how good 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. Here the tests for other vector types are still missing, otherwise the rest of the PR LGTM and can be merged. |
||
let a: vector_unsigned_long = u64x2::new(0, 1).into_bits(); | ||
let b = u64x2::new(2, 3).into_bits(); | ||
|
||
assert_eq!(u64x2::new(0, 2), vec_xxpermdi(a, b, 0).into_bits()); | ||
assert_eq!(u64x2::new(1, 2), vec_xxpermdi(a, b, 1).into_bits()); | ||
assert_eq!(u64x2::new(0, 3), vec_xxpermdi(a, b, 2).into_bits()); | ||
assert_eq!(u64x2::new(1, 3), vec_xxpermdi(a, b, 3).into_bits()); | ||
} | ||
} |
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 add
assert_instr
tests for all vector types.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.
That function is the only one that is called for every vector type.
All the vector types are transmuted to i32x4.