Skip to content

Commit

Permalink
Fixup import pathing for core
Browse files Browse the repository at this point in the history
This changes simd_swizzle! to a decl_macro to give it a path,
so it can be imported using a path and not the crate root.
It also adds various uses that were missed, adjusts paths,
and exposes some details to make it easier to pass CI.
  • Loading branch information
workingjubilee committed Oct 21, 2021
1 parent 5b4282e commit cc78a1c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
4 changes: 2 additions & 2 deletions crates/core_simd/examples/matrix_inversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Code ported from the `packed_simd` crate
// Run this code with `cargo test --example matrix_inversion`
#![feature(array_chunks, portable_simd)]
use core_simd::Which::*;
use core_simd::*;
use core_simd::simd::*;
use Which::*;

// Gotta define our own 4x4 matrix since Rust doesn't ship multidim arrays yet :^)
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
Expand Down
2 changes: 1 addition & 1 deletion crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(
const_fn_trait_bound,
const_panic,
decl_macro,
platform_intrinsics,
repr_simd,
simd_ffi,
Expand Down
12 changes: 8 additions & 4 deletions crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ use core::fmt;

/// Marker trait for types that may be used as SIMD mask elements.
pub unsafe trait MaskElement: SimdElement {
#[doc(hidden)]
/// This is supposed to be a hidden helper function. Before stabilizing
/// this trait, it should be erased from public access.
fn valid<const LANES: usize>(values: Simd<Self, LANES>) -> bool
where
LaneCount<LANES>: SupportedLaneCount;

#[doc(hidden)]
/// This is supposed to be a hidden helper function. Before stabilizing
/// this trait, it should be erased from public access.
fn eq(self, other: Self) -> bool;

#[doc(hidden)]
/// This is supposed to be a hidden helper const. Before stabilizing
/// this trait, it should be erased from public access.
const TRUE: Self;

#[doc(hidden)]
/// This is supposed to be a hidden helper const. Before stabilizing
/// this trait, it should be erased from public access.
const FALSE: Self;
}

Expand Down
8 changes: 6 additions & 2 deletions crates/core_simd/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use sealed::Sealed;

/// Supporting trait for vector `select` function
pub trait Select<Mask>: Sealed {
#[doc(hidden)]
/// This is supposed to be a hidden helper function. Before stabilizing
/// this trait, it should be erased from public access.
fn select(mask: Mask, true_values: Self, false_values: Self) -> Self;
}

Expand All @@ -24,6 +25,8 @@ where
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
{
/// This is supposed to be a hidden helper function. Before stabilizing
/// this trait, it should be erased from public access.
#[inline]
fn select(mask: Mask<T::Mask, LANES>, true_values: Self, false_values: Self) -> Self {
unsafe { intrinsics::simd_select(mask.to_int(), true_values, false_values) }
Expand All @@ -42,7 +45,8 @@ where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[doc(hidden)]
/// This is supposed to be a hidden helper function. Before stabilizing
/// this trait, it should be erased from public access.
#[inline]
fn select(mask: Self, true_values: Self, false_values: Self) -> Self {
mask & true_values | !mask & false_values
Expand Down
28 changes: 16 additions & 12 deletions crates/core_simd/src/swizzle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::simd::intrinsics;
use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};

/// Constructs a new vector by selecting values from the lanes of the source vector or vectors to use.
///
Expand All @@ -12,7 +12,8 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
/// ## One source vector
/// ```
/// # #![feature(portable_simd)]
/// # use core_simd::{Simd, simd_swizzle};
/// # #[cfg(feature = "std")] use core_simd::{Simd, simd_swizzle};
/// # #[cfg(not(feature = "std"))] use core::simd::{Simd, simd_swizzle};
/// let v = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
///
/// // Keeping the same size
Expand All @@ -27,7 +28,8 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
/// ## Two source vectors
/// ```
/// # #![feature(portable_simd)]
/// # use core_simd::{Simd, simd_swizzle, Which};
/// # #[cfg(feature = "std")] use core_simd::{Simd, simd_swizzle, Which};
/// # #[cfg(not(feature = "std"))] use core::simd::{Simd, simd_swizzle, Which};
/// use Which::*;
/// let a = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
/// let b = Simd::<f32, 4>::from_array([4., 5., 6., 7.]);
Expand All @@ -40,11 +42,11 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
/// let r = simd_swizzle!(a, b, [First(0), Second(0)]);
/// assert_eq!(r.to_array(), [0., 4.]);
/// ```
#[macro_export]
macro_rules! simd_swizzle {
{
#[allow(unused_macros)]
pub macro simd_swizzle {
(
$vector:expr, $index:expr $(,)?
} => {
) => {
{
use $crate::simd::Swizzle;
struct Impl;
Expand All @@ -53,10 +55,10 @@ macro_rules! simd_swizzle {
}
Impl::swizzle($vector)
}
};
{
},
(
$first:expr, $second:expr, $index:expr $(,)?
} => {
) => {
{
use $crate::simd::{Which, Swizzle2};
struct Impl;
Expand Down Expand Up @@ -262,7 +264,8 @@ where
///
/// ```
/// #![feature(portable_simd)]
/// # use core_simd::Simd;
/// # #[cfg(feature = "std")] use core_simd::Simd;
/// # #[cfg(not(feature = "std"))] use core::simd::Simd;
/// let a = Simd::from_array([0, 1, 2, 3]);
/// let b = Simd::from_array([4, 5, 6, 7]);
/// let (x, y) = a.interleave(b);
Expand Down Expand Up @@ -324,7 +327,8 @@ where
///
/// ```
/// #![feature(portable_simd)]
/// # use core_simd::Simd;
/// # #[cfg(feature = "std")] use core_simd::Simd;
/// # #[cfg(not(feature = "std"))] use core::simd::Simd;
/// let a = Simd::from_array([0, 4, 1, 5]);
/// let b = Simd::from_array([2, 6, 3, 7]);
/// let (x, y) = a.deinterleave(b);
Expand Down

0 comments on commit cc78a1c

Please sign in to comment.