rotate_{left,right} -> rotate_lanes_{left,right}

This commit is contained in:
Caleb Zulawski 2021-11-06 00:34:23 +00:00
parent 772bf2090e
commit 4e00aa68c7
3 changed files with 37 additions and 37 deletions

View File

@ -180,58 +180,58 @@ pub fn simd_inv4x4(m: Matrix4x4) -> Option<Matrix4x4> {
let row2 = simd_swizzle!(tmp, row3, SHUFFLE02);
let row3 = simd_swizzle!(row3, tmp, SHUFFLE13);
let tmp = (row2 * row3).reverse().rotate_right::<2>();
let tmp = (row2 * row3).reverse().rotate_lanes_right::<2>();
let minor0 = row1 * tmp;
let minor1 = row0 * tmp;
let tmp = tmp.rotate_right::<2>();
let tmp = tmp.rotate_lanes_right::<2>();
let minor0 = (row1 * tmp) - minor0;
let minor1 = (row0 * tmp) - minor1;
let minor1 = minor1.rotate_right::<2>();
let minor1 = minor1.rotate_lanes_right::<2>();
let tmp = (row1 * row2).reverse().rotate_right::<2>();
let tmp = (row1 * row2).reverse().rotate_lanes_right::<2>();
let minor0 = (row3 * tmp) + minor0;
let minor3 = row0 * tmp;
let tmp = tmp.rotate_right::<2>();
let tmp = tmp.rotate_lanes_right::<2>();
let minor0 = minor0 - row3 * tmp;
let minor3 = row0 * tmp - minor3;
let minor3 = minor3.rotate_right::<2>();
let minor3 = minor3.rotate_lanes_right::<2>();
let tmp = (row3 * row1.rotate_right::<2>())
let tmp = (row3 * row1.rotate_lanes_right::<2>())
.reverse()
.rotate_right::<2>();
let row2 = row2.rotate_right::<2>();
.rotate_lanes_right::<2>();
let row2 = row2.rotate_lanes_right::<2>();
let minor0 = row2 * tmp + minor0;
let minor2 = row0 * tmp;
let tmp = tmp.rotate_right::<2>();
let tmp = tmp.rotate_lanes_right::<2>();
let minor0 = minor0 - row2 * tmp;
let minor2 = row0 * tmp - minor2;
let minor2 = minor2.rotate_right::<2>();
let minor2 = minor2.rotate_lanes_right::<2>();
let tmp = (row0 * row1).reverse().rotate_right::<2>();
let tmp = (row0 * row1).reverse().rotate_lanes_right::<2>();
let minor2 = minor2 + row3 * tmp;
let minor3 = row2 * tmp - minor3;
let tmp = tmp.rotate_right::<2>();
let tmp = tmp.rotate_lanes_right::<2>();
let minor2 = row3 * tmp - minor2;
let minor3 = minor3 - row2 * tmp;
let tmp = (row0 * row3).reverse().rotate_right::<2>();
let tmp = (row0 * row3).reverse().rotate_lanes_right::<2>();
let minor1 = minor1 - row2 * tmp;
let minor2 = row1 * tmp + minor2;
let tmp = tmp.rotate_right::<2>();
let tmp = tmp.rotate_lanes_right::<2>();
let minor1 = row2 * tmp + minor1;
let minor2 = minor2 - row1 * tmp;
let tmp = (row0 * row2).reverse().rotate_right::<2>();
let tmp = (row0 * row2).reverse().rotate_lanes_right::<2>();
let minor1 = row3 * tmp + minor1;
let minor3 = minor3 - row1 * tmp;
let tmp = tmp.rotate_right::<2>();
let tmp = tmp.rotate_lanes_right::<2>();
let minor1 = minor1 - row3 * tmp;
let minor3 = row1 * tmp + minor3;
let det = row0 * minor0;
let det = det.rotate_right::<2>() + det;
let det = det.reverse().rotate_right::<2>() + det;
let det = det.rotate_lanes_right::<2>() + det;
let det = det.reverse().rotate_lanes_right::<2>() + det;
if det.horizontal_sum() == 0. {
return None;

View File

@ -203,10 +203,10 @@ where
}
/// Rotates the vector such that the first `OFFSET` elements of the slice move to the end
/// while the last `LANES - OFFSET` elements move to the front. After calling `rotate_left`, the
/// element previously in lane `OFFSET` will become the first element in the slice.
/// while the last `LANES - OFFSET` elements move to the front. After calling `rotate_lanes_left`,
/// the element previously in lane `OFFSET` will become the first element in the slice.
#[inline]
pub fn rotate_left<const OFFSET: usize>(self) -> Self {
pub fn rotate_lanes_left<const OFFSET: usize>(self) -> Self {
const fn rotate_index<const OFFSET: usize, const LANES: usize>() -> [usize; LANES] {
let offset = OFFSET % LANES;
let mut index = [0; LANES];
@ -228,10 +228,10 @@ where
}
/// Rotates the vector such that the first `LANES - OFFSET` elements of the vector move to
/// the end while the last `OFFSET` elements move to the front. After calling `rotate_right`, the
/// element previously at index `LANES - OFFSET` will become the first element in the slice.
/// the end while the last `OFFSET` elements move to the front. After calling `rotate_lanes_right`,
/// the element previously at index `LANES - OFFSET` will become the first element in the slice.
#[inline]
pub fn rotate_right<const OFFSET: usize>(self) -> Self {
pub fn rotate_lanes_right<const OFFSET: usize>(self) -> Self {
const fn rotate_index<const OFFSET: usize, const LANES: usize>() -> [usize; LANES] {
let offset = LANES - OFFSET % LANES;
let mut index = [0; LANES];

View File

@ -34,18 +34,18 @@ fn reverse() {
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn rotate() {
let a = Simd::from_array([1, 2, 3, 4]);
assert_eq!(a.rotate_left::<0>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_left::<1>().to_array(), [2, 3, 4, 1]);
assert_eq!(a.rotate_left::<2>().to_array(), [3, 4, 1, 2]);
assert_eq!(a.rotate_left::<3>().to_array(), [4, 1, 2, 3]);
assert_eq!(a.rotate_left::<4>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_left::<5>().to_array(), [2, 3, 4, 1]);
assert_eq!(a.rotate_right::<0>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_right::<1>().to_array(), [4, 1, 2, 3]);
assert_eq!(a.rotate_right::<2>().to_array(), [3, 4, 1, 2]);
assert_eq!(a.rotate_right::<3>().to_array(), [2, 3, 4, 1]);
assert_eq!(a.rotate_right::<4>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_right::<5>().to_array(), [4, 1, 2, 3]);
assert_eq!(a.rotate_lanes_left::<0>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_lanes_left::<1>().to_array(), [2, 3, 4, 1]);
assert_eq!(a.rotate_lanes_left::<2>().to_array(), [3, 4, 1, 2]);
assert_eq!(a.rotate_lanes_left::<3>().to_array(), [4, 1, 2, 3]);
assert_eq!(a.rotate_lanes_left::<4>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_lanes_left::<5>().to_array(), [2, 3, 4, 1]);
assert_eq!(a.rotate_lanes_right::<0>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_lanes_right::<1>().to_array(), [4, 1, 2, 3]);
assert_eq!(a.rotate_lanes_right::<2>().to_array(), [3, 4, 1, 2]);
assert_eq!(a.rotate_lanes_right::<3>().to_array(), [2, 3, 4, 1]);
assert_eq!(a.rotate_lanes_right::<4>().to_array(), [1, 2, 3, 4]);
assert_eq!(a.rotate_lanes_right::<5>().to_array(), [4, 1, 2, 3]);
}
#[test]