Skip to content

Commit 97007cc

Browse files
Merge pull request rust-lang#386 from rust-lang/core-intrinsics
Use core::intrinsics
2 parents 1273da6 + e7130ec commit 97007cc

19 files changed

+107
-286
lines changed

crates/core_simd/src/intrinsics.rs

-170
This file was deleted.

crates/core_simd/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#![no_std]
22
#![feature(
3+
core_intrinsics,
34
const_refs_to_cell,
45
const_maybe_uninit_as_mut_ptr,
56
const_mut_refs,
67
convert_float_to_int,
78
decl_macro,
89
inline_const,
910
intra_doc_pointers,
10-
platform_intrinsics,
1111
repr_simd,
1212
simd_ffi,
1313
staged_api,

crates/core_simd/src/masks.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
)]
1313
mod mask_impl;
1414

15-
use crate::simd::{
16-
cmp::SimdPartialEq, intrinsics, LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount,
17-
};
15+
use crate::simd::{cmp::SimdPartialEq, LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount};
1816
use core::cmp::Ordering;
1917
use core::{fmt, mem};
2018

@@ -141,8 +139,9 @@ where
141139
// but these are "dependently-sized" types, so copy elision it is!
142140
unsafe {
143141
let bytes: [u8; N] = mem::transmute_copy(&array);
144-
let bools: Simd<i8, N> = intrinsics::simd_ne(Simd::from_array(bytes), Simd::splat(0u8));
145-
Mask::from_int_unchecked(intrinsics::simd_cast(bools))
142+
let bools: Simd<i8, N> =
143+
core::intrinsics::simd::simd_ne(Simd::from_array(bytes), Simd::splat(0u8));
144+
Mask::from_int_unchecked(core::intrinsics::simd::simd_cast(bools))
146145
}
147146
}
148147

@@ -160,7 +159,7 @@ where
160159
// This would be hypothetically valid as an "in-place" transmute,
161160
// but these are "dependently-sized" types, so copy elision it is!
162161
unsafe {
163-
let mut bytes: Simd<i8, N> = intrinsics::simd_cast(self.to_int());
162+
let mut bytes: Simd<i8, N> = core::intrinsics::simd::simd_cast(self.to_int());
164163
bytes &= Simd::splat(1i8);
165164
mem::transmute_copy(&bytes)
166165
}
@@ -374,15 +373,17 @@ where
374373
);
375374

376375
// Safety: the input and output are integer vectors
377-
let index: Simd<T, N> = unsafe { intrinsics::simd_cast(index) };
376+
let index: Simd<T, N> = unsafe { core::intrinsics::simd::simd_cast(index) };
378377

379378
let masked_index = self.select(index, Self::splat(true).to_int());
380379

381380
// Safety: the input and output are integer vectors
382-
let masked_index: Simd<T::Unsigned, N> = unsafe { intrinsics::simd_cast(masked_index) };
381+
let masked_index: Simd<T::Unsigned, N> =
382+
unsafe { core::intrinsics::simd::simd_cast(masked_index) };
383383

384384
// Safety: the input is an integer vector
385-
let min_index: T::Unsigned = unsafe { intrinsics::simd_reduce_min(masked_index) };
385+
let min_index: T::Unsigned =
386+
unsafe { core::intrinsics::simd::simd_reduce_min(masked_index) };
386387

387388
// Safety: the return value is the unsigned version of T
388389
let min_index: T = unsafe { core::mem::transmute_copy(&min_index) };

crates/core_simd/src/masks/bitmask.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(unused_imports)]
22
use super::MaskElement;
3-
use crate::simd::intrinsics;
43
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
54
use core::marker::PhantomData;
65

@@ -109,14 +108,18 @@ where
109108
#[must_use = "method returns a new vector and does not mutate the original value"]
110109
pub fn to_int(self) -> Simd<T, N> {
111110
unsafe {
112-
intrinsics::simd_select_bitmask(self.0, Simd::splat(T::TRUE), Simd::splat(T::FALSE))
111+
core::intrinsics::simd::simd_select_bitmask(
112+
self.0,
113+
Simd::splat(T::TRUE),
114+
Simd::splat(T::FALSE),
115+
)
113116
}
114117
}
115118

116119
#[inline]
117120
#[must_use = "method returns a new mask and does not mutate the original value"]
118121
pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
119-
unsafe { Self(intrinsics::simd_bitmask(value), PhantomData) }
122+
unsafe { Self(core::intrinsics::simd::simd_bitmask(value), PhantomData) }
120123
}
121124

122125
#[inline]

crates/core_simd/src/masks/full_masks.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Masks that take up full SIMD vector registers.
22
3-
use crate::simd::intrinsics;
43
use crate::simd::{LaneCount, MaskElement, Simd, SupportedLaneCount};
54

