Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7134a49
Use ordered reduction intrinsics for integer reductions
sayantn Nov 10, 2025
c683ffc
Make some helpers `const`
sayantn Sep 14, 2025
a370d9a
Make `abm`, `bmi1`, `bmi2`, `bswap` and `tbm` functions const
sayantn Sep 23, 2025
7c6b17e
Make `sse` functions const
sayantn Sep 23, 2025
7b0f0c2
Make `sse2` functions const
sayantn Sep 23, 2025
8472fe5
Make `sse3` functions const
sayantn Sep 23, 2025
66da7ef
Make `ssse3` functions const
sayantn Sep 23, 2025
8c10d3e
Make `sse4.1` functions const
sayantn Sep 23, 2025
9e75ab0
Make `sse4.2` functions const
sayantn Sep 23, 2025
23accad
Make `avx` functions const
sayantn Sep 23, 2025
67408fa
Make `avx2` functions const
sayantn Sep 23, 2025
2d362c7
Make `fma` functions const
sayantn Oct 1, 2025
c7b4ffd
Make `avx512f` functions const
sayantn Sep 23, 2025
ade884d
Make `avx512bw` functions const
sayantn Sep 23, 2025
5153025
Make `avx512cd` functions const
sayantn Sep 23, 2025
6e117c0
Make `avx512dq` functions const
sayantn Sep 23, 2025
2af33f3
Make `avx512vbmi2` functions const
sayantn Sep 23, 2025
69285e5
Make `avx512bitalg` functions const
sayantn Sep 23, 2025
99ec475
Make `avx512vpopcntdq` functions const
sayantn Sep 23, 2025
b912c6e
Make `avx512fp16` functions const
sayantn Sep 23, 2025
fa55d7d
Modify `#[simd_test]` to enable const-testing
sayantn Nov 20, 2025
391dc70
Make some test helpers const
sayantn Nov 23, 2025
e1572c5
Add const tests for `abm`, `bmi1`, `bmi2`, `bswap` and `tbm`
sayantn Nov 23, 2025
b451207
Add const tests for `sse`
sayantn Nov 23, 2025
1638f94
Add const tests for `sse2`
sayantn Nov 23, 2025
cb352e9
Add const tests for `sse3`
sayantn Nov 23, 2025
8910ea8
Add const tests for `ssse3`
sayantn Nov 23, 2025
0a8d652
Add const tests for `sse4.1`
sayantn Nov 23, 2025
3fe3188
Add const tests for `sse4.2`
sayantn Nov 23, 2025
8c83435
Add const tests for `avx`
sayantn Nov 23, 2025
3ac22a3
Add const tests for `avx2`
sayantn Nov 23, 2025
9aecd92
Add const tests for `fma`
sayantn Nov 23, 2025
e5765bc
Add const tests for `avx512f`
sayantn Nov 23, 2025
0846143
Add const tests for `avx512bw`
sayantn Nov 23, 2025
7d9fc28
Add const tests for `avx512cd`
sayantn Nov 23, 2025
4cf1840
Add const tests for `avx512dq`
sayantn Nov 23, 2025
348e1b5
Add const tests for `avx512vbmi2`
sayantn Nov 23, 2025
f3fd5b0
Add const tests for `avx512bitalg`
sayantn Nov 23, 2025
0df3968
Add const tests for `avx512vpopcntdq`
sayantn Nov 23, 2025
58c2424
Add const tests for `avx512fp16`
sayantn Nov 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/core_arch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
aarch64_unstable_target_feature,
bigint_helper_methods,
funnel_shifts,
avx10_target_feature
avx10_target_feature,
const_trait_impl,
const_cmp,
const_eval_select
)]
#![cfg_attr(test, feature(test, abi_vectorcall, stdarch_internal))]
#![deny(clippy::missing_inline_in_public_items)]
Expand Down
5 changes: 5 additions & 0 deletions crates/core_arch/src/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#[macro_use]
mod macros;

#[cfg(test)]
mod test;
#[cfg(test)]
use test::assert_eq_const;

#[cfg(any(target_arch = "riscv32", target_arch = "riscv64", doc))]
mod riscv_shared;

