Skip to content

add the trap instrinsic #571

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 4 commits into from
Nov 11, 2018
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
10 changes: 10 additions & 0 deletions coresimd/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ pub use self::neon::*;

mod crypto;
pub use self::crypto::*;

#[cfg(test)]
use stdsimd_test::assert_instr;

/// Generates the trap instruction `BRK 1`
#[cfg_attr(test, assert_instr(brk))]
#[inline]
pub unsafe fn brk() -> ! {
::_core::intrinsics::abort()
}
11 changes: 11 additions & 0 deletions coresimd/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ mod neon;
dox
))]
pub use self::neon::*;

#[cfg(test)]
use stdsimd_test::assert_instr;

/// Generates the trap instruction `UDF`
#[cfg(target_arch = "arm")]
#[cfg_attr(test, assert_instr(udf))]
#[inline]
pub unsafe fn udf() -> ! {
::_core::intrinsics::abort()
}
10 changes: 10 additions & 0 deletions coresimd/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@

mod msa;
pub use self::msa::*;

#[cfg(test)]
use stdsimd_test::assert_instr;

/// Generates the trap instruction `BREAK`
#[cfg_attr(test, assert_instr(break))]
#[inline]
pub unsafe fn break_() -> ! {
::_core::intrinsics::abort()
}
6 changes: 6 additions & 0 deletions coresimd/nvptx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ pub unsafe fn _thread_idx_y() -> i32 {
pub unsafe fn _thread_idx_z() -> i32 {
thread_idx_z()
}

/// Generates the trap instruction `TRAP`
#[inline]
pub unsafe fn trap() -> ! {
::_core::intrinsics::abort()
}
10 changes: 10 additions & 0 deletions coresimd/powerpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ pub use self::altivec::*;

mod vsx;
pub use self::vsx::*;

#[cfg(test)]
use stdsimd_test::assert_instr;

/// Generates the trap instruction `TRAP`
#[cfg_attr(test, assert_instr(trap))]
#[inline]
pub unsafe fn trap() -> ! {
::_core::intrinsics::abort()
}
7 changes: 7 additions & 0 deletions coresimd/wasm32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ pub unsafe fn grow_memory(delta: i32) -> i32 {

pub mod atomic;
pub mod memory;

/// Generates the trap instruction `UNREACHABLE`
#[cfg_attr(test, assert_instr(unreachable))]
#[inline]
pub unsafe fn unreachable() -> ! {
::_core::intrinsics::abort()
}
10 changes: 10 additions & 0 deletions coresimd/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,13 @@ pub use self::rdrand::*;

mod sha;
pub use self::sha::*;

#[cfg(test)]
use stdsimd_test::assert_instr;

/// Generates the trap instruction `UD2`
#[cfg_attr(test, assert_instr(ud2))]
#[inline]
pub unsafe fn ud2() -> ! {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stdsimd-verify crate (https://github.com/rust-lang-nursery/stdsimd/tree/master/crates/stdsimd-verify) needs to be updated to support bottom.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

::_core::intrinsics::abort()
}
3 changes: 2 additions & 1 deletion crates/stdsimd-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn to_type(t: &syn::Type) -> proc_macro2::TokenStream {
"u64" => quote! { &U64 },
"u8" => quote! { &U8 },
"CpuidResult" => quote! { &CPUID },
s => panic!("unspported type: {}", s),
s => panic!("unspported type: \"{}\"", s),
}
}
syn::Type::Ptr(syn::TypePtr { ref elem, .. })
Expand All @@ -124,6 +124,7 @@ fn to_type(t: &syn::Type) -> proc_macro2::TokenStream {
syn::Type::Slice(_) => panic!("unsupported slice"),
syn::Type::Array(_) => panic!("unsupported array"),
syn::Type::Tuple(_) => quote! { &TUPLE },
syn::Type::Never(_) => quote! { &NEVER },
_ => panic!("unsupported type"),
}
}
Expand Down
24 changes: 16 additions & 8 deletions crates/stdsimd-verify/tests/x86-intel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static M256D: Type = Type::M256D;

static TUPLE: Type = Type::Tuple;
static CPUID: Type = Type::CpuidResult;
static NEVER: Type = Type::Never;

#[derive(Debug)]
enum Type {
Expand All @@ -73,6 +74,7 @@ enum Type {
M256I,
Tuple,
CpuidResult,
Never,
}

x86_functions!(static FUNCTIONS);
Expand Down Expand Up @@ -135,14 +137,20 @@ fn verify_all_signatures() {
let mut all_valid = true;
'outer: for rust in FUNCTIONS {
match rust.name {
// These aren't defined by Intel but they're defined by what
// appears to be all other compilers. For more
// information see rust-lang-nursery/stdsimd#307, and
// otherwise these signatures have all been manually
// verified.
"__readeflags" | "__writeeflags" | "__cpuid_count" | "__cpuid"
| "__get_cpuid_max" => continue,

// These aren't defined by Intel but they're defined by what appears
// to be all other compilers. For more information see
// rust-lang-nursery/stdsimd#307, and otherwise these signatures
// have all been manually verified.
"__readeflags" |
"__writeeflags" |
"__cpuid_count" |
"__cpuid" |
"__get_cpuid_max" |
// The UD2 intrinsic is not defined by Intel, but it was agreed on
// in the RFC Issue 2512:
// https://github.com/rust-lang/rfcs/issues/2512
"ud2"
=> continue,
_ => {}
}

Expand Down