Skip to content

Commit 596aabe

Browse files
committed
Add num, ptr, and cmp modules
1 parent 3e4e13c commit 596aabe

27 files changed

+104
-65
lines changed

crates/core_simd/examples/dot_product.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![feature(slice_as_chunks)]
77
// Add these imports to use the stdsimd library
88
#![feature(portable_simd)]
9-
use core_simd::simd::*;
9+
use core_simd::simd::prelude::*;
1010

1111
// This is your barebones dot product implementation:
1212
// Take 2 vectors, multiply them element wise and *then*

crates/core_simd/examples/matrix_inversion.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
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::simd::*;
6-
use Which::*;
5+
use core_simd::simd::{
6+
prelude::*,
7+
Which::{self, *},
8+
};
79

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

crates/core_simd/examples/nbody.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate std_float;
55
/// Taken from the `packed_simd` crate
66
/// Run this benchmark with `cargo test --example nbody`
77
mod nbody {
8-
use core_simd::simd::*;
8+
use core_simd::simd::prelude::*;
99
#[allow(unused)] // False positive?
1010
use std_float::StdFloat;
1111

crates/core_simd/examples/spectral_norm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(portable_simd)]
22

3-
use core_simd::simd::*;
3+
use core_simd::simd::prelude::*;
44