65
#[repr(transparent)]
@@ -138,7 +137,7 @@ where
138137
U: MaskElement,
139138
{
140139
// Safety: masks are simply integer vectors of 0 and -1, and we can cast the element type.
141-
unsafe { Mask(intrinsics::simd_cast(self.0)) }
140+
unsafe { Mask(core::intrinsics::simd::simd_cast(self.0)) }
142141
}
143142

144143
#[inline]
@@ -150,7 +149,7 @@ where
150149
unsafe {
151150
// Compute the bitmask
152151
let mut bytes: <LaneCount<N> as SupportedLaneCount>::BitMask =
153-
intrinsics::simd_bitmask(self.0);
152+
core::intrinsics::simd::simd_bitmask(self.0);
154153

155154
// LLVM assumes bit order should match endianness
156155
if cfg!(target_endian = "big") {
@@ -183,7 +182,7 @@ where
183182
}
184183

185184
// Compute the regular mask
186-
Self::from_int_unchecked(intrinsics::simd_select_bitmask(
185+
Self::from_int_unchecked(core::intrinsics::simd::simd_select_bitmask(
187186
bytes,
188187
Self::splat(true).to_int(),
189188
Self::splat(false).to_int(),
@@ -199,7 +198,7 @@ where
199198
let resized = self.to_int().resize::<M>(T::FALSE);
200199

201200
// Safety: `resized` is an integer vector with length M, which must match T
202-
let bitmask: U = unsafe { intrinsics::simd_bitmask(resized) };
201+
let bitmask: U = unsafe { core::intrinsics::simd::simd_bitmask(resized) };
203202

204203
// LLVM assumes bit order should match endianness
205204
if cfg!(target_endian = "big") {
@@ -223,7 +222,7 @@ where
223222

224223
// SAFETY: `mask` is the correct bitmask type for a u64 bitmask
225224
let mask: Simd<T, M> = unsafe {
226-
intrinsics::simd_select_bitmask(
225+
core::intrinsics::simd::simd_select_bitmask(
227226
bitmask,
228227
Simd::<T, M>::splat(T::TRUE),
229228
Simd::<T, M>::splat(T::FALSE),
@@ -274,14 +273,14 @@ where
274273
#[must_use = "method returns a new bool and does not mutate the original value"]
275274
pub fn any(self) -> bool {
276275
// Safety: use `self` as an integer vector
277-
unsafe { intrinsics::simd_reduce_any(self.to_int()) }
276+
unsafe { core::intrinsics::simd::simd_reduce_any(self.to_int()) }
278277
}
279278

280279
#[inline]
281280
#[must_use = "method returns a new vector and does not mutate the original value"]
282281
pub fn all(self) -> bool {
283282
// Safety: use `self` as an integer vector
284-
unsafe { intrinsics::simd_reduce_all(self.to_int()) }
283+
unsafe { core::intrinsics::simd::simd_reduce_all(self.to_int()) }
285284
}
286285
}
287286

@@ -306,7 +305,7 @@ where
306305
#[must_use = "method returns a new mask and does not mutate the original value"]
307306
fn bitand(self, rhs: Self) -> Self {
308307
// Safety: `self` is an integer vector
309-
unsafe { Self(intrinsics::simd_and(self.0, rhs.0)) }
308+
unsafe { Self(core::intrinsics::simd::simd_and(self.0, rhs.0)) }
310309
}
311310
}
312311

@@ -320,7 +319,7 @@ where
320319
#[must_use = "method returns a new mask and does not mutate the original value"]
321320
fn bitor(self, rhs: Self) -> Self {
322321
// Safety: `self` is an integer vector
323-
unsafe { Self(intrinsics::simd_or(self.0, rhs.0)) }
322+
unsafe { Self(core::intrinsics::simd::simd_or(self.0, rhs.0)) }
324323
}
325324
}
326325

@@ -334,7 +333,7 @@ where
334333
#[must_use = "method returns a new mask and does not mutate the original value"]
335334
fn bitxor(self, rhs: Self) -> Self {
336335
// Safety: `self` is an integer vector
337-
unsafe { Self(intrinsics::simd_xor(self.0, rhs.0)) }
336+
unsafe { Self(core::intrinsics::simd::simd_xor(self.0, rhs.0)) }
338337
}
339338
}
340339

crates/core_simd/src/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#[macro_use]
22
mod swizzle;
33

4-
pub(crate) mod intrinsics;
5-
64
mod alias;
75
mod cast;
86
mod fmt;
@@ -27,8 +25,6 @@ pub mod simd {
2725

2826
pub mod cmp;
2927

30-
pub(crate) use crate::core_simd::intrinsics;
31-
3228
pub use crate::core_simd::alias::*;
3329
pub use crate::core_simd::cast::*;
3430
pub use crate::core_simd::lane_count::{LaneCount, SupportedLaneCount};

0 commit comments

Comments
 (0)