Skip to content

Commit cc78a1c

Browse files
Fixup import pathing for core
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.
1 parent 5b4282e commit cc78a1c

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

crates/core_simd/examples/matrix_inversion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Code ported from the `packed_simd` crate
33
// Run this code with `cargo test --example matrix_inversion`
44
#![feature(array_chunks, portable_simd)]
5-
use core_simd::Which::*;
6-
use core_simd::*;
5+
use core_simd::simd::*;
6+
use Which::*;
77

88
// Gotta define our own 4x4 matrix since Rust doesn't ship multidim arrays yet :^)
99
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]

crates/core_simd/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22
#![feature(
33
const_fn_trait_bound,
4-
const_panic,
4+
decl_macro,
55
platform_intrinsics,
66
repr_simd,
77
simd_ffi,

crates/core_simd/src/masks.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ use core::fmt;
1818

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

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

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

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

crates/core_simd/src/select.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use sealed::Sealed;
88

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

@@ -24,6 +25,8 @@ where
2425
T: SimdElement,
2526
LaneCount<LANES>: SupportedLaneCount,
2627
{
28+
/// This is supposed to be a hidden helper function. Before stabilizing
29+
/// this trait, it should be erased from public access.
2730
#[inline]
2831
fn select(mask: Mask<T::Mask, LANES>, true_values: Self, false_values: Self) -> Self {
2932
unsafe { intrinsics::simd_select(mask.to_int(), true_values, false_values) }
@@ -42,7 +45,8 @@ where
4245
T: MaskElement,
4346
LaneCount<LANES>: SupportedLaneCount,
4447
{
45-
#[doc(hidden)]
48+
/// This is supposed to be a hidden helper function. Before stabilizing
49+
/// this trait, it should be erased from public access.
4650
#[inline]
4751
fn select(mask: Self, true_values: Self, false_values: Self) -> Self {
4852
mask & true_values | !mask & false_values

crates/core_simd/src/swizzle.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::simd::intrinsics;
2-
use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
2+
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
33

44
/// Constructs a new vector by selecting values from the lanes of the source vector or vectors to use.
55
///
@@ -12,7 +12,8 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
1212
/// ## One source vector
1313
/// ```
1414
/// # #![feature(portable_simd)]
15-
/// # use core_simd::{Simd, simd_swizzle};
15+
/// # #[cfg(feature = "std")] use core_simd::{Simd, simd_swizzle};
16+
/// # #[cfg(not(feature = "std"))] use core::simd::{Simd, simd_swizzle};
1617
/// let v = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
1718
///
1819
/// // Keeping the same size
@@ -27,7 +28,8 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
2728
/// ## Two source vectors
2829
/// ```
2930
/// # #![feature(portable_simd)]
30-
/// # use core_simd::{Simd, simd_swizzle, Which};
31+
/// # #[cfg(feature = "std")] use core_simd::{Simd, simd_swizzle, Which};
32+
/// # #[cfg(not(feature = "std"))] use core::simd::{Simd, simd_swizzle, Which};
3133
/// use Which::*;
3234
/// let a = Simd::<f32, 4>::from_array([0., 1., 2., 3.]);
3335
/// let b = Simd::<f32, 4>::from_array([4., 5., 6., 7.]);
@@ -40,11 +42,11 @@ use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
4042
/// let r = simd_swizzle!(a, b, [First(0), Second(0)]);
4143
/// assert_eq!(r.to_array(), [0., 4.]);
4244
/// ```
43-
#[macro_export]
44-
macro_rules! simd_swizzle {
45-
{
45+
#[allow(unused_macros)]
46+
pub macro simd_swizzle {
47+
(
4648
$vector:expr, $index:expr $(,)?
47-
} => {
49+
) => {
4850
{
4951
use $crate::simd::Swizzle;
5052
struct Impl;
@@ -53,10 +55,10 @@ macro_rules! simd_swizzle {
5355
}
5456
Impl::swizzle($vector)
5557
}
56-
};
57-
{
58+
},
59+
(
5860
$first:expr, $second:expr, $index:expr $(,)?
59-
} => {
61+
) => {
6062
{
6163
use $crate::simd::{Which, Swizzle2};
6264
struct Impl;
@@ -262,7 +264,8 @@ where
262264
///
263265
/// ```
264266
/// #![feature(portable_simd)]
265-
/// # use core_simd::Simd;
267+
/// # #[cfg(feature = "std")] use core_simd::Simd;
268+
/// # #[cfg(not(feature = "std"))] use core::simd::Simd;
266269
/// let a = Simd::from_array([0, 1, 2, 3]);
267270
/// let b = Simd::from_array([4, 5, 6, 7]);
268271
/// let (x, y) = a.interleave(b);
@@ -324,7 +327,8 @@ where
324327
///
325328
/// ```
326329
/// #![feature(portable_simd)]
327-
/// # use core_simd::Simd;
330+
/// # #[cfg(feature = "std")] use core_simd::Simd;
331+
/// # #[cfg(not(feature = "std"))] use core::simd::Simd;
328332
/// let a = Simd::from_array([0, 4, 1, 5]);
329333
/// let b = Simd::from_array([2, 6, 3, 7]);
330334
/// let (x, y) = a.deinterleave(b);

0 commit comments

Comments
 (0)