Skip to content

Commit 11cd98d

Browse files
committed
Stabilize funnel_shifts (including const)
`funnel_shl` and `funnel_shr` have been around for close to a year, the unchecked versions for a number of months. These are reasonably small and uncontroversial, and it can be tricky to get similar performance with a fallback; stabilize them here. Newly stable API: impl {u8, u16, u32, u64, u128, usize} { pub const fn funnel_shl(self, right: Self, shift: u32) -> Self; pub const fn funnel_shr(self, right: Self, shift: u32) -> Self; pub const unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self; pub const unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self; } The tracking issue also mentions a `wrapping_` version but it has not been implemented. Tracking issue: RUST-145686
1 parent 79ef636 commit 11cd98d

10 files changed

Lines changed: 18 additions & 30 deletions

File tree

library/core/src/intrinsics/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ pub const unsafe fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
22062206
#[rustc_intrinsic_const_stable_indirect]
22072207
#[rustc_nounwind]
22082208
#[rustc_intrinsic]
2209-
#[rustc_allow_const_fn_unstable(const_trait_impl, funnel_shifts)]
2209+
#[rustc_allow_const_fn_unstable(const_trait_impl)]
22102210
#[miri::intrinsic_fallback_is_spec]
22112211
pub const fn rotate_left<T: [const] fallback::FunnelShift>(x: T, shift: u32) -> T {
22122212
// Make sure to call the intrinsic for `funnel_shl`, not the fallback impl.
@@ -2228,7 +2228,7 @@ pub const fn rotate_left<T: [const] fallback::FunnelShift>(x: T, shift: u32) ->
22282228
#[rustc_intrinsic_const_stable_indirect]
22292229
#[rustc_nounwind]
22302230
#[rustc_intrinsic]
2231-
#[rustc_allow_const_fn_unstable(const_trait_impl, funnel_shifts)]
2231+
#[rustc_allow_const_fn_unstable(const_trait_impl)]
22322232
#[miri::intrinsic_fallback_is_spec]
22332233
pub const fn rotate_right<T: [const] fallback::FunnelShift>(x: T, shift: u32) -> T {
22342234
// Make sure to call the intrinsic for `funnel_shr`, not the fallback impl.
@@ -2324,11 +2324,11 @@ pub const fn saturating_sub<T: Copy>(a: T, b: T) -> T;
23242324
///
23252325
/// Safe versions of this intrinsic are available on the integer primitives
23262326
/// via the `funnel_shl` method. For example, [`u32::funnel_shl`].
2327+
#[rustc_intrinsic_const_stable_indirect]
23272328
#[rustc_intrinsic]
23282329
#[rustc_nounwind]
2329-
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
2330-
#[unstable(feature = "funnel_shifts", issue = "145686")]
23312330
#[track_caller]
2331+
#[rustc_allow_const_fn_unstable(const_trait_impl, core_intrinsics_fallbacks)]
23322332
#[miri::intrinsic_fallback_is_spec]
23332333
pub const unsafe fn unchecked_funnel_shl<T: [const] fallback::FunnelShift>(
23342334
a: T,
@@ -2352,11 +2352,11 @@ pub const unsafe fn unchecked_funnel_shl<T: [const] fallback::FunnelShift>(
23522352
///
23532353
/// Safer versions of this intrinsic are available on the integer primitives
23542354
/// via the `funnel_shr` method. For example, [`u32::funnel_shr`]
2355+
#[rustc_intrinsic_const_stable_indirect]
23552356
#[rustc_intrinsic]
23562357
#[rustc_nounwind]
2357-
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
2358-
#[unstable(feature = "funnel_shifts", issue = "145686")]
23592358
#[track_caller]
2359+
#[rustc_allow_const_fn_unstable(const_trait_impl, core_intrinsics_fallbacks)]
23602360
#[miri::intrinsic_fallback_is_spec]
23612361
pub const unsafe fn unchecked_funnel_shr<T: [const] fallback::FunnelShift>(
23622362
a: T,

library/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
#![feature(final_associated_functions)]
132132
#![feature(freeze_impls)]
133133
#![feature(fundamental)]
134-
#![feature(funnel_shifts)]
135134
#![feature(impl_restriction)]
136135
#![feature(intra_doc_pointers)]
137136
#![feature(intrinsics)]

library/core/src/num/uint_macros.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,6 @@ macro_rules! uint_impl {
521521
/// # Examples
522522
///
523523
/// ```
524-
/// #![feature(funnel_shifts)]
525-
///
526524
#[doc = concat!("let a = ", $rot_op, "_", stringify!($SelfT), ";")]
527525
#[doc = concat!("let b = ", $fsh_op, "_", stringify!($SelfT), ";")]
528526
///
@@ -542,16 +540,14 @@ macro_rules! uint_impl {
542540
/// rotating by an unbounded amount like [`rotate_left`](Self::rotate_left) does:
543541
///
544542
/// ```should_panic
545-
/// #![feature(funnel_shifts)]
546-
///
547543
#[doc = concat!("let a = ", stringify!($SelfT), "::MAX;")]
548544
/// // Okay
549545
#[doc = concat!("let _ = a.rotate_left(", stringify!($SelfT), "::BITS);")]
550546
/// // Panics
551547
#[doc = concat!("let _ = a.funnel_shl(a, ", stringify!($SelfT), "::BITS);")]
552548
/// ```
553-
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
554-
#[unstable(feature = "funnel_shifts", issue = "145686")]
549+
#[rustc_const_stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
550+
#[stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
555551
#[must_use = "this returns the result of the operation, without modifying the original"]
556552
#[inline(always)]
557553
pub const fn funnel_shl(self, right: Self, n: u32) -> Self {
@@ -577,8 +573,6 @@ macro_rules! uint_impl {
577573
/// # Examples
578574
///
579575
/// ```
580-
/// #![feature(funnel_shifts)]
581-
///
582576
#[doc = concat!("let a = ", $rot_op, "_", stringify!($SelfT), ";")]
583577
#[doc = concat!("let b = ", $fsh_op, "_", stringify!($SelfT), ";")]
584578
///
@@ -598,16 +592,14 @@ macro_rules! uint_impl {
598592
/// rotating by an unbounded amount like [`rotate_right`](Self::rotate_right) does:
599593
///
600594
/// ```should_panic
601-
/// #![feature(funnel_shifts)]
602-
///
603595
#[doc = concat!("let a = ", stringify!($SelfT), "::MAX;")]
604596
/// // Okay
605597
#[doc = concat!("let _ = a.rotate_right(", stringify!($SelfT), "::BITS);")]
606598
/// // Panics
607599
#[doc = concat!("let _ = a.funnel_shr(a, ", stringify!($SelfT), "::BITS);")]
608600
/// ```
609-
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
610-
#[unstable(feature = "funnel_shifts", issue = "145686")]
601+
#[rustc_const_stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
602+
#[stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
611603
#[must_use = "this returns the result of the operation, without modifying the original"]
612604
#[inline(always)]
613605
pub const fn funnel_shr(self, right: Self, n: u32) -> Self {
@@ -624,8 +616,8 @@ macro_rules! uint_impl {
624616
#[doc = concat!("`", stringify!($SelfT) , "::BITS`,")]
625617
/// i.e. when [`funnel_shl`](Self::funnel_shl) would panic.
626618
///
627-
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
628-
#[unstable(feature = "funnel_shifts", issue = "145686")]
619+
#[rustc_const_stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
620+
#[stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
629621
#[must_use = "this returns the result of the operation, without modifying the original"]
630622
#[inline(always)]
631623
#[track_caller]
@@ -650,8 +642,8 @@ macro_rules! uint_impl {
650642
#[doc = concat!("`", stringify!($SelfT) , "::BITS`,")]
651643
/// i.e. when [`funnel_shr`](Self::funnel_shr) would panic.
652644
///
653-
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")]
654-
#[unstable(feature = "funnel_shifts", issue = "145686")]
645+
#[rustc_const_stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
646+
#[stable(feature = "funnel_shifts", since = "CURRENT_RUSTC_VERSION")]
655647
#[must_use = "this returns the result of the operation, without modifying the original"]
656648
#[inline(always)]
657649
#[track_caller]

library/coretests/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#![feature(fmt_internals)]
6161
#![feature(formatting_options)]
6262
#![feature(freeze)]
63-
#![feature(funnel_shifts)]
6463
#![feature(future_join)]
6564
#![feature(generic_assert_internals)]
6665
#![feature(hasher_prefixfree_extras)]

library/std/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@
350350
#![feature(fmt_internals)]
351351
#![feature(fn_ptr_trait)]
352352
#![feature(formatting_options)]
353-
#![feature(funnel_shifts)]
354353
#![feature(generic_atomic)]
355354
#![feature(hash_map_internals)]
356355
#![feature(hash_map_macro)]

library/stdarch/crates/core_arch/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
x86_amx_intrinsics,
3434
f16,
3535
aarch64_unstable_target_feature,
36-
funnel_shifts,
3736
avx10_target_feature,
3837
const_trait_impl,
3938
const_cmp,

src/tools/miri/tests/fail/intrinsics/funnel_shl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(core_intrinsics, funnel_shifts)]
1+
#![feature(core_intrinsics)]
22

33
fn main() {
44
unsafe {

src/tools/miri/tests/fail/intrinsics/funnel_shr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(core_intrinsics, funnel_shifts)]
1+
#![feature(core_intrinsics)]
22

33
fn main() {
44
unsafe {

src/tools/miri/tests/pass/intrinsics/integer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@run-native
2-
#![feature(core_intrinsics, funnel_shifts)]
2+
#![feature(core_intrinsics)]
33
use std::intrinsics::*;
44

55
fn main() {

tests/codegen-llvm/force-intrinsic-fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
//@ revisions: NORMAL FALLBACK
44
//@ [FALLBACK] compile-flags: -Zforce-intrinsic-fallback
5-
#![feature(core_intrinsics, funnel_shifts)]
5+
#![feature(core_intrinsics)]
66

77
// Check the effect of `-Zforce-intrinsic-fallback`.
88
//

0 commit comments

Comments
 (0)