Skip to content

Commit 3251c2c

Browse files
Restructure crate as core module
Aligns module with rust-lang/library/core, creating an... unusual architecture that is easier to pull in as a module, as core itself can have no dependencies (as we haven't built core yet).
1 parent 8cf7a62 commit 3251c2c

26 files changed

+159
-130
lines changed

crates/core_simd/src/comparisons.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{LaneCount, Mask, Simd, SimdElement, SupportedLaneCount};
1+
use crate::simd::intrinsics;
2+
use crate::simd::{LaneCount, Mask, Simd, SimdElement, SupportedLaneCount};
23

34
impl<T, const LANES: usize> Simd<T, LANES>
45
where
@@ -8,13 +9,13 @@ where
89
/// Test if each lane is equal to the corresponding lane in `other`.
910
#[inline]
1011
pub fn lanes_eq(self, other: Self) -> Mask<T::Mask, LANES> {
11-
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_eq(self, other)) }
12+
unsafe { Mask::from_int_unchecked(intrinsics::simd_eq(self, other)) }
1213
}
1314

1415
/// Test if each lane is not equal to the corresponding lane in `other`.
1516
#[inline]
1617
pub fn lanes_ne(self, other: Self) -> Mask<T::Mask, LANES> {
17-
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ne(self, other)) }
18+
unsafe { Mask::from_int_unchecked(intrinsics::simd_ne(self, other)) }
1819
}
1920
}
2021

@@ -26,24 +27,24 @@ where
2627
/// Test if each lane is less than the corresponding lane in `other`.
2728
#[inline]
2829
pub fn lanes_lt(self, other: Self) -> Mask<T::Mask, LANES> {
29-
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_lt(self, other)) }
30+
unsafe { Mask::from_int_unchecked(intrinsics::simd_lt(self, other)) }
3031
}
3132

3233
/// Test if each lane is greater than the corresponding lane in `other`.
3334
#[inline]
3435
pub fn lanes_gt(self, other: Self) -> Mask<T::Mask, LANES> {
35-
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_gt(self, other)) }
36+
unsafe { Mask::from_int_unchecked(intrinsics::simd_gt(self, other)) }
3637
}
3738

3839
/// Test if each lane is less than or equal to the corresponding lane in `other`.
3940
#[inline]
4041
pub fn lanes_le(self, other: Self) -> Mask<T::Mask, LANES> {
41-
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_le(self, other)) }
42+
unsafe { Mask::from_int_unchecked(intrinsics::simd_le(self, other)) }
4243
}
4344

4445
/// Test if each lane is greater than or equal to the corresponding lane in `other`.
4546
#[inline]
4647
pub fn lanes_ge(self, other: Self) -> Mask<T::Mask, LANES> {
47-
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ge(self, other)) }
48+
unsafe { Mask::from_int_unchecked(intrinsics::simd_ge(self, other)) }
4849
}
4950
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Portable SIMD module.
2+
3+
This module offers a portable abstraction for SIMD operations
4+
that is not bound to any particular hardware architecture.

crates/core_simd/src/fmt.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
2+
use core::fmt;
3+
14
macro_rules! impl_fmt_trait {
25
{ $($trait:ident,)* } => {
36
$(
4-
impl<T, const LANES: usize> core::fmt::$trait for crate::Simd<T, LANES>
7+
impl<T, const LANES: usize> fmt::$trait for Simd<T, LANES>
58
where
6-
crate::LaneCount<LANES>: crate::SupportedLaneCount,
7-
T: crate::SimdElement + core::fmt::$trait,
9+
LaneCount<LANES>: SupportedLaneCount,
10+
T: SimdElement + fmt::$trait,
811
{
9-
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
12+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1013
#[repr(transparent)]
11-
struct Wrapper<'a, T: core::fmt::$trait>(&'a T);
14+
struct Wrapper<'a, T: fmt::$trait>(&'a T);
1215

13-
impl<T: core::fmt::$trait> core::fmt::Debug for Wrapper<'_, T> {
14-
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
16+
impl<T: fmt::$trait> fmt::Debug for Wrapper<'_, T> {
17+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1518
self.0.fmt(f)
1619
}
1720
}

crates/core_simd/src/intrinsics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ extern "platform-intrinsic" {
9191
pub(crate) fn simd_bitmask<T, U>(x: T) -> U;
9292

9393
// select
94-
pub(crate) fn simd_select<T, U>(m: T, a: U, b: U) -> U;
94+
pub(crate) fn simd_select<M, T>(m: M, a: T, b: T) -> T;
9595
#[allow(unused)]
96-
pub(crate) fn simd_select_bitmask<T, U>(m: T, a: U, b: U) -> U;
96+
pub(crate) fn simd_select_bitmask<M, T>(m: M, a: T, b: T) -> T;
9797
}
9898

9999
#[cfg(feature = "std")]
@@ -114,4 +114,4 @@ mod std {
114114
}
115115

