Auto merge of #3556 - RalfJung:intrinsics, r=RalfJung
move intrinsics tests into dedicated folder And separate them from "shims" (which are for extern functions we link against).
This commit is contained in:
commit
9d4eea1369
@ -79,6 +79,7 @@ mod concurrency;
|
||||
mod diagnostics;
|
||||
mod eval;
|
||||
mod helpers;
|
||||
mod intrinsics;
|
||||
mod machine;
|
||||
mod mono_hash_map;
|
||||
mod operator;
|
||||
@ -95,9 +96,9 @@ pub use rustc_const_eval::interpret::*;
|
||||
#[doc(no_inline)]
|
||||
pub use rustc_const_eval::interpret::{self, AllocMap, PlaceTy, Provenance as _};
|
||||
|
||||
pub use crate::intrinsics::EvalContextExt as _;
|
||||
pub use crate::shims::env::{EnvVars, EvalContextExt as _};
|
||||
pub use crate::shims::foreign_items::{DynSym, EvalContextExt as _};
|
||||
pub use crate::shims::intrinsics::EvalContextExt as _;
|
||||
pub use crate::shims::os_str::EvalContextExt as _;
|
||||
pub use crate::shims::panic::{CatchUnwindData, EvalContextExt as _};
|
||||
pub use crate::shims::time::EvalContextExt as _;
|
||||
|
@ -893,6 +893,38 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||
throw_unsup_format!("unsupported `llvm.prefetch` type argument: {}", ty);
|
||||
}
|
||||
}
|
||||
// Used to implement the x86 `_mm{,256,512}_popcnt_epi{8,16,32,64}` and wasm
|
||||
// `{i,u}8x16_popcnt` functions.
|
||||
name if name.starts_with("llvm.ctpop.v") => {
|
||||
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
|
||||
|
||||
let (op, op_len) = this.operand_to_simd(op)?;
|
||||
let (dest, dest_len) = this.mplace_to_simd(dest)?;
|
||||
|
||||
assert_eq!(dest_len, op_len);
|
||||
|
||||
for i in 0..dest_len {
|
||||
let op = this.read_immediate(&this.project_index(&op, i)?)?;
|
||||
// Use `to_uint` to get a zero-extended `u128`. Those
|
||||
// extra zeros will not affect `count_ones`.
|
||||
let res = op.to_scalar().to_uint(op.layout.size)?.count_ones();
|
||||
|
||||
this.write_scalar(
|
||||
Scalar::from_uint(res, op.layout.size),
|
||||
&this.project_index(&dest, i)?,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Target-specific shims
|
||||
name if name.starts_with("llvm.x86.")
|
||||
&& (this.tcx.sess.target.arch == "x86"
|
||||
|| this.tcx.sess.target.arch == "x86_64") =>
|
||||
{
|
||||
return shims::x86::EvalContextExt::emulate_x86_intrinsic(
|
||||
this, link_name, abi, args, dest,
|
||||
);
|
||||
}
|
||||
// FIXME: Move these to an `arm` submodule.
|
||||
"llvm.aarch64.isb" if this.tcx.sess.target.arch == "aarch64" => {
|
||||
let [arg] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
|
||||
@ -923,38 +955,6 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
// Used to implement the x86 `_mm{,256,512}_popcnt_epi{8,16,32,64}` and wasm
|
||||
// `{i,u}8x16_popcnt` functions.
|
||||
name if name.starts_with("llvm.ctpop.v") => {
|
||||
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
|
||||
|
||||
let (op, op_len) = this.operand_to_simd(op)?;
|
||||
let (dest, dest_len) = this.mplace_to_simd(dest)?;
|
||||
|
||||
assert_eq!(dest_len, op_len);
|
||||
|
||||
for i in 0..dest_len {
|
||||
let op = this.read_immediate(&this.project_index(&op, i)?)?;
|
||||
// Use `to_uint` to get a zero-extended `u128`. Those
|
||||
// extra zeros will not affect `count_ones`.
|
||||
let res = op.to_scalar().to_uint(op.layout.size)?.count_ones();
|
||||
|
||||
this.write_scalar(
|
||||
Scalar::from_uint(res, op.layout.size),
|
||||
&this.project_index(&dest, i)?,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
name if name.starts_with("llvm.x86.")
|
||||
&& (this.tcx.sess.target.arch == "x86"
|
||||
|| this.tcx.sess.target.arch == "x86_64") =>
|
||||
{
|
||||
return shims::x86::EvalContextExt::emulate_x86_intrinsic(
|
||||
this, link_name, abi, args, dest,
|
||||
);
|
||||
}
|
||||
|
||||
// Platform-specific shims
|
||||
_ =>
|
||||
return match this.tcx.sess.target.os.as_ref() {
|
||||
|
@ -5,7 +5,6 @@ mod backtrace;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod ffi_support;
|
||||
pub mod foreign_items;
|
||||
pub mod intrinsics;
|
||||
pub mod unix;
|
||||
pub mod windows;
|
||||
mod x86;
|
||||
|
Loading…
x
Reference in New Issue
Block a user