mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
Use bitcast to transmute where possible
This commit is contained in:
parent
9cf1bcea5c
commit
dfb5d16fb3
@ -631,12 +631,29 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
|||||||
ret.write_cvalue(fx, CValue::by_val(res, base.layout()));
|
ret.write_cvalue(fx, CValue::by_val(res, base.layout()));
|
||||||
};
|
};
|
||||||
|
|
||||||
transmute, <src_ty, dst_ty> (c from) {
|
transmute, (c from) {
|
||||||
assert_eq!(from.layout().ty, src_ty);
|
assert_eq!(from.layout().size, ret.layout().size);
|
||||||
let (addr, meta) = from.force_stack(fx);
|
if from.layout().ty.kind == ret.layout().ty.kind {
|
||||||
assert!(meta.is_none());
|
ret.write_cvalue(fx, from);
|
||||||
let dst_layout = fx.layout_of(dst_ty);
|
} else if let (Some(src_ty), Some(dst_ty)) = (fx.clif_type(from.layout().ty), fx.clif_type(ret.layout().ty)) {
|
||||||
ret.write_cvalue(fx, CValue::by_ref(addr, dst_layout))
|
let from = from.load_scalar(fx);
|
||||||
|
let val = match (src_ty, dst_ty) {
|
||||||
|
(_, _) if src_ty == dst_ty => from,
|
||||||
|
(types::I32, types::F32) | (types::F32, types::I32)
|
||||||
|
| (types::I64, types::F64) | (types::F64, types::I64) => {
|
||||||
|
fx.bcx.ins().bitcast(dst_ty, from)
|
||||||
|
}
|
||||||
|
(_, _) if src_ty.is_vector() && dst_ty.is_vector() => {
|
||||||
|
fx.bcx.ins().raw_bitcast(dst_ty, from)
|
||||||
|
}
|
||||||
|
_ => unreachable!("{:?} -> {:?}", src_ty, dst_ty),
|
||||||
|
};
|
||||||
|
ret.write_cvalue(fx, CValue::by_val(val, ret.layout()));
|
||||||
|
} else {
|
||||||
|
let (addr, meta) = from.force_stack(fx);
|
||||||
|
assert!(meta.is_none());
|
||||||
|
ret.write_cvalue(fx, CValue::by_ref(addr, ret.layout()));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
write_bytes, (c dst, v val, v count) {
|
write_bytes, (c dst, v val, v count) {
|
||||||
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap().ty;
|
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap().ty;
|
||||||
|
Loading…
Reference in New Issue
Block a user