Skip to content
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

import simd_ intrinsics #137551

Merged
merged 4 commits into from
Mar 1, 2025
Merged
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
4 changes: 2 additions & 2 deletions library/core/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
/// `idx` must be in-bounds of the vector.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
pub const unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;

/// Extracts an element from a vector.
///
@@ -22,7 +22,7 @@ pub unsafe fn simd_insert<T, U>(_x: T, _idx: u32, _val: U) -> T;
/// `idx` must be in-bounds of the vector.
#[rustc_intrinsic]
#[rustc_nounwind]
pub unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;
pub const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;

/// Adds two simd vectors elementwise.
///
7 changes: 2 additions & 5 deletions tests/codegen/issues/issue-84268.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//@ compile-flags: -Copt-level=3 --crate-type=rlib
#![feature(intrinsics, repr_simd)]
#![feature(core_intrinsics, repr_simd)]

extern "rust-intrinsic" {
fn simd_fabs<T>(x: T) -> T;
fn simd_eq<T, U>(x: T, y: T) -> U;
}
use std::intrinsics::simd::{simd_eq, simd_fabs};

#[repr(simd)]
pub struct V([f32; 4]);
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-abs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_fabs;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_fabs<T>(x: T) -> T;
}

// CHECK-LABEL: @fabs_32x2
#[no_mangle]
pub unsafe fn fabs_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-ceil.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_ceil;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_ceil<T>(x: T) -> T;
}

// CHECK-LABEL: @ceil_32x2
#[no_mangle]
pub unsafe fn ceil_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-cos.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_fcos;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_fcos<T>(x: T) -> T;
}

// CHECK-LABEL: @fcos_32x2
#[no_mangle]
pub unsafe fn fcos_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-exp.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_fexp;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_fexp<T>(x: T) -> T;
}

// CHECK-LABEL: @exp_32x2
#[no_mangle]
pub unsafe fn exp_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-exp2.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_fexp2;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_fexp2<T>(x: T) -> T;
}

// CHECK-LABEL: @exp2_32x2
#[no_mangle]
pub unsafe fn exp2_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-floor.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_floor;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_floor<T>(x: T) -> T;
}

// CHECK-LABEL: @floor_32x2
#[no_mangle]
pub unsafe fn floor_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-fma.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_fma;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_fma<T>(x: T, b: T, c: T) -> T;
}

// CHECK-LABEL: @fma_32x2
#[no_mangle]
pub unsafe fn fma_32x2(a: f32x2, b: f32x2, c: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-fsqrt.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_fsqrt;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_fsqrt<T>(x: T) -> T;
}

// CHECK-LABEL: @fsqrt_32x2
#[no_mangle]
pub unsafe fn fsqrt_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-log.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_flog;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_flog<T>(x: T) -> T;
}

// CHECK-LABEL: @log_32x2
#[no_mangle]
pub unsafe fn log_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-log10.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_flog10;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_flog10<T>(x: T) -> T;
}

// CHECK-LABEL: @log10_32x2
#[no_mangle]
pub unsafe fn log10_32x2(a: f32x2) -> f32x2 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-log2.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_flog2;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_flog2<T>(x: T) -> T;
}

// CHECK-LABEL: @log2_32x2
#[no_mangle]
pub unsafe fn log2_32x2(a: f32x2) -> f32x2 {
10 changes: 3 additions & 7 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-minmax.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::{simd_fmax, simd_fmin};

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x4(pub [f32; 4]);

extern "rust-intrinsic" {
fn simd_fmin<T>(x: T, y: T) -> T;
fn simd_fmax<T>(x: T, y: T) -> T;
}

// CHECK-LABEL: @fmin
#[no_mangle]
pub unsafe fn fmin(a: f32x4, b: f32x4) -> f32x4 {
9 changes: 3 additions & 6 deletions tests/codegen/simd-intrinsic/simd-intrinsic-float-sin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//@ compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, intrinsics)]
#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]

use std::intrinsics::simd::simd_fsin;

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub [f32; 2]);
@@ -21,10 +22,6 @@ pub struct f32x8(pub [f32; 8]);
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub [f32; 16]);

extern "rust-intrinsic" {
fn simd_fsin<T>(x: T) -> T;
}

// CHECK-LABEL: @fsin_32x2
#[no_mangle]
pub unsafe fn fsin_32x2(a: f32x2) -> f32x2 {
Loading