Skip to content

Commit a93ded5

Browse files
committed
Remove generic_const_exprs
1 parent 4825b2a commit a93ded5

File tree

10 files changed

+148
-110
lines changed

10 files changed

+148
-110
lines changed

crates/core_simd/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ license = "MIT OR Apache-2.0"
1212
default = ["as_crate"]
1313
as_crate = []
1414
std = []
15-
generic_const_exprs = []
1615
all_lane_counts = []
1716

1817
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]

crates/core_simd/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
strict_provenance,
1515
ptr_metadata
1616
)]
17-
#![cfg_attr(feature = "generic_const_exprs", feature(generic_const_exprs))]
18-
#![cfg_attr(feature = "generic_const_exprs", allow(incomplete_features))]
1917
#![warn(missing_docs, clippy::missing_inline_in_public_items)] // basically all items, really
2018
#![deny(unsafe_op_in_unsafe_fn, clippy::undocumented_unsafe_blocks)]
2119
#![allow(internal_features)]

crates/core_simd/src/masks.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
mod mask_impl;
1414

1515
mod to_bitmask;
16-
pub use to_bitmask::ToBitMask;
17-
18-
#[cfg(feature = "generic_const_exprs")]
19-
pub use to_bitmask::{bitmask_len, ToBitMaskArray};
16+
pub use to_bitmask::{ToBitMask, ToBitMaskArray};
2017

2118
use crate::simd::{intrinsics, LaneCount, Simd, SimdElement, SimdPartialEq, SupportedLaneCount};
2219
use core::cmp::Ordering;

crates/core_simd/src/masks/bitmask.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ where
119119
unsafe { Self(intrinsics::simd_bitmask(value), PhantomData) }
120120
}
121121

122-
#[cfg(feature = "generic_const_exprs")]
123122
#[inline]
124123
#[must_use = "method returns a new array and does not mutate the original value"]
125124
pub fn to_bitmask_array<const N: usize>(self) -> [u8; N] {
@@ -129,7 +128,6 @@ where
129128
unsafe { core::mem::transmute_copy(&self.0) }
130129
}
131130

132-
#[cfg(feature = "generic_const_exprs")]
133131
#[inline]
134132
#[must_use = "method returns a new mask and does not mutate the original value"]
135133
pub fn from_bitmask_array<const N: usize>(bitmask: [u8; N]) -> Self {

crates/core_simd/src/masks/full_masks.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//! Masks that take up full SIMD vector registers.
22
3-
use super::MaskElement;
3+
use super::{to_bitmask::ToBitMaskArray, MaskElement};
44
use crate::simd::intrinsics;
55
use crate::simd::{LaneCount, Simd, SupportedLaneCount, ToBitMask};
66

7-
#[cfg(feature = "generic_const_exprs")]
8-
use crate::simd::ToBitMaskArray;
9-
107
#[repr(transparent)]
118
pub struct Mask<T, const LANES: usize>(Simd<T, LANES>)
129
where
@@ -145,23 +142,19 @@ where
145142
unsafe { Mask(intrinsics::simd_cast(self.0)) }
146143
}
147144

148-
#[cfg(feature = "generic_const_exprs")]
149145
#[inline]
150146
#[must_use = "method returns a new array and does not mutate the original value"]
151147
pub fn to_bitmask_array<const N: usize>(self) -> [u8; N]
152148
where
153149
super::Mask<T, LANES>: ToBitMaskArray,
154-
[(); <super::Mask<T, LANES> as ToBitMaskArray>::BYTES]: Sized,
155150
{
156-
assert_eq!(<super::Mask<T, LANES> as ToBitMaskArray>::BYTES, N);
157-
158-
// Safety: N is the correct bitmask size
151+
// Safety: Bytes is the right size array
159152
unsafe {
160153
// Compute the bitmask
161-
let bitmask: [u8; <super::Mask<T, LANES> as ToBitMaskArray>::BYTES] =
154+
let bitmask: <super::Mask<T, LANES> as ToBitMaskArray>::BitMaskArray =
162155
intrinsics::simd_bitmask(self.0);
163156

164-
// Transmute to the return type, previously asserted to be the same size
157+
// Transmute to the return type
165158
let mut bitmask: [u8; N] = core::mem::transmute_copy(&bitmask);
166159

167160
// LLVM assumes bit order should match endianness
@@ -175,17 +168,13 @@ where
175168
}
176169
}
177170

