Skip to content

Commit 6ecd38c

Browse files
committed
Add f16-f128 support for SIMD intrinsics
- refactor float rounding intrinsics a bit
1 parent 6491ae4 commit 6ecd38c

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
989989
interp_ok(())
990990
}
991991

992+
fn float_round<F>(
993+
&mut self,
994+
x: Scalar<M::Provenance>,
995+
mode: rustc_apfloat::Round,
996+
) -> InterpResult<'tcx, F>
997+
where
998+
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F>,
999+
{
1000+
let x: F = x.to_float()?;
1001+
let res = x.round_to_integral(mode).value;
1002+
let res = self.adjust_nan(res, &[x]);
1003+
interp_ok(res)
1004+
}
1005+
9921006
fn float_round_intrinsic<F>(
9931007
&mut self,
9941008
args: &[OpTy<'tcx, M::Provenance>],
@@ -998,9 +1012,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
9981012
where
9991013
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
10001014
{
1001-
let x: F = self.read_scalar(&args[0])?.to_float()?;
1002-
let res = x.round_to_integral(mode).value;
1003-
let res = self.adjust_nan(res, &[x]);
1015+
let res = self.float_round::<F>(self.read_scalar(&args[0])?, mode)?;
10041016
self.write_scalar(res, dest)?;
10051017
interp_ok(())
10061018
}

compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
119119
let op = op.to_scalar();
120120
// "Bitwise" operation, no NaN adjustments
121121
match float_ty {
122-
FloatTy::F16 => unimplemented!("f16_f128"),
122+
FloatTy::F16 => Scalar::from_f16(op.to_f16()?.abs()),
123123
FloatTy::F32 => Scalar::from_f32(op.to_f32()?.abs()),
124124
FloatTy::F64 => Scalar::from_f64(op.to_f64()?.abs()),
125-
FloatTy::F128 => unimplemented!("f16_f128"),
125+
FloatTy::F128 => Scalar::from_f128(op.to_f128()?.abs()),
126126
}
127127
}
128128
Op::Round(rounding) => {
@@ -133,21 +133,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
133133
intrinsic_name
134134
)
135135
};
136+
let op = op.to_scalar();
136137
match float_ty {
137-
FloatTy::F16 => unimplemented!("f16_f128"),
138-
FloatTy::F32 => {
139-
let f = op.to_scalar().to_f32()?;
140-
let res = f.round_to_integral(rounding).value;
141-
let res = self.adjust_nan(res, &[f]);
142-
Scalar::from_f32(res)
143-
}
144-
FloatTy::F64 => {
145-
let f = op.to_scalar().to_f64()?;
146-
let res = f.round_to_integral(rounding).value;
147-
let res = self.adjust_nan(res, &[f]);
148-
Scalar::from_f64(res)
149-
}
150-
FloatTy::F128 => unimplemented!("f16_f128"),
138+
FloatTy::F16 => Scalar::from_f16(self.float_round(op, rounding)?),
139+
FloatTy::F32 => Scalar::from_f32(self.float_round(op, rounding)?),
140+
FloatTy::F64 => Scalar::from_f64(self.float_round(op, rounding)?),
141+
FloatTy::F128 => Scalar::from_f128(self.float_round(op, rounding)?),
151142
}
152143
}
153144
Op::Numeric(name) => {

0 commit comments

Comments
 (0)