Skip to content

Commit

Permalink
Rename LANES to N.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vu0r committed Dec 5, 2023
1 parent 53b92ff commit 2cc1562
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 197 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ Lane-Associated Vector (LAV): [Portable SIMD] vector trait as GAT of SIMD lane t
# Features

* SIMD lane trait [`Real`] abstracting over [`f32`] and [`f64`].
* SIMD vector trait [`SimdReal<Real, LANES>`] abstracting over [`Simd<f32, LANES>`] and
[`Simd<f64, LANES>`].
* Generic associated type (GAT) [`Real::Simd<LANES>`] as part of SIMD lane trait [`Real`]
implementing SIMD vector trait [`SimdReal<Self, LANES>`] for itself as lane type where the
GAT is generic over the number of SIMD vector `LANES`.
* SIMD vector trait [`SimdReal<Real, N>`] abstracting over `Simd<f32, N>` and `Simd<f64, N>`.
* Generic associated type (GAT) [`Real::Simd<N>`] as part of SIMD lane trait [`Real`]
implementing SIMD vector trait [`SimdReal<Self, N>`] for itself as lane type where the
GAT is generic over the number of SIMD vector lanes `N`.
* Lanewise approximate equality test wrt to epsilon and [ULP] SIMD vectors.
* [`ApproxEq`] trait complementing [`PartialEq`].
* [`no_std`] without loss of functionality by enabling the [`libm`] feature.
Expand All @@ -35,14 +34,12 @@ This [`example`] uses SIMD generically over floating-point types while hiding it
See the [release history] to keep track of the development.