Expand Down
18 changes: 11 additions & 7 deletions crates/core_arch/src/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ macro_rules! simd_ty {
}
// FIXME: Workaround rust@60637
#[inline(always)]
pub(crate) fn splat(value: $elem_type) -> Self {
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
pub(crate) const fn splat(value: $elem_type) -> Self {
#[derive(Copy, Clone)]
#[repr(simd)]
struct JustOne([$elem_type; 1]);
Expand All @@ -38,12 +39,12 @@ macro_rules! simd_ty {
/// Use for testing only.
// FIXME: Workaround rust@60637
#[inline(always)]
pub(crate) fn extract(&self, index: usize) -> $elem_type {
pub(crate) const fn extract(&self, index: usize) -> $elem_type {
self.as_array()[index]
}

#[inline]
pub(crate) fn as_array(&self) -> &[$elem_type; $len] {
pub(crate) const fn as_array(&self) -> &[$elem_type; $len] {
let simd_ptr: *const Self = self;
let array_ptr: *const [$elem_type; $len] = simd_ptr.cast();
// SAFETY: We can always read the prefix of a simd type as an array.
Expand All @@ -53,7 +54,8 @@ macro_rules! simd_ty {
}
}

impl core::cmp::PartialEq for $id {
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
const impl core::cmp::PartialEq for $id {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.as_array() == other.as_array()
Expand Down Expand Up @@ -89,7 +91,8 @@ macro_rules! simd_m_ty {

// FIXME: Workaround rust@60637
#[inline(always)]
pub(crate) fn splat(value: bool) -> Self {
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
pub(crate) const fn splat(value: bool) -> Self {
#[derive(Copy, Clone)]
#[repr(simd)]
struct JustOne([$elem_type; 1]);
Expand All @@ -100,7 +103,7 @@ macro_rules! simd_m_ty {
}

#[inline]
pub(crate) fn as_array(&self) -> &[$elem_type; $len] {
pub(crate) const fn as_array(&self) -> &[$elem_type; $len] {
let simd_ptr: *const Self = self;
let array_ptr: *const [$elem_type; $len] = simd_ptr.cast();
// SAFETY: We can always read the prefix of a simd type as an array.
Expand All @@ -110,7 +113,8 @@ macro_rules! simd_m_ty {
}
}

impl core::cmp::PartialEq for $id {
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
const impl core::cmp::PartialEq for $id {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.as_array() == other.as_array()
Expand Down
25 changes: 25 additions & 0 deletions crates/core_arch/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::fmt::Debug;

#[track_caller]
#[allow(unused)]
pub(crate) fn assert_eq_rt<T: PartialEq + Debug>(a: &T, b: &T) {
std::assert_eq!(a, b)
}

#[allow(unused)]
macro_rules! assert_eq_const {
($a:expr, $b:expr $(,)?) => {{
#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
const fn assert_eq_ct<T: [const] PartialEq>(a: &T, b: &T) {
assert!(a == b, concat!("`", stringify!($a), "` != `", stringify!($b), "`"));
}

$crate::intrinsics::const_eval_select((&$a, &$b), assert_eq_ct, $crate::core_arch::test::assert_eq_rt);
}};
($a:expr, $b:expr, $($t:tt)+) => {
::std::assert_eq!($a, $b, $($t)+)
};
}

pub(crate) use assert_eq_const;
11 changes: 7 additions & 4 deletions crates/core_arch/src/x86/abm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use stdarch_test::assert_instr;
#[target_feature(enable = "lzcnt")]
#[cfg_attr(test, assert_instr(lzcnt))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub fn _lzcnt_u32(x: u32) -> u32 {
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
pub const fn _lzcnt_u32(x: u32) -> u32 {
x.leading_zeros()
}

Expand All @@ -40,23 +41,25 @@ pub fn _lzcnt_u32(x: u32) -> u32 {
#[target_feature(enable = "popcnt")]
#[cfg_attr(test, assert_instr(popcnt))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub fn _popcnt32(x: i32) -> i32 {
#[rustc_const_unstable(feature = "stdarch_const_intrinsics", issue = "none")]
pub const fn _popcnt32(x: i32) -> i32 {
x.count_ones() as i32
}

#[cfg(test)]
mod tests {
use crate::core_arch::assert_eq_const as assert_eq;
use stdarch_test::simd_test;

use crate::core_arch::x86::*;

#[simd_test(enable = "lzcnt")]
unsafe fn test_lzcnt_u32() {
const unsafe fn test_lzcnt_u32() {
assert_eq!(_lzcnt_u32(0b0101_1010), 25);
}

#[simd_test(enable = "popcnt")]
unsafe fn test_popcnt32() {
const unsafe fn test_popcnt32() {
assert_eq!(_popcnt32(0b0101_1010), 4);
}
}
Loading