Implement intrinsics {ctlz,cttz}{,_nonzero} and ctpop

This commit is contained in:
bjorn3 2018-08-08 14:39:46 +02:00
parent d4b6bce39c
commit c4705af4e2
4 changed files with 25 additions and 1 deletions

View File

@ -150,3 +150,7 @@ fn use_array(arr: [u8; 3]) -> u8 {
fn repeat_array() -> [u8; 3] {
[0; 3]
}
unsafe fn use_ctlz_nonzero(a: u16) -> u16 {
intrinsics::ctlz_nonzero(a)
}

View File

@ -139,6 +139,7 @@ pub mod intrinsics {
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
pub fn transmute<T, U>(e: T) -> U;
pub fn uninit<T>() -> T;
pub fn ctlz_nonzero<T>(x: T) -> T;
}
}

View File

@ -500,6 +500,24 @@ pub fn codegen_call<'a, 'tcx: 'a>(
let uninit_val = uninit_place.to_cvalue(fx);
ret.write_cvalue(fx, uninit_val);
}
"ctlz" | "ctlz_nonzero" => {
assert_eq!(args.len(), 1);
let arg = args[0].load_value(fx);
let res = CValue::ByVal(fx.bcx.ins().clz(arg), args[0].layout());
ret.write_cvalue(fx, res);
}
"cttz" | "cttz_nonzero" => {
assert_eq!(args.len(), 1);
let arg = args[0].load_value(fx);
let res = CValue::ByVal(fx.bcx.ins().clz(arg), args[0].layout());
ret.write_cvalue(fx, res);
}
"ctpop" => {
assert_eq!(args.len(), 1);
let arg = args[0].load_value(fx);
let res = CValue::ByVal(fx.bcx.ins().popcnt(arg), args[0].layout());
ret.write_cvalue(fx, res);
}
_ => fx
.tcx
.sess

View File

@ -359,7 +359,8 @@ fn trans_stmt<'a, 'tcx: 'a>(
UnOp::Not => fx.bcx.ins().bnot(val),
UnOp::Neg => match ty.sty {
TypeVariants::TyInt(_) => {
let zero = fx.bcx.ins().iconst(types::I64, 0);
let clif_ty = fx.cton_type(ty).unwrap();
let zero = fx.bcx.ins().iconst(clif_ty, 0);
fx.bcx.ins().isub(zero, val)
}
TypeVariants::TyFloat(_) => fx.bcx.ins().fneg(val),