178-
#[cfg(feature = "generic_const_exprs")]
179171
#[inline]
180172
#[must_use = "method returns a new mask and does not mutate the original value"]
181173
pub fn from_bitmask_array<const N: usize>(mut bitmask: [u8; N]) -> Self
182174
where
183175
super::Mask<T, LANES>: ToBitMaskArray,
184-
[(); <super::Mask<T, LANES> as ToBitMaskArray>::BYTES]: Sized,
185176
{
186-
assert_eq!(<super::Mask<T, LANES> as ToBitMaskArray>::BYTES, N);
187-
188-
// Safety: N is the correct bitmask size
177+
// Safety: Bytes is the right size array
189178
unsafe {
190179
// LLVM assumes bit order should match endianness
191180
if cfg!(target_endian = "big") {
@@ -194,8 +183,8 @@ where
194183
}
195184
}
196185

197-
// Transmute to the bitmask type, previously asserted to be the same size
198-
let bitmask: [u8; <super::Mask<T, LANES> as ToBitMaskArray>::BYTES] =
186+
// Transmute to the bitmask
187+
let bitmask: <super::Mask<T, LANES> as ToBitMaskArray>::BitMaskArray =
199188
core::mem::transmute_copy(&bitmask);
200189

201190
// Compute the regular mask

crates/core_simd/src/masks/to_bitmask.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,18 @@ pub trait ToBitMask: Sealed {
3030
/// Converts masks to and from byte array bitmasks.
3131
///
3232
/// Each bit of the bitmask corresponds to a mask lane, starting with the LSB of the first byte.
33-
#[cfg(feature = "generic_const_exprs")]
3433
pub trait ToBitMaskArray: Sealed {
35-
/// The length of the bitmask array.
36-
const BYTES: usize;
34+
/// The bitmask array.
35+
type BitMaskArray;
3736

3837
/// Converts a mask to a bitmask.
39-
fn to_bitmask_array(self) -> [u8; Self::BYTES];
38+
fn to_bitmask_array(self) -> Self::BitMaskArray;
4039

4140
/// Converts a bitmask to a mask.
42-
fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self;
41+
fn from_bitmask_array(bitmask: Self::BitMaskArray) -> Self;
4342
}
4443

45-
macro_rules! impl_integer_intrinsic {
44+
macro_rules! impl_integer {
4645
{ $(impl ToBitMask<BitMask=$int:ty> for Mask<_, $lanes:literal>)* } => {
4746
$(
4847
impl<T: MaskElement> ToBitMask for Mask<T, $lanes> {
@@ -62,7 +61,27 @@ macro_rules! impl_integer_intrinsic {
6261
}
6362
}
6463

65-
impl_integer_intrinsic! {
64+
macro_rules! impl_array {
65+
{ $(impl ToBitMaskArray<Bytes=$int:literal> for Mask<_, $lanes:literal>)* } => {
66+
$(
67+
impl<T: MaskElement> ToBitMaskArray for Mask<T, $lanes> {
68+
type BitMaskArray = [u8; $int];
69+
70+
#[inline]
71+
fn to_bitmask_array(self) -> Self::BitMaskArray {
72+
self.0.to_bitmask_array()
73+
}
74+
75+
#[inline]
76+
fn from_bitmask_array(bitmask: Self::BitMaskArray) -> Self {
77+
Self(mask_impl::Mask::from_bitmask_array(bitmask))
78+
}
79+
}
80+
)*
81+
}
82+
}
83+
84+
impl_integer! {
6685
impl ToBitMask<BitMask=u8> for Mask<_, 1>
6786
impl ToBitMask<BitMask=u8> for Mask<_, 2>
6887
impl ToBitMask<BitMask=u8> for Mask<_, 4>
@@ -72,27 +91,12 @@ impl_integer_intrinsic! {
7291
impl ToBitMask<BitMask=u64> for Mask<_, 64>
7392
}
7493

75-
/// Returns the minimum number of bytes in a bitmask with `lanes` lanes.
76-
#[cfg(feature = "generic_const_exprs")]
77-
#[allow(clippy::missing_inline_in_public_items)]
78-
pub const fn bitmask_len(lanes: usize) -> usize {
79-
(lanes + 7) / 8
80-
}
81-
82-
#[cfg(feature = "generic_const_exprs")]
83-
impl<T: MaskElement, const LANES: usize> ToBitMaskArray for Mask<T, LANES>
84-
where
85-
LaneCount<LANES>: SupportedLaneCount,
86-
{
87-
const BYTES: usize = bitmask_len(LANES);
88-
89-
#[inline]
90-
fn to_bitmask_array(self) -> [u8; Self::BYTES] {
91-
self.0.to_bitmask_array()
92-
}
93-
94-
#[inline]
95-
fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self {
96-
Mask(mask_impl::Mask::from_bitmask_array(bitmask))
97-
}
94+
impl_array! {
95+
impl ToBitMaskArray<Bytes=1> for Mask<_, 1>
96+
impl ToBitMaskArray<Bytes=1> for Mask<_, 2>
97+
impl ToBitMaskArray<Bytes=1> for Mask<_, 4>
98+
impl ToBitMaskArray<Bytes=1> for Mask<_, 8>
99+
impl ToBitMaskArray<Bytes=2> for Mask<_, 16>
100+
impl ToBitMaskArray<Bytes=4> for Mask<_, 32>
101+
impl ToBitMaskArray<Bytes=8> for Mask<_, 64>
98102
}

crates/core_simd/src/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ mod swizzle;
33

44
pub(crate) mod intrinsics;
55

6-
#[cfg(feature = "generic_const_exprs")]
7-
mod to_bytes;
8-
96
mod alias;
107
mod cast;
118
mod elements;
@@ -18,6 +15,7 @@ mod ops;
1815
mod ord;
1916
mod select;
2017
mod swizzle_dyn;
18+
mod to_bytes;
2119
mod vector;
2220
mod vendor;
2321

@@ -37,5 +35,6 @@ pub mod simd {
3735
pub use crate::core_simd::ord::*;
3836
pub use crate::core_simd::swizzle::*;
3937
pub use crate::core_simd::swizzle_dyn::*;
38+
pub use crate::core_simd::to_bytes::ToBytes;
4039
pub use crate::core_simd::vector::*;
4140
}

0 commit comments

Comments
 (0)