Skip to content

Commit ee353b2

Browse files
committed
Make some helpers const
1 parent 999b963 commit ee353b2

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

crates/core_arch/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
f16,
3535
aarch64_unstable_target_feature,
3636
bigint_helper_methods,
37-
funnel_shifts
37+
funnel_shifts,
38+
const_trait_impl,
39+
const_cmp,
40+
const_convert
3841
)]
3942
#![cfg_attr(test, feature(test, abi_vectorcall, stdarch_internal))]
4043
#![deny(clippy::missing_inline_in_public_items)]

crates/core_arch/src/simd.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ macro_rules! simd_ty {
2323
}
2424
// FIXME: Workaround rust@60637
2525
#[inline(always)]
26-
pub(crate) fn splat(value: $elem_type) -> Self {
26+
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
27+
pub(crate) const fn splat(value: $elem_type) -> Self {
2728
#[derive(Copy, Clone)]
2829
#[repr(simd)]
2930
struct JustOne([$elem_type; 1]);
@@ -38,12 +39,12 @@ macro_rules! simd_ty {
3839
/// Use for testing only.
3940
// FIXME: Workaround rust@60637
4041
#[inline(always)]
41-
pub(crate) fn extract(&self, index: usize) -> $elem_type {
42+
pub(crate) const fn extract(&self, index: usize) -> $elem_type {
4243
self.as_array()[index]
4344
}
4445

4546
#[inline]
46-
pub(crate) fn as_array(&self) -> &[$elem_type; $len] {
47+
pub(crate) const fn as_array(&self) -> &[$elem_type; $len] {
4748
let simd_ptr: *const Self = self;
4849
let array_ptr: *const [$elem_type; $len] = simd_ptr.cast();
4950
// SAFETY: We can always read the prefix of a simd type as an array.
@@ -89,7 +90,8 @@ macro_rules! simd_m_ty {
8990

9091
// FIXME: Workaround rust@60637
9192
#[inline(always)]
92-
pub(crate) fn splat(value: bool) -> Self {
93+
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
94+
pub(crate) const fn splat(value: bool) -> Self {
9395
#[derive(Copy, Clone)]
9496
#[repr(simd)]
9597
struct JustOne([$elem_type; 1]);
@@ -100,7 +102,7 @@ macro_rules! simd_m_ty {
100102
}
101103

102104
#[inline]
103-
pub(crate) fn as_array(&self) -> &[$elem_type; $len] {
105+
pub(crate) const fn as_array(&self) -> &[$elem_type; $len] {
104106
let simd_ptr: *const Self = self;
105107
let array_ptr: *const [$elem_type; $len] = simd_ptr.cast();
106108
// SAFETY: We can always read the prefix of a simd type as an array.

crates/core_arch/src/x86/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,14 @@ macro_rules! as_transmute {
520520
($from:ty => $as_from:ident, $($as_to:ident -> $to:ident),* $(,)?) => {
521521
impl $from {$(
522522
#[inline]
523-
pub(crate) fn $as_to(self) -> crate::core_arch::simd::$to {
523+
pub(crate) const fn $as_to(self) -> crate::core_arch::simd::$to {
524524
unsafe { transmute(self) }
525525
}
526526
)*}
527527
$(
528528
impl crate::core_arch::simd::$to {
529529
#[inline]
530-
pub(crate) fn $as_from(self) -> $from {
530+
pub(crate) const fn $as_from(self) -> $from {
531531
unsafe { transmute(self) }
532532
}
533533
}

crates/core_arch/src/x86/test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ pub unsafe fn assert_eq_m128h(a: __m128h, b: __m128h) {
4848
// not actually an intrinsic but useful in various tests as we proted from
4949
// `i64x2::new` which is backwards from `_mm_set_epi64x`
5050
#[target_feature(enable = "sse2")]
51-
pub unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i {
51+
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
52+
pub const unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i {
5253
_mm_set_epi64x(b, a)
5354
}
5455

@@ -118,14 +119,14 @@ mod x86_polyfill {
118119
use crate::intrinsics::simd::*;
119120

120121
#[rustc_legacy_const_generics(2)]
121-
pub unsafe fn _mm_insert_epi64<const INDEX: i32>(a: __m128i, val: i64) -> __m128i {
122+
pub const unsafe fn _mm_insert_epi64<const INDEX: i32>(a: __m128i, val: i64) -> __m128i {
122123
static_assert_uimm_bits!(INDEX, 1);
123124
transmute(simd_insert!(a.as_i64x2(), INDEX as u32, val))
124125
}
125126

126127
#[target_feature(enable = "avx2")]
127128
#[rustc_legacy_const_generics(2)]
128-
pub unsafe fn _mm256_insert_epi64<const INDEX: i32>(a: __m256i, val: i64) -> __m256i {
129+
pub const unsafe fn _mm256_insert_epi64<const INDEX: i32>(a: __m256i, val: i64) -> __m256i {
129130
static_assert_uimm_bits!(INDEX, 2);
130131
transmute(simd_insert!(a.as_i64x4(), INDEX as u32, val))
131132
}

0 commit comments

Comments
 (0)