Skip to content

Commit abd73fd

Browse files
committed
linker issue fix
1 parent 4aed46d commit abd73fd

File tree

1 file changed

+23
-2
lines changed
  • compiler/rustc_codegen_cranelift/src/intrinsics

1 file changed

+23
-2
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,29 @@ fn codegen_float_intrinsic_call<'tcx>(
504504
CValue::by_val(codegen_f16_f128::f32_to_f16(fx, ret_val), fx.layout_of(ty))
505505
}
506506
_ => {
507-
let input_tys: Vec<_> = args.iter().map(|_| AbiParam::new(clif_ty)).collect();
508-
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], args)[0];
507+
let mut converted_args: Option<Vec<Value>> = None;
508+
let mut call_args: &[Value] = args;
509+
let mut call_name = name;
510+
let mut call_ty = clif_ty;
511+
let mut convert_back_to_f16 = false;
512+
513+
if clif_ty == types::F16 {
514+
if let Some(f32_name) = name.strip_suffix("16") {
515+
converted_args = Some(
516+
args.iter().map(|&arg| codegen_f16_f128::f16_to_f32(fx, arg)).collect(),
517+
);
518+
call_args = converted_args.as_deref().unwrap();
519+
call_name = f32_name;
520+
call_ty = types::F32;
521+
convert_back_to_f16 = true;
522+
}
523+
}
524+
525+
let input_tys: Vec<_> = call_args.iter().map(|_| AbiParam::new(call_ty)).collect();
526+
let ret_val =
527+
fx.lib_call(call_name, input_tys, vec![AbiParam::new(call_ty)], call_args)[0];
528+
let ret_val =
529+
if convert_back_to_f16 { codegen_f16_f128::f32_to_f16(fx, ret_val) } else { ret_val };
509530
CValue::by_val(ret_val, fx.layout_of(ty))
510531
}
511532
};

0 commit comments

Comments
 (0)