Skip to content
Open
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
28 changes: 26 additions & 2 deletions compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,32 @@ fn codegen_float_intrinsic_call<'tcx>(
CValue::by_val(codegen_f16_f128::f32_to_f16(fx, ret_val), fx.layout_of(ty))
}
_ => {
let input_tys: Vec<_> = args.iter().map(|_| AbiParam::new(clif_ty)).collect();
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], args)[0];
let mut converted_args: Option<Vec<Value>> = None;
let mut call_args: &[Value] = args;
let mut call_name = name;
let mut call_ty = clif_ty;
let mut convert_back_to_f16 = false;

if clif_ty == types::F16 {
if let Some(f32_name) = name.strip_suffix("16") {
converted_args = Some(
args.iter().map(|&arg| codegen_f16_f128::f16_to_f32(fx, arg)).collect(),
);
call_args = converted_args.as_deref().unwrap();
call_name = f32_name;
call_ty = types::F32;
convert_back_to_f16 = true;
}
}

let input_tys: Vec<_> = call_args.iter().map(|_| AbiParam::new(call_ty)).collect();
let ret_val =
fx.lib_call(call_name, input_tys, vec![AbiParam::new(call_ty)], call_args)[0];
let ret_val = if convert_back_to_f16 {
codegen_f16_f128::f32_to_f16(fx, ret_val)
} else {
ret_val
};
CValue::by_val(ret_val, fx.layout_of(ty))
}
};
Expand Down
Loading
Loading