116116
#[cfg(feature = "std")]
117-
pub(crate) use crate::intrinsics::std::*;
117+
pub(crate) use crate::simd::intrinsics::std::*;

crates/core_simd/src/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{LaneCount, Simd, SupportedLaneCount};
1+
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
22
use core::{
33
iter::{Product, Sum},
44
ops::{Add, Mul},
@@ -15,7 +15,7 @@ macro_rules! impl_traits {
1515
}
1616
}
1717

18-
impl<const LANES: usize> core::iter::Product<Self> for Simd<$type, LANES>
18+
impl<const LANES: usize> Product<Self> for Simd<$type, LANES>
1919
where
2020
LaneCount<LANES>: SupportedLaneCount,
2121
{

crates/core_simd/src/lib.rs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,6 @@
1414
#![unstable(feature = "portable_simd", issue = "86656")]
1515
//! Portable SIMD module.
1616
17-
#[macro_use]
18-
mod permute;
19-
#[macro_use]
20-
mod reduction;
21-
22-
mod select;
23-
pub use select::Select;
24-
25-
#[cfg(feature = "generic_const_exprs")]
26-
mod to_bytes;
27-
28-
mod comparisons;
29-
mod fmt;
30-
mod intrinsics;
31-
mod iter;
32-
mod math;
33-
mod ops;
34-
mod round;
35-
mod vendor;
36-
37-
mod lane_count;
38-
pub use lane_count::*;
39-
40-
mod masks;
41-
pub use masks::*;
42-
43-
mod vector;
44-
pub use vector::*;
17+
#[path = "mod.rs"]
18+
mod core_simd;
19+
pub use self::core_simd::simd::*;

crates/core_simd/src/masks.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
)]
1313
mod mask_impl;
1414

15-
use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
15+
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
16+
use core::cmp::Ordering;
17+
use core::fmt;
1618

1719
/// Marker trait for types that may be used as SIMD mask elements.
1820
pub unsafe trait MaskElement: SimdElement {
@@ -251,17 +253,17 @@ where
251253
LaneCount<LANES>: SupportedLaneCount,
252254
{
253255
#[inline]
254-
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
256+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
255257
self.0.partial_cmp(&other.0)
256258
}
257259
}
258260

259-
impl<T, const LANES: usize> core::fmt::Debug for Mask<T, LANES>
261+
impl<T, const LANES: usize> fmt::Debug for Mask<T, LANES>
260262
where
261-
T: MaskElement + core::fmt::Debug,
263+
T: MaskElement + fmt::Debug,
262264
LaneCount<LANES>: SupportedLaneCount,
263265
{
264-
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
266+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
265267
f.debug_list()
266268
.entries((0..LANES).map(|lane| self.test(lane)))
267269
.finish()

crates/core_simd/src/masks/bitmask.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{LaneCount, MaskElement, Simd, SupportedLaneCount};
1+
use crate::simd::intrinsics;
2+
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
23
use core::marker::PhantomData;
34

45
/// A mask where each lane is represented by a single bit.
@@ -99,11 +100,7 @@ where
99100
unsafe {
100101
let mask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
101102
core::mem::transmute_copy(&self);
102-
crate::intrinsics::simd_select_bitmask(
103-
mask,
104-
Simd::splat(T::TRUE),
105-
Simd::splat(T::FALSE),
106-
)
103+
intrinsics::simd_select_bitmask(mask, Simd::splat(T::TRUE), Simd::splat(T::FALSE))
107104
}
108105
}
109106

@@ -115,7 +112,7 @@ where
115112
core::mem::size_of::<<LaneCount::<LANES> as SupportedLaneCount>::IntBitMask>(),
116113
);
117114
let mask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
118-
crate::intrinsics::simd_bitmask(value);
115+
intrinsics::simd_bitmask(value);
119116
Self(core::mem::transmute_copy(&mask), PhantomData)
120117
}
121118

crates/core_simd/src/masks/full_masks.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Masks that take up full SIMD vector registers.
22
33
use super::MaskElement;
4-
use crate::{LaneCount, Simd, SupportedLaneCount};
4+
use crate::simd::intrinsics;
5+
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
56

67
#[repr(transparent)]
78
pub struct Mask<T, const LANES: usize>(Simd<T, LANES>)
@@ -98,7 +99,7 @@ where
9899
where
99100
U: MaskElement,
100101
{
101-
unsafe { Mask(crate::intrinsics::simd_cast(self.0)) }
102+
unsafe { Mask(intrinsics::simd_cast(self.0)) }
102103
}
103104

104105
#[cfg(feature = "generic_const_exprs")]
@@ -111,7 +112,7 @@ where
111112
LaneCount::<LANES>::BITMASK_LEN,
112113
);
113114
let bitmask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
114-
crate::intrinsics::simd_bitmask(self.0);
115+
intrinsics::simd_bitmask(self.0);
115116
let mut bitmask: [u8; LaneCount::<LANES>::BITMASK_LEN] =
116117
core::mem::transmute_copy(&bitmask);
117118

