Skip to content

Extend minicore with intrinsics and use it to replace #[rustc_intrinsic] in tests #140037

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
43 changes: 3 additions & 40 deletions tests/assembly/rust-abi-arg-attr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ add-core-stubs
//@ assembly-output: emit-asm
//@ revisions: riscv64 riscv64-zbb loongarch64
//@ compile-flags: -C opt-level=3
Expand All @@ -14,46 +15,8 @@
#![no_std]
#![no_core]

// FIXME: Migrate these code after PR #130693 is landed.
// vvvvv core

#[lang = "sized"]
trait Sized {}

#[lang = "copy"]
trait Copy {}

impl Copy for i8 {}
impl Copy for u32 {}
impl Copy for i32 {}

#[lang = "neg"]
trait Neg {
type Output;

fn neg(self) -> Self::Output;
}

impl Neg for i8 {
type Output = i8;

fn neg(self) -> Self::Output {
-self
}
}

#[lang = "Ordering"]
#[repr(i8)]
enum Ordering {
Less = -1,
Equal = 0,
Greater = 1,
}

#[rustc_intrinsic]
fn three_way_compare<T: Copy>(lhs: T, rhs: T) -> Ordering;

// ^^^^^ core
extern crate minicore;
use minicore::*;

// Reimplementation of function `{integer}::max`.
macro_rules! max {
Expand Down
3 changes: 0 additions & 3 deletions tests/assembly/simd-intrinsic-gather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ pub struct m64x4([i64; 4]);
#[repr(simd)]
pub struct pf64x4([*const f64; 4]);

#[rustc_intrinsic]
unsafe fn simd_gather<V, M, P>(values: V, mask: M, pointer: P) -> V;

// CHECK-LABEL: gather_f64x4
#[no_mangle]
pub unsafe extern "C" fn gather_f64x4(mask: m64x4, ptrs: pf64x4) -> f64x4 {
Expand Down
3 changes: 0 additions & 3 deletions tests/assembly/simd-intrinsic-mask-load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ pub struct f64x4([f64; 4]);
#[repr(simd)]
pub struct m64x4([i64; 4]);

#[rustc_intrinsic]
unsafe fn simd_masked_load<M, P, T>(mask: M, pointer: P, values: T) -> T;

// CHECK-LABEL: load_i8x16
#[no_mangle]
pub unsafe extern "C" fn load_i8x16(mask: m8x16, pointer: *const i8) -> i8x16 {
Expand Down
44 changes: 43 additions & 1 deletion tests/auxiliary/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
f16,
f128,
asm_experimental_arch,
unboxed_closures
unboxed_closures,
intrinsics
)]
#![allow(unused, improper_ctypes_definitions, internal_features)]
#![no_std]
Expand Down Expand Up @@ -191,3 +192,44 @@ impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b
trait Drop {
fn drop(&mut self);
}

#[lang = "neg"]
trait Neg: Sized {
type Output;

fn neg(self) -> Self::Output;
}

// Macro to implement Neg for a list of primitive numeric types
macro_rules! impl_neg_trait {
( $($ty:ty),* $(,)? ) => {
$(
impl Neg for $ty {
type Output = $ty;

fn neg(self) -> Self::Output {
-self
}
}
)*
}
}

impl_neg_trait!(isize, i8, i16, i32, i64, i128,);

#[lang = "Ordering"]
#[repr(i8)]
pub enum Ordering {
Less = -1,
Equal = 0,
Greater = 1,
}

#[rustc_intrinsic]
pub fn three_way_compare<T: Copy>(lhs: T, rhs: T) -> Ordering;

#[rustc_intrinsic]
pub unsafe fn simd_gather<V, M, P>(values: V, mask: M, pointer: P) -> V;

#[rustc_intrinsic]
pub unsafe fn simd_masked_load<M, P, T>(mask: M, pointer: P, values: T) -> T;
Loading