[Portable SIMD]: https://doc.rust-lang.org/nightly/core/simd/index.html
[`Real`]: https://docs.rs/lav/latest/lav/trait.Real.html
[`f32`]: https://doc.rust-lang.org/nightly/core/primitive.f32.html
[`f64`]: https://doc.rust-lang.org/nightly/core/primitive.f64.html
[`Real`]: https://docs.rs/lav/latest/lav/trait.Real.html
[`SimdReal<Real, LANES>`]: https://docs.rs/lav/latest/lav/trait.SimdReal.html
[`SimdReal<Self, LANES>`]: https://docs.rs/lav/latest/lav/trait.SimdReal.html
[`Simd<f32, LANES>`]: https://doc.rust-lang.org/nightly/core/simd/struct.Simd.html#impl-10
[`Simd<f64, LANES>`]: https://doc.rust-lang.org/nightly/core/simd/struct.Simd.html#impl-11
[`Real::Simd<LANES>`]: https://docs.rs/lav/latest/lav/trait.Real.html#associatedtype.Simd
[`SimdReal<Real, N>`]: https://docs.rs/lav/latest/lav/trait.SimdReal.html
[`SimdReal<Self, N>`]: https://docs.rs/lav/latest/lav/trait.SimdReal.html
[`Real::Simd<N>`]: https://docs.rs/lav/latest/lav/trait.Real.html#associatedtype.Simd
[ULP]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
[`ApproxEq`]: https://docs.rs/lav/latest/lav/trait.ApproxEq.html
[`PartialEq`]: https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html
Expand Down
8 changes: 4 additions & 4 deletions src/bits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ where
Self: SimdElement,
{
/// Associated vector.
type Simd<const LANES: usize>: SimdBits<Self, LANES>
type Simd<const N: usize>: SimdBits<Self, N>
where
LaneCount<LANES>: SupportedLaneCount;
LaneCount<N>: SupportedLaneCount;

/// The smallest value that can be represented by this integer type.
const MIN: Self;
Expand Down Expand Up @@ -84,9 +84,9 @@ where
/// Constructs a SIMD vector by setting all lanes to the given value.
#[must_use]
#[inline]
fn splat<const LANES: usize>(self) -> Self::Simd<LANES>
fn splat<const N: usize>(self) -> Self::Simd<N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
Self::Simd::splat(self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/bits/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use super::Bits;
use core::simd::{LaneCount, Simd, SupportedLaneCount};

impl Bits for u32 {
type Simd<const LANES: usize> = Simd<Self, LANES>
type Simd<const N: usize> = Simd<Self, N>
where
LaneCount<LANES>: SupportedLaneCount;
LaneCount<N>: SupportedLaneCount;

const MIN: Self = Self::MIN;
const MAX: Self = Self::MAX;
Expand Down
4 changes: 2 additions & 2 deletions src/bits/u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use super::Bits;
use core::simd::{LaneCount, Simd, SupportedLaneCount};

impl Bits for u64 {
type Simd<const LANES: usize> = Simd<Self, LANES>
type Simd<const N: usize> = Simd<Self, N>
where
LaneCount<LANES>: SupportedLaneCount;
LaneCount<N>: SupportedLaneCount;

const MIN: Self = Self::MIN;
const MAX: Self = Self::MAX;
Expand Down
8 changes: 4 additions & 4 deletions src/example/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! }
//! pub fn from_xyzw(xyzw: [R; 4]) -> Self {
//! Self {
//! wxyz: R::Simd::from_array(xyzw).rotate_lanes_right::<1>(),
//! wxyz: R::Simd::from_array(xyzw).simd_rotate_right::<1>(),
//! }
//! }
//! pub fn norm(&self) -> R {
Expand Down Expand Up @@ -62,7 +62,7 @@
//! self.wxyz.to_array()
//! }
//! pub fn to_xyzw(self) -> [R; 4] {
//! self.wxyz.rotate_lanes_left::<1>().to_array()
//! self.wxyz.simd_rotate_left::<1>().to_array()
//! }
//! pub fn w(&self) -> R {
//! self.wxyz[0]
Expand Down Expand Up @@ -251,7 +251,7 @@
//! }
//! pub fn from_XYZw(XYZw: [R; 4]) -> Self {
//! Self {
//! wXYZ: R::Simd::from_array(XYZw).rotate_lanes_right::<1>(),
//! wXYZ: R::Simd::from_array(XYZw).simd_rotate_right::<1>(),
//! }
//! }
//! pub fn norm(&self) -> R {
Expand All @@ -274,7 +274,7 @@
//! self.wXYZ.to_array()
//! }
//! pub fn to_XYZw(self) -> [R; 4] {
//! self.wXYZ.rotate_lanes_left::<1>().to_array()
//! self.wXYZ.simd_rotate_left::<1>().to_array()
//! }
//! pub fn w(&self) -> R {
//! self.wXYZ[0]
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
//! # Features
//!
//! * SIMD lane trait [`Real`] abstracting over [`f32`] and [`f64`].
//! * SIMD vector trait [`SimdReal<Real, LANES>`] abstracting over [`Simd<f32, LANES>`] and
//! [`Simd<f64, LANES>`].
//! * Generic associated type (GAT) [`Real::Simd<LANES>`] as part of SIMD lane trait [`Real`]
//! implementing SIMD vector trait [`SimdReal<Self, LANES>`] for itself as lane type where the
//! GAT is generic over the number of SIMD vector `LANES`.
//! * SIMD vector trait [`SimdReal<Real, N>`] abstracting over [`Simd<f32, N>`] and
//! [`Simd<f64, N>`].
//! * Generic associated type (GAT) [`Real::Simd<N>`] as part of SIMD lane trait [`Real`]
//! implementing SIMD vector trait [`SimdReal<Self, N>`] for itself as lane type where the
//! GAT is generic over the number of SIMD vector lanes `N`.
//! * Lanewise approximate equality test wrt to epsilon and [ULP] SIMD vectors.
//! * [`ApproxEq`] trait complementing [`PartialEq`].
//! * [`no_std`] without loss of functionality by enabling the [`libm`] feature.
//!
//! This [`example`] uses SIMD generically over floating-point types while hiding it from the user.
//!
//! [Portable SIMD]: `core::simd`
//! [`Simd<f32, LANES>`]: `core::simd::Simd`
//! [`Simd<f64, LANES>`]: `core::simd::Simd`
//! [`Real::Simd<LANES>`]: `Real::Simd`
//! [`Simd<f32, N>`]: `core::simd::Simd`
//! [`Simd<f64, N>`]: `core::simd::Simd`
//! [`Real::Simd<N>`]: `Real::Simd`
//! [`libm`]: https://docs.rs/libm
//! [`no_std`]: https://docs.rust-embedded.org/book/intro/no-std.html
//! [ULP]: https://en.wikipedia.org/wiki/Unit_in_the_last_place
Expand Down Expand Up @@ -57,13 +57,13 @@ pub use simd_real::*;
pub mod example;

/// Selects lanes from two vectors by mask vector.
pub trait Select<M> {
pub trait Select<Mask> {
/// Selects lanes from two vectors by mask vector.
///
/// For each lane in the mask, choose the corresponding lane from `true_values` if that lane
/// mask is true, and `false_values` if that lane mask is false.
#[must_use]
fn select(mask: M, true_values: Self, false_values: Self) -> Self;
fn select(mask: Mask, true_values: Self, false_values: Self) -> Self;
}

/// Tests for approximate equality.
Expand Down
4 changes: 2 additions & 2 deletions src/real/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use target_features::CURRENT_TARGET;

impl Real for f32 {
type Bits = u32;
type Simd<const LANES: usize> = Simd<Self, LANES>
type Simd<const N: usize> = Simd<Self, N>
where
LaneCount<LANES>: SupportedLaneCount;
LaneCount<N>: SupportedLaneCount;

#[cfg(feature = "target-features")]
const NATIVE_LANE_COUNT: usize = match CURRENT_TARGET.suggested_simd_width::<Self>() {
Expand Down
4 changes: 2 additions & 2 deletions src/real/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use target_features::CURRENT_TARGET;

impl Real for f64 {
type Bits = u64;
type Simd<const LANES: usize> = Simd<Self, LANES>
type Simd<const N: usize> = Simd<Self, N>
where
LaneCount<LANES>: SupportedLaneCount;
LaneCount<N>: SupportedLaneCount;

#[cfg(feature = "target-features")]
const NATIVE_LANE_COUNT: usize = match CURRENT_TARGET.suggested_simd_width::<Self>() {
Expand Down
8 changes: 4 additions & 4 deletions src/real/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ where
/// Associated bits representation.
type Bits: Bits;
/// Associated vector.
type Simd<const LANES: usize>: SimdReal<Self, LANES>
type Simd<const N: usize>: SimdReal<Self, N>
where
LaneCount<LANES>: SupportedLaneCount;
LaneCount<N>: SupportedLaneCount;

/// Native lane count of current build target or `1` if unknown.
#[cfg(feature = "target-features")]
Expand Down Expand Up @@ -445,9 +445,9 @@ where
/// Constructs a SIMD vector by setting all lanes to the given value.
#[must_use]
#[inline]
fn splat<const LANES: usize>(self) -> Self::Simd<LANES>
fn splat<const N: usize>(self) -> Self::Simd<N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
Self::Simd::splat(self)
}
Expand Down
19 changes: 10 additions & 9 deletions src/simd_bits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ mod u64;
/// Bits representation vector of [`SimdReal`] vector with associated [`SimdMask`] vector.
///
/// [`SimdReal`]: `super::SimdReal`
pub trait SimdBits<B: Bits, const LANES: usize>
#[allow(clippy::len_without_is_empty)]
pub trait SimdBits<B: Bits, const N: usize>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
Self: Send + Sync + Clone + Copy + Default,
Self: PartialEq + Eq + PartialOrd + Ord,
Self: From<Simd<B, LANES>> + Into<Simd<B, LANES>>,
Self: From<[B; LANES]> + Into<[B; LANES]>,
Self: AsRef<[B; LANES]> + AsMut<[B; LANES]>,
Self: From<Simd<B, N>> + Into<Simd<B, N>>,
Self: From<[B; N]> + Into<[B; N]>,
Self: AsRef<[B; N]> + AsMut<[B; N]>,
Self: Product<Self> + Sum<Self>,
for<'a> Self: Product<&'a Self> + Sum<&'a Self>,
Self: Hash,
Expand Down Expand Up @@ -59,16 +60,16 @@ where
Self: Not<Output = Self>,
{
/// Associated mask vector.
type Mask: SimdMask<LANES>;
type Mask: SimdMask<N>;

/// Number of lanes in this vector.
const LANES: usize = LANES;
const N: usize = N;

/// Get the number of lanes in this vector.
#[must_use]
#[inline]
fn lanes(&self) -> usize {
LANES
fn len(&self) -> usize {
N
}

/// Constructs a SIMD vector by setting all lanes to the given value.
Expand Down
12 changes: 6 additions & 6 deletions src/simd_bits/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use core::simd::{
LaneCount, Mask, Simd, SupportedLaneCount,
};

impl<const LANES: usize> SimdBits<u32, LANES> for Simd<u32, LANES>
impl<const N: usize> SimdBits<u32, N> for Simd<u32, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
type Mask = Mask<i32, LANES>;
type Mask = Mask<i32, N>;

#[inline]
fn splat(value: u32) -> Self {
Expand Down Expand Up @@ -57,12 +57,12 @@ where
}
}

impl<const LANES: usize> Select<Mask<i32, LANES>> for Simd<u32, LANES>
impl<const N: usize> Select<Mask<i32, N>> for Simd<u32, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
#[inline]
fn select(mask: Mask<i32, LANES>, true_values: Self, false_values: Self) -> Self {
fn select(mask: Mask<i32, N>, true_values: Self, false_values: Self) -> Self {
mask.select(true_values, false_values)
}
}
12 changes: 6 additions & 6 deletions src/simd_bits/u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use core::simd::{
LaneCount, Mask, Simd, SupportedLaneCount,
};

impl<const LANES: usize> SimdBits<u64, LANES> for Simd<u64, LANES>
impl<const N: usize> SimdBits<u64, N> for Simd<u64, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
type Mask = Mask<i64, LANES>;
type Mask = Mask<i64, N>;

#[inline]
fn splat(value: u64) -> Self {
Expand Down Expand Up @@ -57,12 +57,12 @@ where
}
}

impl<const LANES: usize> Select<Mask<i64, LANES>> for Simd<u64, LANES>
impl<const N: usize> Select<Mask<i64, N>> for Simd<u64, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
#[inline]
fn select(mask: Mask<i64, LANES>, true_values: Self, false_values: Self) -> Self {
fn select(mask: Mask<i64, N>, true_values: Self, false_values: Self) -> Self {
mask.select(true_values, false_values)
}
}
12 changes: 6 additions & 6 deletions src/simd_mask/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
use super::{Select, SimdMask};
use core::simd::{LaneCount, Mask, SupportedLaneCount};

impl<const LANES: usize> SimdMask<LANES> for Mask<i32, LANES>
impl<const N: usize> SimdMask<N> for Mask<i32, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
#[inline]
fn splat(value: bool) -> Self {
Self::splat(value)
}

#[inline]
fn from_array(array: [bool; LANES]) -> Self {
fn from_array(array: [bool; N]) -> Self {
Self::from(array)
}
#[inline]
fn to_array(self) -> [bool; LANES] {
fn to_array(self) -> [bool; N] {
self.to_array()
}

Expand All @@ -44,9 +44,9 @@ where
}
}

impl<const LANES: usize> Select<Self> for Mask<i32, LANES>
impl<const N: usize> Select<Self> for Mask<i32, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
#[inline]
fn select(mask: Self, true_values: Self, false_values: Self) -> Self {
Expand Down
12 changes: 6 additions & 6 deletions src/simd_mask/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
use super::{Select, SimdMask};
use core::simd::{LaneCount, Mask, SupportedLaneCount};

impl<const LANES: usize> SimdMask<LANES> for Mask<i64, LANES>
impl<const N: usize> SimdMask<N> for Mask<i64, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
#[inline]
fn splat(value: bool) -> Self {
Self::splat(value)
}

#[inline]
fn from_array(array: [bool; LANES]) -> Self {
fn from_array(array: [bool; N]) -> Self {
Self::from(array)
}
#[inline]
fn to_array(self) -> [bool; LANES] {
fn to_array(self) -> [bool; N] {
self.to_array()
}

Expand All @@ -44,9 +44,9 @@ where
}
}

impl<const LANES: usize> Select<Self> for Mask<i64, LANES>
impl<const N: usize> Select<Self> for Mask<i64, N>
where
LaneCount<LANES>: SupportedLaneCount,
LaneCount<N>: SupportedLaneCount,
{
#[inline]
fn select(mask: Self, true_values: Self, false_values: Self) -> Self {
Expand Down
Loading

0 comments on commit 2cc1562

Please sign in to comment.