55
fn a(i: usize, j: usize) -> f64 {
66
((i + j) * (i + j + 1) / 2 + i + 1) as f64

crates/core_simd/src/core_simd_docs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Instead, they map to a reasonable implementation of the operation for the target
3030

3131
Consistency between targets is not compromised to use faster or fewer instructions.
3232
In some cases, `std::arch` will provide a faster function that has slightly different behavior than the `std::simd` equivalent.
33-
For example, [`_mm_min_ps`](`core::arch::x86_64::_mm_min_ps`)[^1] can be slightly faster than [`SimdFloat::simd_min`], but does not conform to the IEEE standard also used by [`f32::min`].
33+
For example, [`_mm_min_ps`](`core::arch::x86_64::_mm_min_ps`)[^1] can be slightly faster than [`SimdFloat::simd_min`](`num::SimdFloat::simd_min`), but does not conform to the IEEE standard also used by [`f32::min`].
3434
When necessary, [`Simd<T, N>`] can be converted to the types provided by `std::arch` to make use of target-specific functions.
3535

3636
Many targets simply don't have SIMD, or don't support SIMD for a particular element type.

crates/core_simd/src/masks.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ mod mask_impl;
1515
mod to_bitmask;
1616
pub use to_bitmask::{ToBitMask, ToBitMaskArray};
1717

18-
use crate::simd::{intrinsics, LaneCount, Simd, SimdElement, SimdPartialEq, SupportedLaneCount};
18+
use crate::simd::{
19+
cmp::SimdPartialEq, intrinsics, LaneCount, Simd, SimdElement, SupportedLaneCount,
20+
};
1921
use core::cmp::Ordering;
2022
use core::{fmt, mem};
2123

crates/core_simd/src/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ pub(crate) mod intrinsics;
55

66
mod alias;
77
mod cast;
8-
mod elements;
9-
mod eq;
108
mod fmt;
119
mod iter;
1210
mod lane_count;
1311
mod masks;
1412
mod ops;
15-
mod ord;
1613
mod select;
1714
mod swizzle_dyn;
1815
mod to_bytes;
@@ -24,15 +21,18 @@ pub mod simd {
2421

2522
pub mod prelude;
2623

24+
pub mod num;
25+
26+
pub mod ptr;
27+
28+
pub mod cmp;
29+
2730
pub(crate) use crate::core_simd::intrinsics;
2831

2932
pub use crate::core_simd::alias::*;
3033
pub use crate::core_simd::cast::*;
31-
pub use crate::core_simd::elements::*;
32-
pub use crate::core_simd::eq::*;
3334
pub use crate::core_simd::lane_count::{LaneCount, SupportedLaneCount};
3435
pub use crate::core_simd::masks::*;
35-
pub use crate::core_simd::ord::*;
3636
pub use crate::core_simd::swizzle::*;
3737
pub use crate::core_simd::swizzle_dyn::*;
3838
pub use crate::core_simd::to_bytes::ToBytes;

crates/core_simd/src/ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::simd::{LaneCount, Simd, SimdElement, SimdPartialEq, SupportedLaneCount};
1+
use crate::simd::{cmp::SimdPartialEq, LaneCount, Simd, SimdElement, SupportedLaneCount};
22
use core::ops::{Add, Mul};
33
use core::ops::{BitAnd, BitOr, BitXor};
44
use core::ops::{Div, Rem, Sub};

crates/core_simd/src/simd/cmp.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Traits for comparing and ordering vectors.
2+
3+
mod eq;
4+
mod ord;
5+
6+
pub use eq::*;
7+
pub use ord::*;

crates/core_simd/src/eq.rs renamed to crates/core_simd/src/simd/cmp/eq.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::simd::{
2-
intrinsics, LaneCount, Mask, Simd, SimdConstPtr, SimdElement, SimdMutPtr, SupportedLaneCount,
2+
intrinsics,
3+
ptr::{SimdConstPtr, SimdMutPtr},
4+
LaneCount, Mask, Simd, SimdElement, SupportedLaneCount,
35
};
46

57
/// Parallel `PartialEq`.

crates/core_simd/src/ord.rs renamed to crates/core_simd/src/simd/cmp/ord.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::simd::{
2-
intrinsics, LaneCount, Mask, Simd, SimdConstPtr, SimdMutPtr, SimdPartialEq, SupportedLaneCount,
2+
cmp::SimdPartialEq,
3+
intrinsics,
4+
ptr::{SimdConstPtr, SimdMutPtr},
5+
LaneCount, Mask, Simd, SupportedLaneCount,
36
};
47

58
/// Parallel `PartialOrd`.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
mod const_ptr;
1+
//! Traits for vectors with numeric elements.
2+
23
mod float;
34
mod int;
4-
mod mut_ptr;
55
mod uint;
66

77
mod sealed {
88
pub trait Sealed {}
99
}
1010

11-
pub use const_ptr::*;
1211
pub use float::*;
1312
pub use int::*;
14-
pub use mut_ptr::*;
1513
pub use uint::*;

crates/core_simd/src/elements/float.rs renamed to crates/core_simd/src/simd/num/float.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::sealed::Sealed;
22
use crate::simd::{
3-
intrinsics, LaneCount, Mask, Simd, SimdCast, SimdElement, SimdPartialEq, SimdPartialOrd,
4-
SupportedLaneCount,
3+
cmp::{SimdPartialEq, SimdPartialOrd},
4+
intrinsics, LaneCount, Mask, Simd, SimdCast, SimdElement, SupportedLaneCount,
55
};
66

77
/// Operations on SIMD vectors of floats.
@@ -28,7 +28,7 @@ pub trait SimdFloat: Copy + Sealed {
2828
/// # #![feature(portable_simd)]
2929
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
3030
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
31-
/// # use simd::{SimdFloat, SimdInt, Simd};
31+
/// # use simd::prelude::*;
3232
/// let floats: Simd<f32, 4> = Simd::from_array([1.9, -4.5, f32::INFINITY, f32::NAN]);
3333
/// let ints = floats.cast::<i32>();
3434
/// assert_eq!(ints, Simd::from_array([1, -4, i32::MAX, 0]));
@@ -162,7 +162,7 @@ pub trait SimdFloat: Copy + Sealed {
162162
/// # #![feature(portable_simd)]
163163
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
164164
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
165-
/// # use simd::{f32x2, SimdFloat};
165+
/// # use simd::prelude::*;
166166
/// let v = f32x2::from_array([1., 2.]);
167167
/// assert_eq!(v.reduce_sum(), 3.);
168168
/// ```
@@ -176,7 +176,7 @@ pub trait SimdFloat: Copy + Sealed {
176176
/// # #![feature(portable_simd)]
177177
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
178178
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
179-
/// # use simd::{f32x2, SimdFloat};
179+
/// # use simd::prelude::*;
180180
/// let v = f32x2::from_array([3., 4.]);
181181
/// assert_eq!(v.reduce_product(), 12.);
182182
/// ```
@@ -195,7 +195,7 @@ pub trait SimdFloat: Copy + Sealed {
195195
/// # #![feature(portable_simd)]
196196
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
197197
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
198-
/// # use simd::{f32x2, SimdFloat};
198+
/// # use simd::prelude::*;
199199
/// let v = f32x2::from_array([1., 2.]);
200200
/// assert_eq!(v.reduce_max(), 2.);
201201
///
@@ -222,7 +222,7 @@ pub trait SimdFloat: Copy + Sealed {
222222
/// # #![feature(portable_simd)]
223223
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
224224
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
225-
/// # use simd::{f32x2, SimdFloat};
225+
/// # use simd::prelude::*;
226226
/// let v = f32x2::from_array([3., 7.]);
227227
/// assert_eq!(v.reduce_min(), 3.);
228228
///

crates/core_simd/src/elements/int.rs renamed to crates/core_simd/src/simd/num/int.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::sealed::Sealed;
22
use crate::simd::{
3-
intrinsics, LaneCount, Mask, Simd, SimdCast, SimdElement, SimdPartialOrd, SimdUint,
3+
cmp::SimdPartialOrd, intrinsics, num::SimdUint, LaneCount, Mask, Simd, SimdCast, SimdElement,
44
SupportedLaneCount,
55
};
66

@@ -32,7 +32,7 @@ pub trait SimdInt: Copy + Sealed {
3232
/// # #![feature(portable_simd)]
3333
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
3434
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
35-
/// # use simd::{Simd, SimdInt};
35+
/// # use simd::prelude::*;
3636
/// use core::i32::{MIN, MAX};
3737
/// let x = Simd::from_array([MIN, 0, 1, MAX]);
3838
/// let max = Simd::splat(MAX);
@@ -50,7 +50,7 @@ pub trait SimdInt: Copy + Sealed {
5050
/// # #![feature(portable_simd)]
5151
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
5252
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
53-
/// # use simd::{Simd, SimdInt};
53+
/// # use simd::prelude::*;
5454
/// use core::i32::{MIN, MAX};
5555
/// let x = Simd::from_array([MIN, -2, -1, MAX]);
5656
/// let max = Simd::splat(MAX);
@@ -68,7 +68,7 @@ pub trait SimdInt: Copy + Sealed {
6868
/// # #![feature(portable_simd)]
6969
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
7070
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
71-
/// # use simd::{Simd, SimdInt};
71+
/// # use simd::prelude::*;
7272
/// use core::i32::{MIN, MAX};
7373
/// let xs = Simd::from_array([MIN, MIN +1, -5, 0]);
7474
/// assert_eq!(xs.abs(), Simd::from_array([MIN, MAX, 5, 0]));
@@ -83,7 +83,7 @@ pub trait SimdInt: Copy + Sealed {
8383
/// # #![feature(portable_simd)]
8484
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
8585
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
86-
/// # use simd::{Simd, SimdInt};
86+
/// # use simd::prelude::*;
8787
/// use core::i32::{MIN, MAX};
8888
/// let xs = Simd::from_array([MIN, -2, 0, 3]);
8989
/// let unsat = xs.abs();
@@ -101,7 +101,7 @@ pub trait SimdInt: Copy + Sealed {
101101
/// # #![feature(portable_simd)]
102102
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
103103
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
104-
/// # use simd::{Simd, SimdInt};
104+
/// # use simd::prelude::*;
105105
/// use core::i32::{MIN, MAX};
106106
/// let x = Simd::from_array([MIN, -2, 3, MAX]);
107107
/// let unsat = -x;
@@ -131,7 +131,7 @@ pub trait SimdInt: Copy + Sealed {
131131
/// # #![feature(portable_simd)]
132132
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
133133
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
134-
/// # use simd::{i32x4, SimdInt};
134+
/// # use simd::prelude::*;
135135
/// let v = i32x4::from_array([1, 2, 3, 4]);
136136
/// assert_eq!(v.reduce_sum(), 10);
137137
///
@@ -149,7 +149,7 @@ pub trait SimdInt: Copy + Sealed {
149149
/// # #![feature(portable_simd)]
150150
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
151151
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
152-
/// # use simd::{i32x4, SimdInt};
152+
/// # use simd::prelude::*;
153153
/// let v = i32x4::from_array([1, 2, 3, 4]);
154154
/// assert_eq!(v.reduce_product(), 24);
155155
///
@@ -167,7 +167,7 @@ pub trait SimdInt: Copy + Sealed {
167167
/// # #![feature(portable_simd)]
168168
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
169169
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
170-
/// # use simd::{i32x4, SimdInt};
170+
/// # use simd::prelude::*;
171171
/// let v = i32x4::from_array([1, 2, 3, 4]);
172172
/// assert_eq!(v.reduce_max(), 4);
173173
/// ```
@@ -181,7 +181,7 @@ pub trait SimdInt: Copy + Sealed {
181181
/// # #![feature(portable_simd)]
182182
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
183183
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
184-
/// # use simd::{i32x4, SimdInt};
184+
/// # use simd::prelude::*;
185185
/// let v = i32x4::from_array([1, 2, 3, 4]);
186186
/// assert_eq!(v.reduce_min(), 1);
187187
/// ```

crates/core_simd/src/elements/uint.rs renamed to crates/core_simd/src/simd/num/uint.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait SimdUint: Copy + Sealed {
2929
/// # #![feature(portable_simd)]
3030
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
3131
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
32-
/// # use simd::{Simd, SimdUint};
32+
/// # use simd::prelude::*;
3333
/// use core::u32::MAX;
3434
/// let x = Simd::from_array([2, 1, 0, MAX]);
3535
/// let max = Simd::splat(MAX);
@@ -47,7 +47,7 @@ pub trait SimdUint: Copy + Sealed {
4747
/// # #![feature(portable_simd)]
4848
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
4949
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
50-
/// # use simd::{Simd, SimdUint};
50+
/// # use simd::prelude::*;
5151
/// use core::u32::MAX;
5252
/// let x = Simd::from_array([2, 1, 0, MAX]);
5353
/// let max = Simd::splat(MAX);
@@ -122,7 +122,7 @@ macro_rules! impl_trait {
122122

123123
#[inline]
124124
fn wrapping_neg(self) -> Self {
125-
use crate::simd::SimdInt;
125+
use crate::simd::num::SimdInt;
126126
(-self.cast::<$signed>()).cast()
127127
}
128128

crates/core_simd/src/simd/prelude.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
88
#[doc(no_inline)]
99
pub use super::{
10-
simd_swizzle, Mask, Simd, SimdConstPtr, SimdFloat, SimdInt, SimdMutPtr, SimdOrd, SimdPartialEq,
11-
SimdPartialOrd, SimdUint,
10+
cmp::{SimdOrd, SimdPartialEq, SimdPartialOrd},
11+
num::{SimdFloat, SimdInt, SimdUint},
12+
ptr::{SimdConstPtr, SimdMutPtr},
13+
simd_swizzle, Mask, Simd,
1214
};
1315

1416
#[rustfmt::skip]

crates/core_simd/src/simd/ptr.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Traits for vectors of pointers.
2+
3+
mod const_ptr;
4+
mod mut_ptr;
5+
6+
mod sealed {
7+
pub trait Sealed {}
8+
}
9+
10+
pub use const_ptr::*;
11+
pub use mut_ptr::*;

crates/core_simd/src/elements/const_ptr.rs renamed to crates/core_simd/src/simd/ptr/const_ptr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::sealed::Sealed;
2-
use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdPartialEq, SimdUint, SupportedLaneCount};
2+
use crate::simd::{
3+
cmp::SimdPartialEq, intrinsics, num::SimdUint, LaneCount, Mask, Simd, SupportedLaneCount,
4+
};
35

46
/// Operations on SIMD vectors of constant pointers.
57
pub trait SimdConstPtr: Copy + Sealed {

crates/core_simd/src/elements/mut_ptr.rs renamed to crates/core_simd/src/simd/ptr/mut_ptr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::sealed::Sealed;
2-
use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdPartialEq, SimdUint, SupportedLaneCount};
2+
use crate::simd::{
3+
cmp::SimdPartialEq, intrinsics, num::SimdUint, LaneCount, Mask, Simd, SupportedLaneCount,
4+
};
35

46
/// Operations on SIMD vectors of mutable pointers.
57
pub trait SimdMutPtr: Copy + Sealed {

crates/core_simd/src/swizzle_dyn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ where
8686
#[inline]
8787
#[allow(clippy::let_and_return)]
8888
unsafe fn avx2_pshufb(bytes: Simd<u8, 32>, idxs: Simd<u8, 32>) -> Simd<u8, 32> {
89-
use crate::simd::SimdPartialOrd;
89+
use crate::simd::cmp::SimdPartialOrd;
9090
#[cfg(target_arch = "x86")]
9191
use core::arch::x86;
9292
#[cfg(target_arch = "x86_64")]
@@ -149,7 +149,7 @@ where
149149
// On x86, make sure the top bit is set.
150150
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
151151
let idxs = {
152-
use crate::simd::SimdPartialOrd;
152+
use crate::simd::cmp::SimdPartialOrd;
153153
idxs.simd_lt(Simd::splat(N as u8))
154154
.select(idxs, Simd::splat(u8::MAX))
155155
};

crates/core_simd/src/to_bytes.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::simd::{LaneCount, Simd, SimdElement, SimdFloat, SimdInt, SimdUint, SupportedLaneCount};
1+
use crate::simd::{
2+
num::{SimdFloat, SimdInt, SimdUint},
3+
LaneCount, Simd, SimdElement, SupportedLaneCount,
4+
};
25

36
mod sealed {
47
use super::*;

0 commit comments

Comments
 (0)