Skip to content

Commit 87c425b

Browse files
committed
Add basic support for f16/f128 values
1 parent f0fb19c commit 87c425b

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/abi/pass_mode.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ fn reg_to_abi_param(reg: Reg) -> AbiParam {
2222
(RegKind::Integer, 3..=4) => types::I32,
2323
(RegKind::Integer, 5..=8) => types::I64,
2424
(RegKind::Integer, 9..=16) => types::I128,
25+
(RegKind::Float, 2) => types::F16,
2526
(RegKind::Float, 4) => types::F32,
2627
(RegKind::Float, 8) => types::F64,
28+
(RegKind::Float, 16) => types::F128,
2729
(RegKind::Vector, size) => types::I8.by(u32::try_from(size).unwrap()).unwrap(),
2830
_ => unreachable!("{:?}", reg),
2931
};

src/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ pub(crate) fn scalar_to_clif_type(tcx: TyCtxt<'_>, scalar: Scalar) -> Type {
3333
Integer::I128 => types::I128,
3434
},
3535
Primitive::Float(float) => match float {
36-
Float::F16 => unimplemented!("f16_f128"),
36+
Float::F16 => types::F16,
3737
Float::F32 => types::F32,
3838
Float::F64 => types::F64,
39-
Float::F128 => unimplemented!("f16_f128"),
39+
Float::F128 => types::F128,
4040
},
4141
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
4242
Primitive::Pointer(_) => pointer_ty(tcx),
@@ -64,10 +64,10 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
6464
},
6565
ty::Char => types::I32,
6666
ty::Float(size) => match size {
67-
FloatTy::F16 => unimplemented!("f16_f128"),
67+
FloatTy::F16 => types::F16,
6868
FloatTy::F32 => types::F32,
6969
FloatTy::F64 => types::F64,
70-
FloatTy::F128 => unimplemented!("f16_f128"),
70+
FloatTy::F128 => types::F128,
7171
},
7272
ty::FnPtr(..) => pointer_ty(tcx),
7373
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {

src/value_and_place.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'tcx> CValue<'tcx> {
325325
const_val: ty::ScalarInt,
326326
) -> CValue<'tcx> {
327327
assert_eq!(const_val.size(), layout.size, "{:#?}: {:?}", const_val, layout);
328-
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};
328+
use cranelift_codegen::ir::immediates::{Ieee16, Ieee32, Ieee64, Ieee128};
329329

330330
let clif_ty = fx.clif_type(layout.ty).unwrap();
331331

@@ -346,12 +346,24 @@ impl<'tcx> CValue<'tcx> {
346346
let raw_val = const_val.size().truncate(const_val.to_bits(layout.size));
347347
fx.bcx.ins().iconst(clif_ty, raw_val as i64)
348348
}
349+
ty::Float(FloatTy::F16) => {
350+
fx.bcx.ins().f16const(Ieee16::with_bits(u16::try_from(const_val).unwrap()))
351+
}
349352
ty::Float(FloatTy::F32) => {
350353
fx.bcx.ins().f32const(Ieee32::with_bits(u32::try_from(const_val).unwrap()))
351354
}
352355
ty::Float(FloatTy::F64) => {
353356
fx.bcx.ins().f64const(Ieee64::with_bits(u64::try_from(const_val).unwrap()))
354357
}
358+
ty::Float(FloatTy::F128) => {
359+
let value = fx
360+
.bcx
361+
.func
362+
.dfg
363+
.constants
364+
.insert(Ieee128::with_bits(u128::try_from(const_val).unwrap()).into());
365+
fx.bcx.ins().f128const(value)
366+
}
355367
_ => panic!(
356368
"CValue::const_val for non bool/char/float/integer/pointer type {:?} is not allowed",
357369
layout.ty

0 commit comments

Comments
 (0)