Skip to content

avx512_target_feature is now stable on nightly #1802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion crates/core_arch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
sse4a_target_feature,
riscv_target_feature,
arm_target_feature,
avx512_target_feature,
mips_target_feature,
powerpc_target_feature,
s390x_target_feature,
Expand Down
6 changes: 3 additions & 3 deletions crates/core_arch/src/powerpc/altivec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ mod sealed {
#[target_feature(enable = "altivec")]
#[cfg_attr(test, assert_instr($instr))]
pub unsafe fn $fun(a: isize, b: *const $ty) -> t_t_l!($ty) {
let addr = (b as *const i8).offset(a);
let addr = b.byte_offset(a).cast::<i8>();
transmute($instr(addr))
}

Expand Down Expand Up @@ -4785,7 +4785,7 @@ mod tests {
unsafe fn test_vec_lde_u16() {
let pat = [u16x8::new(0, 1, 2, 3, 4, 5, 6, 7)];
for off in 0..8 {
let v: u16x8 = transmute(vec_lde(off * 2, pat.as_ptr() as *const u8));
let v: u16x8 = transmute(vec_lde(off * 2, pat.as_ptr() as *const u16));
assert_eq!(off as u16, v.extract(off as _));
}
}
Expand All @@ -4794,7 +4794,7 @@ mod tests {
unsafe fn test_vec_lde_u32() {
let pat = [u32x4::new(0, 1, 2, 3)];
for off in 0..4 {
let v: u32x4 = transmute(vec_lde(off * 4, pat.as_ptr() as *const u8));
let v: u32x4 = transmute(vec_lde(off * 4, pat.as_ptr() as *const u32));
assert_eq!(off as u32, v.extract(off as _));
}
}
Expand Down
13 changes: 12 additions & 1 deletion crates/intrinsic-test/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,25 @@ impl Intrinsic {
constraints
};

// the `intrinsic-test` crate compares the output of C and Rust intrinsics. Currently, It uses
// a string representation of the output value to compare. In C, f16 values are currently printed
// as hexadecimal integers. Since https://github.com/rust-lang/rust/pull/127013, rust does print
// them as decimal floating point values. To keep the intrinsics tests working, for now, format
// vectors containing f16 values like C prints them.
let return_value = match self.results.kind() {
TypeKind::Float if self.results.inner_size() == 16 => "debug_f16(__return_value)",
_ => "format_args!(\"{__return_value:.150?}\")",
};

let indentation2 = indentation.nested();
let indentation3 = indentation2.nested();

format!(
"{indentation}for i in 0..{passes} {{\n\
{indentation2}unsafe {{\n\
{loaded_args}\
{indentation3}let __return_value = {intrinsic_call}{const}({args});\n\
{indentation3}println!(\"Result {additional}-{{}}: {{:.150?}}\", i + 1, __return_value);\n\
{indentation3}println!(\"Result {additional}-{{}}: {{:?}}\", i + 1, {return_value});\n\
{indentation2}}}\n\
{indentation}}}",
loaded_args = self.arguments.load_values_rust(indentation3),
Expand Down
90 changes: 90 additions & 0 deletions crates/intrinsic-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,99 @@ fn generate_rust_program(notices: &str, intrinsic: &Intrinsic, target: &str) ->
.filter(|i| i.has_constraint())
.collect_vec();

// Format f16 values (and vectors containing them) in a way that is consistent with C.
let f16_formatting = r#"
/// Used to continue `Debug`ging SIMD types as `MySimd(1, 2, 3, 4)`, as they
/// were before moving to array-based simd.
#[inline]
fn debug_simd_finish<T: core::fmt::Debug, const N: usize>(
formatter: &mut core::fmt::Formatter<'_>,
type_name: &str,
array: &[T; N],
) -> core::fmt::Result {
core::fmt::Formatter::debug_tuple_fields_finish(
formatter,
type_name,
&core::array::from_fn::<&dyn core::fmt::Debug, N, _>(|i| &array[i]),
)
}

#[repr(transparent)]
struct Hex<T>(T);

impl<T: DebugHexF16> core::fmt::Debug for Hex<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
<T as DebugHexF16>::fmt(&self.0, f)
}
}

fn debug_f16<T: DebugHexF16>(x: T) -> impl core::fmt::Debug {
Hex(x)
}

trait DebugHexF16 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result;
}

impl DebugHexF16 for f16 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:#06x?}", self.to_bits())
}
}

impl DebugHexF16 for float16x4_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let array = unsafe { core::mem::transmute::<_, [Hex<f16>; 4]>(*self) };
debug_simd_finish(f, "float16x4_t", &array)
}
}

impl DebugHexF16 for float16x8_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let array = unsafe { core::mem::transmute::<_, [Hex<f16>; 8]>(*self) };
debug_simd_finish(f, "float16x8_t", &array)
}
}

impl DebugHexF16 for float16x4x2_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
debug_simd_finish(f, "float16x4x2_t", &[Hex(self.0), Hex(self.1)])
}
}
impl DebugHexF16 for float16x4x3_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
debug_simd_finish(f, "float16x4x3_t", &[Hex(self.0), Hex(self.1), Hex(self.2)])
}
}
impl DebugHexF16 for float16x4x4_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
debug_simd_finish(f, "float16x4x4_t", &[Hex(self.0), Hex(self.1), Hex(self.2), Hex(self.3)])
}
}

impl DebugHexF16 for float16x8x2_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
debug_simd_finish(f, "float16x8x2_t", &[Hex(self.0), Hex(self.1)])
}
}
impl DebugHexF16 for float16x8x3_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
debug_simd_finish(f, "float16x8x3_t", &[Hex(self.0), Hex(self.1), Hex(self.2)])
}
}
impl DebugHexF16 for float16x8x4_t {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
debug_simd_finish(f, "float16x8x4_t", &[Hex(self.0), Hex(self.1), Hex(self.2), Hex(self.3)])
}
}
"#;

let indentation = Indentation::default();
format!(
r#"{notices}#![feature(simd_ffi)]
#![feature(link_llvm_intrinsics)]
#![feature(f16)]
#![feature(fmt_helpers_for_derive)]
#![cfg_attr(target_arch = "arm", feature(stdarch_arm_neon_intrinsics))]
#![cfg_attr(target_arch = "arm", feature(stdarch_aarch32_crc32))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_fcma))]
Expand All @@ -207,6 +295,8 @@ fn generate_rust_program(notices: &str, intrinsic: &Intrinsic, target: &str) ->
#![allow(non_upper_case_globals)]
use core_arch::arch::{target_arch}::*;

{f16_formatting}

fn main() {{
{arglists}
{passes}
Expand Down
1 change: 0 additions & 1 deletion crates/std_detect/tests/x86-specific.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(internal_features)]
#![feature(
stdarch_internal,
avx512_target_feature,
sha512_sm_x86,
x86_amx_intrinsics,
xop_target_feature,
Expand Down
1 change: 0 additions & 1 deletion examples/connect5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
//! each move.

#![allow(internal_features)]
#![feature(avx512_target_feature)]
#![cfg_attr(target_arch = "x86", feature(stdarch_x86_avx512, stdarch_internal))]
#![cfg_attr(target_arch = "x86_64", feature(stdarch_x86_avx512, stdarch_internal))]
#![feature(stmt_expr_attributes)]
Expand Down