@@ -149,7 +150,7 @@ where
149150
let bitmask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
150151
core::mem::transmute_copy(&bitmask);
151152

152-
Self::from_int_unchecked(crate::intrinsics::simd_select_bitmask(
153+
Self::from_int_unchecked(intrinsics::simd_select_bitmask(
153154
bitmask,
154155
Self::splat(true).to_int(),
155156
Self::splat(false).to_int(),
@@ -159,12 +160,12 @@ where
159160

160161
#[inline]
161162
pub fn any(self) -> bool {
162-
unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) }
163+
unsafe { intrinsics::simd_reduce_any(self.to_int()) }
163164
}
164165

165166
#[inline]
166167
pub fn all(self) -> bool {
167-
unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) }
168+
unsafe { intrinsics::simd_reduce_all(self.to_int()) }
168169
}
169170
}
170171

@@ -186,7 +187,7 @@ where
186187
type Output = Self;
187188
#[inline]
188189
fn bitand(self, rhs: Self) -> Self {
189-
unsafe { Self(crate::intrinsics::simd_and(self.0, rhs.0)) }
190+
unsafe { Self(intrinsics::simd_and(self.0, rhs.0)) }
190191
}
191192
}
192193

@@ -198,7 +199,7 @@ where
198199
type Output = Self;
199200
#[inline]
200201
fn bitor(self, rhs: Self) -> Self {
201-
unsafe { Self(crate::intrinsics::simd_or(self.0, rhs.0)) }
202+
unsafe { Self(intrinsics::simd_or(self.0, rhs.0)) }
202203
}
203204
}
204205

@@ -210,7 +211,7 @@ where
210211
type Output = Self;
211212
#[inline]
212213
fn bitxor(self, rhs: Self) -> Self {
213-
unsafe { Self(crate::intrinsics::simd_xor(self.0, rhs.0)) }
214+
unsafe { Self(intrinsics::simd_xor(self.0, rhs.0)) }
214215
}
215216
}
216217

crates/core_simd/src/math.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{LaneCount, Simd, SupportedLaneCount};
1+
use crate::simd::intrinsics::{simd_saturating_add, simd_saturating_sub};
2+
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
23

34
macro_rules! impl_uint_arith {
45
($($ty:ty),+) => {
@@ -20,7 +21,7 @@ macro_rules! impl_uint_arith {
2021
/// ```
2122
#[inline]
2223
pub fn saturating_add(self, second: Self) -> Self {
23-
unsafe { crate::intrinsics::simd_saturating_add(self, second) }
24+
unsafe { simd_saturating_add(self, second) }
2425
}
2526

2627
/// Lanewise saturating subtract.
@@ -38,7 +39,7 @@ macro_rules! impl_uint_arith {
3839
/// assert_eq!(sat, Simd::splat(0));
3940
#[inline]
4041
pub fn saturating_sub(self, second: Self) -> Self {
41-
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
42+
unsafe { simd_saturating_sub(self, second) }
4243
}
4344
})+
4445
}
@@ -64,7 +65,7 @@ macro_rules! impl_int_arith {
6465
/// ```
6566
#[inline]
6667
pub fn saturating_add(self, second: Self) -> Self {
67-
unsafe { crate::intrinsics::simd_saturating_add(self, second) }
68+
unsafe { simd_saturating_add(self, second) }
6869
}
6970

7071
/// Lanewise saturating subtract.
@@ -82,7 +83,7 @@ macro_rules! impl_int_arith {
8283
/// assert_eq!(sat, Simd::from_array([MIN, MIN, MIN, 0]));
8384
#[inline]
8485
pub fn saturating_sub(self, second: Self) -> Self {
85-
unsafe { crate::intrinsics::simd_saturating_sub(self, second) }
86+
unsafe { simd_saturating_sub(self, second) }
8687
}
8788

8889
/// Lanewise absolute value, implemented in Rust.

crates/core_simd/src/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#[macro_use]
2+
mod permute;
3+
#[macro_use]
4+
mod reduction;
5+
6+
mod select;
7+
8+
#[cfg(feature = "generic_const_exprs")]
9+
mod to_bytes;
10+
11+
mod comparisons;
12+
mod fmt;
13+
mod intrinsics;
14+
mod iter;
15+
mod math;
16+
mod ops;
17+
mod round;
18+
mod vendor;
19+
20+
mod lane_count;
21+
22+
mod masks;
23+
24+
mod vector;
25+
26+
#[doc = include_str!("core_simd_docs.md")]
27+
pub mod simd {
28+
pub use crate::core_simd::lane_count::*;
29+
pub use crate::core_simd::masks::*;
30+
pub use crate::core_simd::select::Select;
31+
pub use crate::core_simd::vector::*;
32+
pub(crate) use crate::core_simd::*;
33+
}

0 commit comments

Comments
 (0)