Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f4d142

Browse files
Rollup merge ofrust-lang#127032 - tgross35:f16-f128-const-eval-cast, r=oli-obk
Enable const casting for `f16` and `f128`I have an open PR to the Miri repo adding tests for this behaviorrust-lang/miri#3688, but that unfortunately hits the ICE path here. The changes seem reasonably low risk that it might be okay to merge separately from the tests, and I tested the result locally against an older version ofrust-lang/miri#3688.Cc `````@RalfJung`````
2 parentsabc2c92 +648cb16 commit5f4d142

File tree

1 file changed

+17
-10
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+17
-10
lines changed

‎compiler/rustc_const_eval/src/interpret/cast.rs‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::assert_matches::assert_matches;
22

3-
use rustc_apfloat::ieee::{Double,Single};
3+
use rustc_apfloat::ieee::{Double,Half,Quad,Single};
44
use rustc_apfloat::{Float,FloatConvert};
55
use rustc_middle::mir::interpret::{InterpResult,PointerArithmetic,Scalar};
66
use rustc_middle::mir::CastKind;
@@ -187,10 +187,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
187187
bug!("FloatToFloat/FloatToInt cast: source type {} is not a float type", src.layout.ty)
188188
};
189189
let val =match fty{
190-
FloatTy::F16 =>unimplemented!("f16_f128"),
190+
FloatTy::F16 =>self.cast_from_float(src.to_scalar().to_f16()?, cast_to.ty),
191191
FloatTy::F32 =>self.cast_from_float(src.to_scalar().to_f32()?, cast_to.ty),
192192
FloatTy::F64 =>self.cast_from_float(src.to_scalar().to_f64()?, cast_to.ty),
193-
FloatTy::F128 =>unimplemented!("f16_f128"),
193+
FloatTy::F128 =>self.cast_from_float(src.to_scalar().to_f128()?, cast_to.ty),
194194
};
195195
Ok(ImmTy::from_scalar(val, cast_to))
196196
}
@@ -296,18 +296,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
296296
Float(fty)if signed =>{
297297
let v = vasi128;
298298
match fty{
299-
FloatTy::F16 =>unimplemented!("f16_f128"),
299+
FloatTy::F16 =>Scalar::from_f16(Half::from_i128(v).value),
300300
FloatTy::F32 =>Scalar::from_f32(Single::from_i128(v).value),
301301
FloatTy::F64 =>Scalar::from_f64(Double::from_i128(v).value),
302-
FloatTy::F128 =>unimplemented!("f16_f128"),
302+
FloatTy::F128 =>Scalar::from_f128(Quad::from_i128(v).value),
303303
}
304304
}
305305
// unsigned int -> float
306306
Float(fty) =>match fty{
307-
FloatTy::F16 =>unimplemented!("f16_f128"),
307+
FloatTy::F16 =>Scalar::from_f16(Half::from_u128(v).value),
308308
FloatTy::F32 =>Scalar::from_f32(Single::from_u128(v).value),
309309
FloatTy::F64 =>Scalar::from_f64(Double::from_u128(v).value),
310-
FloatTy::F128 =>unimplemented!("f16_f128"),
310+
FloatTy::F128 =>Scalar::from_f128(Quad::from_u128(v).value),
311311
},
312312

313313
// u8 -> char
@@ -321,7 +321,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
321321
/// Low-level cast helper function. Converts an apfloat `f` into int or float types.
322322
fncast_from_float<F>(&self,f:F,dest_ty:Ty<'tcx>) ->Scalar<M::Provenance>
323323
where
324-
F:Float +Into<Scalar<M::Provenance>> +FloatConvert<Single> +FloatConvert<Double>,
324+
F:Float
325+
+Into<Scalar<M::Provenance>>
326+
+FloatConvert<Half>
327+
+FloatConvert<Single>
328+
+FloatConvert<Double>
329+
+FloatConvert<Quad>,
325330
{
326331
use rustc_type_ir::TyKind::*;
327332

@@ -358,10 +363,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
358363
}
359364
// float -> float
360365
Float(fty) =>match fty{
361-
FloatTy::F16 =>unimplemented!("f16_f128"),
366+
FloatTy::F16 =>Scalar::from_f16(adjust_nan(self, f, f.convert(&mutfalse).value)),
362367
FloatTy::F32 =>Scalar::from_f32(adjust_nan(self, f, f.convert(&mutfalse).value)),
363368
FloatTy::F64 =>Scalar::from_f64(adjust_nan(self, f, f.convert(&mutfalse).value)),
364-
FloatTy::F128 =>unimplemented!("f16_f128"),
369+
FloatTy::F128 =>{
370+
Scalar::from_f128(adjust_nan(self, f, f.convert(&mutfalse).value))
371+
}
365372
},
366373
// That's it.
367374
_ =>span_bug!(self.cur_span(),"invalid float to {} cast", dest_ty),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp